4Devs.tech

    Hreflang Tag Generator

    Build correct hreflang tags for multilingual and multi-regional sites, with x-default and code validation, ready to paste into your <head>.

    Features

    • Unlimited language and region versions
    • Validates ISO 639-1 / ISO 3166 codes
    • Automatic x-default tag
    • Duplicate detection
    • Copy-ready HTML output

    How to Implement Hreflang Correctly

    Hreflang is simple in principle but easy to get wrong: audits regularly find invalid codes, missing return links and canonical tags that contradict the hreflang set. Getting it right means each language version ranks in its own market instead of being filtered as duplicate content.

    Code format

    Use a two-letter ISO 639-1 language code, optionally followed by a hyphen and an ISO 3166-1 region code: en, en-US, pt-BR, zh-Hant. A region on its own (for example 'us') is not valid. Google treats codes case-insensitively, but the convention is lowercase language and uppercase region.

    Three ways to add hreflang

    In the HTML <head> (most common), in HTTP headers (useful for PDFs), or in your XML sitemap using xhtml:link elements. Pick one method per page; mixing them makes errors harder to find.

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

    Canonical and hreflang together

    Each language version should have a self-referencing canonical. If the German page's canonical points to the English page, Google sees it as a duplicate and drops the hreflang signal.

    Testing

    After deploying, check a few URLs with Google Search Console's URL Inspection and confirm the live HTML contains the full set of tags. If your site renders tags with JavaScript, make sure they also appear in the rendered HTML Google sees.

    Frequently asked questions