Hreflang Tags in Vue · Nuxt SEO

-
-
-
-

[1.4K](https://github.com/harlan-zw/nuxt-seo)

[Nuxt SEO on GitHub](https://github.com/harlan-zw/nuxt-seo)

Learn SEO

Master search optimization

Nuxt

 Vue

-
-
-
-
-
-
-

-
-
-
-
-
-
-

-
-
-

-
-
-
-
-
-
-
-
-
-
-

-
-
-

-
-
-
-
-
-
-
-
-

1.
2.
3.
4.
5.

# Hreflang Tags in Vue

Set hreflang tags in Vue to tell search engines which language version to show users. Avoid duplicate content penalties across multilingual sites.

[![Harlan Wilton](https://avatars.githubusercontent.com/u/5326365?v=4)Harlan Wilton](https://x.com/harlan-zw)12 mins read Published Dec 17, 2025

What you'll learn

- Hreflang tags tell search engines which language version to show users
- All pages in a cluster must link to each other bidirectionally (return links)
- Use `x-default` as fallback for users whose language isn't available

Hreflang tags tell search engines which language version of your page to show users. Without them, Google might show your French content to English speakers or rank the wrong regional version, creating

 issues across languages.

```
<head>
  <link rel="alternate" hreflang="en" href="https://example.com/en" />
  <link rel="alternate" hreflang="fr" href="https://example.com/fr" />
  <link rel="alternate" hreflang="x-default" href="https://example.com/en" />
</head>
```

[Google recommends hreflang](https://developers.google.com/search/docs/specialty/international/localized-versions) when you have:

- Same content in different languages
- Regional variations (en-US vs en-GB)
- Partial translations mixed with original language

Hreflang is a signal, not a directive. Search engines can ignore it if they think a different version better matches user intent.

## [Quick Reference](#quick-reference)

Unhead

```
useHead({
  link: [
    { rel: 'alternate', hreflang: 'en', href: 'https://example.com/en' },
    { rel: 'alternate', hreflang: 'fr', href: 'https://example.com/fr' },
    { rel: 'alternate', hreflang: 'x-default', href: 'https://example.com/en' }
  ]
})
```

## [Hreflang Format](#hreflang-format)

Hreflang values use [ISO 639-1 language codes](https://www.linguise.com/blog/guide/list-of-the-hreflang-language-codes-how-to-implement-them/) and optional [ISO 3166-1 Alpha-2 region codes](https://hreflang.org/what-is-a-valid-hreflang/):

| Format | Example | Use Case |
| --- | --- | --- |
| Language only | `en` | English content for all regions |
| Language + region | `en-US` | English for United States |
| Language + region | `en-GB` | English for United Kingdom |
| Special fallback | `x-default` | Default for unmatched languages/regions |

Language codes must be lowercase. Region codes must be uppercase. Separate with hyphen: `en-US`.

### [Common Examples](#common-examples)

```
en          English (all regions)
fr          French (all regions)
es          Spanish (all regions)
en-US       English for USA
en-GB       English for UK
fr-CA       French for Canada
es-MX       Spanish for Mexico
zh-CN       Simplified Chinese (China)
zh-TW       Traditional Chinese (Taiwan)
```

### [Region Codes Are Tricky](#region-codes-are-tricky)

[UK is Ukraine](https://www.weglot.com/blog/hreflang-language-codes), not United Kingdom. Use `GB` for Great Britain. [Chinese uses zh-CN/zh-TW or zh-Hans/zh-Hant](https://www.seroundtable.com/google-iso-3166-1-for-hreflang-24663.html) for simplified/traditional variants since ISO 639-1 only defines one `zh` code.

## [Implementation in Vue](#implementation-in-vue)

### [With Unhead](#with-unhead)

Use [`useHead()`](https://unhead.unjs.io/) to set hreflang tags that work in SSR:

```
<script setup lang="ts">
const route = useRoute()

// Build alternate URLs based on current route
const alternates = [
  { lang: 'en', url: \`https://example.com/en${route.path}\` },
  { lang: 'fr', url: \`https://example.com/fr${route.path}\` },
  { lang: 'de', url: \`https://example.com/de${route.path}\` }
]

useHead({
  link: [
    ...alternates.map(alt => ({
      rel: 'alternate',
      hreflang: alt.lang,
      href: alt.url
    })),
    // x-default fallback
    { rel: 'alternate', hreflang: 'x-default', href: 'https://example.com/en' }
  ]
})
</script>
```

### [With vue-i18n](#with-vue-i18n)

If you're using [vue-i18n](https://vue-i18n.intlify.dev/) for translations, generate hreflang from available locales:

```
import { useI18n } from 'vue-i18n'

const { locale, availableLocales } = useI18n()
const route = useRoute()

// Generate alternate links for all locales
const alternateLinks = availableLocales.map(loc => ({
  rel: 'alternate',
  hreflang: loc,
  href: \`https://example.com/${loc}${route.path}\`
}))

// Add self-referential link for current locale
alternateLinks.push({
  rel: 'alternate',
  hreflang: locale.value,
  href: \`https://example.com/${locale.value}${route.path}\`
})

useHead({ link: alternateLinks })
```

### [Creating a Composable](#creating-a-composable)

Extract hreflang logic into a reusable composable:

```
// composables/useHreflang.ts

export function useHreflang(locales: string[]) {
  const route = useRoute()

  const links = computed(() => {
    const baseUrl = 'https://example.com'

    return [
      ...locales.map(locale => ({
        rel: 'alternate',
        hreflang: locale,
        href: \`${baseUrl}/${locale}${route.path}\`
      })),
      // x-default to primary locale
      {
        rel: 'alternate',
        hreflang: 'x-default',
        href: \`${baseUrl}/${locales[0]}${route.path}\`
      }
    ]
  })

  useHead({ link: links })
}
```

Use it in components:

```
<script setup lang="ts">
useHreflang(['en', 'fr', 'de', 'es'])
</script>
```

## [X-Default Tag](#x-default-tag)

The `x-default` hreflang provides a fallback URL when no language matches the user's preferences. [Google recommends x-default](https://www.weglot.com/guides/hreflang-tag) for all hreflang clusters.

```
<!-- User with no matching language sees this -->
<link rel="alternate" hreflang="x-default" href="https://example.com/en" />
```

### [When to Use X-Default](#when-to-use-x-default)

Set x-default to:

- Your primary language version
- A language selector page
- The most universally understood language version

```
// Point x-default to language selector
useHead({
  link: [
    { rel: 'alternate', hreflang: 'en-US', href: 'https://example.com/en-us' },
    { rel: 'alternate', hreflang: 'en-GB', href: 'https://example.com/en-gb' },
    { rel: 'alternate', hreflang: 'fr-FR', href: 'https://example.com/fr-fr' },
    { rel: 'alternate', hreflang: 'x-default', href: 'https://example.com/choose-language' }
  ]
})
```

[According to Victorious](https://developers.google.com/search/docs/specialty/international/localized-versions#x-default), x-default improves user experience by routing unmatched users to an appropriate fallback instead of a random language version.

## [Hreflang Rules](#hreflang-rules)

### [1. Bidirectional Links (Return Links)](#_1-bidirectional-links-return-links)

Every page referenced in hreflang must link back. If page A links to page B, page B must link to page A. [This is the most common hreflang error](https://developers.google.com/search/docs/specialty/international/localized-versions).

```
<!-- en page must reference fr page -->
<link rel="alternate" hreflang="fr" href="https://example.com/fr" />

<!-- fr page must reference en page -->
<link rel="alternate" hreflang="en" href="https://example.com/en" />
```

### [2. Self-Referential Links](#_2-self-referential-links)

Each page must include a hreflang tag pointing to itself:

```
<!-- On the English page -->
<link rel="alternate" hreflang="en" href="https://example.com/en" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr" />

<!-- On the French page -->
<link rel="alternate" hreflang="en" href="https://example.com/en" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr" />
```

### [3. Use Canonical URLs Only](#_3-use-canonical-urls-only)

All hreflang URLs must:

- Return HTTP 200 status
- Be indexable (no `noindex`)
- Not be blocked by robots.txt
- Point to canonical URLs (not redirects)

[According to I Love SEO](https://developers.google.com/search/docs/specialty/international/localized-versions), using non-200, non-indexable, or non-canonical URLs is the root cause of most hreflang mistakes.

```
<script setup lang="ts">
// ✅ Good - points to canonical URL
useHead({
  link: [
    { rel: 'canonical', href: 'https://example.com/en/products' },
    { rel: 'alternate', hreflang: 'en', href: 'https://example.com/en/products' },
    { rel: 'alternate', hreflang: 'fr', href: 'https://example.com/fr/produits' }
  ]
})

// ❌ Bad - points to redirect
useHead({
  link: [
    { rel: 'alternate', hreflang: 'en', href: 'https://example.com/old-url' } // redirects to /en/products
  ]
})
</script>
```

### [4. Canonical vs Hreflang](#_4-canonical-vs-hreflang)

Canonical tags and hreflang serve different purposes. Don't use canonical to point between language versions. [that signals duplicate content](https://developers.google.com/search/docs/specialty/international/localized-versions), not translations.

```
<!-- ✅ Correct: each language version is canonical to itself -->
<!-- English page -->
<link rel="canonical" href="https://example.com/en/about" />
<link rel="alternate" hreflang="en" href="https://example.com/en/about" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/a-propos" />

<!-- French page -->
<link rel="canonical" href="https://example.com/fr/a-propos" />
<link rel="alternate" hreflang="en" href="https://example.com/en/about" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/a-propos" />
```

```
<!-- ❌ Wrong: canonical pointing between languages -->
<!-- French page -->
<link rel="canonical" href="https://example.com/en/about" />
<!-- This tells Google the French page is duplicate content -->
```

## [Server-Side Rendering Required](#server-side-rendering-required)

Hreflang tags must exist in the initial HTML response. SPAs that render hreflang client-side won't work reliably:

```
<script setup lang="ts">
// ❌ Runs after SSR - search engines may miss this
onMounted(() => {
  useHead({
    link: [
      { rel: 'alternate', hreflang: 'en', href: 'https://example.com/en' }
    ]
  })
})

// ✅ Runs during SSR and client-side
useHead({
  link: [
    { rel: 'alternate', hreflang: 'en', href: 'https://example.com/en' }
  ]
})
</script>
```

If you're building a SPA, see the

 or

.
## [Implementation Methods](#implementation-methods)

You can implement hreflang using HTML `<link>` tags, HTTP headers, or XML sitemaps. [Best practice is to choose one method](https://backlinko.com/hreflang-tag) and stick to it. Mixing methods creates conflicting signals.

### [HTML Link Tags (Recommended)](#html-link-tags-recommended)

Most flexible approach. Set per-page using Unhead:

```
<script setup lang="ts">
useHead({
  link: [
    { rel: 'alternate', hreflang: 'en-US', href: 'https://example.com/us' },
    { rel: 'alternate', hreflang: 'en-GB', href: 'https://example.com/uk' },
    { rel: 'alternate', hreflang: 'x-default', href: 'https://example.com/us' }
  ]
})
</script>
```

### [HTTP Headers](#http-headers)

Useful for non-HTML resources (PDFs, etc.). Configure in your server:

Express

H3

Vite SSR

```
app.get('/document.pdf', (req, res) => {
  res.set('Link', [
    '<https://example.com/en/document.pdf>; rel="alternate"; hreflang="en"',
    '<https://example.com/fr/document.pdf>; rel="alternate"; hreflang="fr"',
    '<https://example.com/en/document.pdf>; rel="alternate"; hreflang="x-default"'
  ].join(', '))

  res.sendFile('/path/to/document.pdf')
})
```

```
export default defineEventHandler((event) => {
  setHeader(event, 'Link', [
    '<https://example.com/en/document.pdf>; rel="alternate"; hreflang="en"',
    '<https://example.com/fr/document.pdf>; rel="alternate"; hreflang="fr"',
    '<https://example.com/en/document.pdf>; rel="alternate"; hreflang="x-default"'
  ].join(', '))

  return sendStream(event, createReadStream('/path/to/document.pdf'))
})
```

```
// server.ts
server.use((req, res, next) => {
  if (req.url.endsWith('.pdf')) {
    res.setHeader('Link', [
      '<https://example.com/en/document.pdf>; rel="alternate"; hreflang="en"',
      '<https://example.com/fr/document.pdf>; rel="alternate"; hreflang="fr"',
      '<https://example.com/en/document.pdf>; rel="alternate"; hreflang="x-default"'
    ].join(', '))
  }
  next()
})
```

### [XML Sitemap](#xml-sitemap)

Add hreflang to your sitemap if you can't modify HTML/headers:

```
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://example.com/en</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en" />
  </url>
  <url>
    <loc>https://example.com/fr</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en" />
  </url>
</urlset>
```

## [Common Mistakes](#common-mistakes)

### [Missing Return Links](#missing-return-links)

```
<!-- ❌ English page links to French, but French doesn't link back -->
<!-- en page -->
<link rel="alternate" hreflang="fr" href="https://example.com/fr" />

<!-- fr page -->
<!-- Missing hreflang links! -->
```

### [Non-Canonical URLs](#non-canonical-urls)

```
<!-- ❌ Linking to URL that redirects -->
<link rel="alternate" hreflang="en" href="https://example.com/en-us" />
<!-- But /en-us redirects to /us -->

<!-- ✅ Use final destination -->
<link rel="alternate" hreflang="en" href="https://example.com/us" />
```

### [Noindex Pages](#noindex-pages)

```
<!-- ❌ Hreflang on noindex page -->
<meta name="robots" content="noindex" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr" />
```

All pages in hreflang cluster must be indexable. Remove `noindex` or remove the page from hreflang annotations.

### [Blocked by Robots.txt](#blocked-by-robotstxt)

If a URL is blocked in `robots.txt`, crawlers can't access it to validate hreflang links. Ensure all alternate URLs are crawlable.

### [Mixing with Canonical](#mixing-with-canonical)

```
<!-- ❌ Don't point canonical between languages -->
<!-- French page -->
<link rel="canonical" href="https://example.com/en" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr" />
<!-- Conflicting signals: canonical says "I'm a duplicate of EN"
     but hreflang says "I'm the French version" -->
```

## [Testing Hreflang](#testing-hreflang)

### [Manual Inspection](#manual-inspection)

View page source and verify:

- All alternate links are present
- Self-referential link exists
- x-default is set
- All URLs return 200
- All URLs are canonical (not redirects)

### [Google Search Console](#google-search-console)

After implementing hreflang, check [Google Search Console](https://search.google.com/search-console) > International Targeting for errors:

- Missing return tags
- Incorrect language codes
- Invalid URLs

### [Third-Party Tools](#third-party-tools)

- [Hreflang Tags Testing Tool](https://hreflang.org)
- [Merkle Hreflang Checker](https://technicalseo.com/tools/hreflang/)
- Search Console reports

## [Full Example: Multilingual Vue App](#full-example-multilingual-vue-app)

Here's a complete implementation with vue-i18n and Vue Router:

```
// router/index.ts
import { createRouter, createWebHistory } from 'vue-router'

const locales = ['en', 'fr', 'de', 'es']

const router = createRouter({
  history: createWebHistory(),
  routes: locales.flatMap(locale => [
    {
      path: \`/${locale}\`,
      component: () => import('@/pages/Home.vue'),
      meta: { locale }
    },
    {
      path: \`/${locale}/products\`,
      component: () => import('@/pages/Products.vue'),
      meta: { locale }
    }
  ])
})

export default router
```

```
// composables/useHreflang.ts

export function useHreflang() {
  const route = useRoute()
  const { locale } = useI18n()

  const locales = ['en', 'fr', 'de', 'es']
  const baseUrl = 'https://example.com'

  // Remove locale prefix to get path
  const pathWithoutLocale = route.path.replace(\`/${locale.value}\`, '')

  const links = computed(() => [
    // All locale variants
    ...locales.map(loc => ({
      rel: 'alternate',
      hreflang: loc,
      href: \`${baseUrl}/${loc}${pathWithoutLocale}\`
    })),
    // Current page (self-referential)
    {
      rel: 'alternate',
      hreflang: locale.value,
      href: \`${baseUrl}${route.path}\`
    },
    // x-default fallback
    {
      rel: 'alternate',
      hreflang: 'x-default',
      href: \`${baseUrl}/en${pathWithoutLocale}\`
    }
  ])

  useHead({ link: links })
}
```

```
<!-- pages/Home.vue -->
<script setup lang="ts">
useHreflang()

useSeoMeta({
  title: 'Home',
  description: 'Welcome to our site'
})
</script>

<template>
  <main>
    <h1>{{ $t('home.title') }}</h1>
  </main>
</template>
```

## [Using Nuxt?](#using-nuxt)

Nuxt's [@nuxtjs/i18n](https://i18n.nuxtjs.org/docs/guide/seo/) module automatically generates hreflang tags for all configured locales with zero configuration. It handles return links, self-referential tags, and x-default automatically.

---

On this page

- [Quick Reference](#quick-reference)
- [Hreflang Format](#hreflang-format)
- [Implementation in Vue](#implementation-in-vue)
- [X-Default Tag](#x-default-tag)
- [Hreflang Rules](#hreflang-rules)
- [Server-Side Rendering Required](#server-side-rendering-required)
- [Implementation Methods](#implementation-methods)
- [Common Mistakes](#common-mistakes)
- [Testing Hreflang](#testing-hreflang)
- [Full Example: Multilingual Vue App](#full-example-multilingual-vue-app)
- [Using Nuxt?](#using-nuxt)

[GitHub](https://github.com/harlan-zw/nuxt-seo) [ Discord](https://discord.com/invite/275MBUBvgP)

###

-
-

Modules

-
-
-
-
-
-
-
-
-

###

-
-
-

###

Nuxt

-
-
-
-
-

Vue

-
-
-
-
-
-
-
-

###

-
-
-
-
-
-
-
-
-
-

Copyright © 2023-2026 Harlan Wilton - [MIT License](https://github.com/harlan-zw/nuxt-seo/blob/main/license) · [mdream](https://mdream.dev)