Hreflang Tag Syntax: The Complete 2026 Guide

A developer-focused reference for correct hreflang syntax including language codes, region codes, and x-default usage.

Dilshad Akhtar
Dilshad Akhtar
Published: 9 July 2026
3 min read
TL;DRAI summary
  • Hreflang syntax looks simple on the surface, but small errors in language codes, region codes, or attribute placement cause search engines to...

Hreflang syntax looks simple on the surface, but small errors in language codes, region codes, or attribute placement cause search engines to silently ignore the entire annotation. This reference covers every syntactical rule you need for correct hreflang implementation in 2026.

Hreflang Tag Syntax: The Complete 2026 Guide

Hreflang syntax looks simple on the surface, but small errors in language codes, region codes, or attribute placement cause search engines to silently ignore the entire annotation. This reference covers every syntactical rule you need for correct hreflang implementation in 2026.

The basic syntax

A hreflang annotation uses the rel="alternate" attribute paired with an hreflang attribute and an href attribute inside a <link> element or an xhtml:link element in a sitemap.

<link rel="alternate" hreflang="en" href="https://example.com/en/" />

The three attributes are mandatory. Omitting any one of them invalidates the annotation.

Language-only syntax

When targeting a language without a region distinction, use a two-letter ISO 639-1 language code:

  • en (English, any region)
  • fr (French, any region)
  • de (German, any region)
  • es (Spanish, any region)

Google and other major search engines support ISO 639-1 codes. Codes from ISO 639-2 (three-letter codes like eng, fre) are not supported and cause the tag to be ignored.

Language-region syntax

When you need to distinguish between variants of the same language in different regions, combine the language code with a two-letter ISO 3166-1 alpha-2 region code:

<link rel="alternate" hreflang="en-US" href="https://example.com/us/" />
<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/" />

The language code comes first, followed by a hyphen, followed by the region code. Both codes are case-insensitive, but the convention is lowercase language and uppercase region (en-US, fr-CA).

The x-default value

x-default is a reserved hreflang value that specifies the default or fallback page when the user's language or region does not match any declared hreflang value.

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

Every hreflang set should include an x-default entry. Without it, users from unlisted locales may see a 404 or the wrong language page. The x-default page is often an automatic redirect page or a language selector.

Common syntax errors

Invalid language codes. Codes like en-uk (should be en-GB), zh without a script identifier, or made-up codes like eng are not valid. Always reference the IANA Language Subtag Registry.

Missing self-referencing tag. Every page must include its own URL in its hreflang set. A page targeting French users needs a hreflang="fr" entry pointing to its own URL.

Trailing slashes mismatch. Search engines treat https://example.com/fr and https://example.com/fr/ as different URLs. If you use trailing slashes, be consistent across every variant and ensure the sitemap matches the actual canonical URL.

Mixing language and region codes in the same set. If one page uses en-US and another uses en (without region), the mappings become ambiguous. Choose either language-only or language-region codes for each language across all variants.

Hreflang in sitemaps

In XML sitemaps, the syntax uses the xhtml namespace:

<?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/" />
  </url>
</urlset>

The namespace declaration xmlns:xhtml is required. Without it, sitemap parsers will not recognize the xhtml:link elements.

Hreflang in HTTP headers

For non-HTML content, use the Link header with a comma-separated list:

Link: <https://example.com/doc-en.pdf>; rel="alternate"; hreflang="en",
      <https://example.com/doc-fr.pdf>; rel="alternate"; hreflang="fr"

Each entry must include the URL in angle brackets, the rel="alternate" parameter, and the hreflang parameter separated by semicolons.

Audit closing

Validate your hreflang syntax with a dedicated checker before deploying to production. The IANA Language Subtag Registry is the authoritative source for valid codes. Run a bulk syntax check across all pages after every content migration or CMS update.

References

  1. IANA. "Language Subtag Registry." iana.org/assignments/language-subtag-registry/language-subtag-registry. 2026.
  2. Google Search Central. "Use hreflang for language and regional URLs." developers.google.com/search/docs/specialty/international/localized-versions. 2026.
  3. W3C. "HTML 5.2: Link Types alternate." w3.org/TR/html52/links.html#link-type-alternate. 2025.
  4. Aleyda Solis. "International SEO Checklist." aleydasolis.com/international-seo-checklist/. 2025.

Ready to Build Your Dream Website?

Let's discuss your project and create something amazing together.