Skip to content

Generated tags (3 formats)

For HTML <head> (put the same set on every page listed)

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

As an HTTP Link header (for PDFs and other non-HTML files)

Link: <https://example.com/>; rel="alternate"; hreflang="en", <https://example.com/es/>; rel="alternate"; hreflang="es", <https://example.com/fr/>; rel="alternate"; hreflang="fr", <https://example.com/>; rel="alternate"; hreflang="x-default"

As an XML sitemap

<?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/</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/" />
    <xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
  </url>
  <url>
    <loc>https://example.com/es/</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/" />
    <xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
  </url>
  <url>
    <loc>https://example.com/fr/</loc>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/" />
    <xhtml:link rel="alternate" hreflang="es" href="https://example.com/es/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
  </url>
</urlset>
info

Reciprocity check

Every URL in the set must list all the others, including itself. If your /es/ page lists /en/, your /en/ page must also list /es/. Without return links Google ignores the pair. Use our Hreflang Validator after you publish to confirm.

This tool checks one thing. Our audit checks 190+.

DarnItSEO Audit scans your entire site and writes the fix instructions for every issue it finds. Included in every yearly plan.

Building a hreflang cluster without hand-typing it

You list each language or regional version of one page, with its language code and full URL, and this generator writes the matching hreflang annotations in three formats: link tags for the HTML head, a Link HTTP header, and an XML sitemap block. Because every version of the page needs the same complete list, including a line for itself, a generator saves you from the copy-and-paste errors that break most hand-written setups.

As you type, the form also catches common mistakes before you copy anything: underscores instead of hyphens (en_US), country codes used as language codes (jp instead of ja, cn instead of zh), the non-existent region en-UK (it is en-GB), URLs that are not absolute http or https addresses, the same code pointing at two different URLs, and a missing x-default. It works entirely in your browser and does not fetch the URLs; to check what is actually live, use the Hreflang Validator.

What hreflang tells search engines, and what it does not

Hreflang says "these URLs are versions of the same content for different languages or regions". Google uses it to show the right version in results: the German page to searchers using German, the en-GB page to English speakers in the UK. It also stops region variants that are nearly identical, such as US and UK English pages, from being treated as competing copies.

It is not a ranking boost, and it does not translate anything. Bing has described hreflang as a weaker signal for its engine and also looks at the html lang attribute and the content-language meta tag, so do not treat hreflang as the only language signal on the page.

A four-version example in HTML and sitemap form

Here a pricing page exists for the US, the UK, German speakers anywhere, and a global fallback. Every one of the four pages carries the identical block, including the line pointing at itself.

<!-- The SAME block goes in the <head> of all four pages -->
<link rel="alternate" hreflang="en-US" href="https://example.com/us/pricing" />
<link rel="alternate" hreflang="en-GB" href="https://example.com/uk/pricing" />
<link rel="alternate" hreflang="de" href="https://example.com/de/preise" />
<link rel="alternate" hreflang="x-default" href="https://example.com/pricing" />

The sitemap method puts the same information in your XML sitemap instead. Each URL gets its own entry, and each entry repeats the full list of alternates. The urlset element must declare the xhtml namespace, which the generator's output includes.

<url>
  <loc>https://example.com/us/pricing</loc>
  <xhtml:link rel="alternate" hreflang="en-US" href="https://example.com/us/pricing" />
  <xhtml:link rel="alternate" hreflang="en-GB" href="https://example.com/uk/pricing" />
  <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise" />
  <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/pricing" />
</url>
<!-- ...then one <url> entry for EACH of the other pages, with the same links -->

Head tags, HTTP header or sitemap: choosing one

Head tags are the easiest to see and debug, and they suit most sites. The HTTP header is the only option for non-HTML files such as PDFs. The sitemap suits large sites where adding dozens of tags to every page would bloat the HTML, or where templates are hard to change. Google treats all three as equivalent. Pick one method per set of pages and keep it consistent; spreading one cluster across methods makes it hard to keep in sync and hard to audit.

Codes: language first, region optional

The value is an ISO 639-1 language code, optionally followed by a hyphen and an ISO 3166-1 alpha-2 region code: de, de-AT, pt-BR. A region on its own (hreflang="us") is invalid. Scripts can be added for languages written in more than one, such as zh-Hans and zh-Hant. Use the broadest code that is true: if one English page serves everyone, use en; only add regions when you really have different pages for different countries, for example because prices, currency or delivery differ.

x-default is a special value for the page to show when no other version matches the searcher, typically a language picker or your main international page. It is optional but recommended.

The return-link rule

If page A lists page B as an alternate, page B must list page A. Google ignores pairs that are not confirmed in both directions. That is why every page gets the full block rather than just links to the others, and why adding a new language means updating every existing version too. Generate the block once, then paste the same output into every page in the cluster.

Two more rules make or break a cluster. Every URL in it should return 200 directly, not redirect. And every URL should be the canonical version of itself: if the German page's canonical points at the English page, Google follows the canonical and the hreflang for that page is ignored. Our Canonical Tag Checker confirms each page's canonical.

Adding the tags on WordPress, Shopify, Next.js or Nginx

WordPress

Multilingual plugins such as WPML and Polylang output hreflang automatically for linked translations; check their output rather than adding a second set by hand. Without one, add the generated block with a header-code plugin limited to the right pages.

Shopify

Shopify Markets adds hreflang for the language and country subfolders or domains it manages. Only add your own tags for pages outside Markets, and make sure you do not end up with two conflicting sets.

Next.js

In the App Router, set alternates.languages in the page's metadata, for example { 'en-US': '/us/pricing', 'de': '/de/preise', 'x-default': '/pricing' }, with metadataBase set so the URLs are absolute.

Nginx (for PDFs)

Paste the generator's HTTP header output into an add_header Link "..." line in the location block that serves the file, and do the same for each language version of the file.

Beyond the tags: structure and content

Hreflang connects versions; it does not decide how you organise them. Country-code domains (example.de) send the clearest country signal but each builds authority separately. Subfolders (example.com/de/) share one domain and are the simplest to run. Subdomains sit in between. Google retired Search Console's country-targeting setting in 2022, so for generic domains the structure, hreflang and the content itself (language, currency, addresses, local details) now carry the targeting. The hreflang validator checks the tags themselves, and our hreflang guide covers the strategy.

After you paste the output

Deploy to every page in the cluster at once, then run one of the URLs through the validator, which fetches each alternate and confirms it links back. Re-check whenever you add a language, change a URL or add a redirect, since those are the moments clusters break. Over the following weeks, Search Console's performance report filtered by country shows whether the right URL is appearing in each market.

How it works

  1. Add URL Pairs

    Enter each page URL along with its language code (e.g., 'en') and optional region code (e.g., 'US'). Add all language variants for the same page.

  2. Generate Reciprocal Tags

    We automatically generate all required return tags, because every page must reference all other versions, including itself.

  3. Copy Your Format

    Get output in HTML link tags, HTTP headers, or XML sitemap format, ready to add to your site.

Frequently asked

What is hreflang and when do I need it?

›

Hreflang is an annotation that tells search engines which language and optional region a page is for, and links it to its equivalents in other languages or regions. You need it when you have several versions of the same page, for example English and Spanish, or US and UK English with different prices.

What formats does this generator produce?

›

Three: link tags for the HTML head, a single Link HTTP header value, and an XML sitemap block with xhtml:link entries for each URL. All three carry the same information. It runs in your browser and does not fetch or check the URLs you enter; use the Hreflang Validator for live pages.

Which mistakes does it catch while I type?

›

Underscores instead of hyphens (en_US), codes that are not valid ISO formats, country codes used as language codes (jp, cn, kr, dk and others), the invalid region en-UK (use en-GB), URLs that are not absolute http or https addresses, the same code pointing at two URLs, and a missing x-default.

What is x-default and when should I use it?

›

x-default names the page to show searchers who do not match any language or region you list, typically a language picker or your main international page. It is optional but recommended, and it can point to the same URL as one of your other versions.

Do I need to include the page itself in its own hreflang list?

›

Yes. Every page lists every version, including itself. That is why the generator outputs one identical block that you paste into all pages in the set. Each page must also be listed back by the others, or Google ignores the pair.

What's the difference between hreflang='en' and hreflang='en-US'?

›

'en' targets English speakers anywhere. 'en-US' targets English speakers in the United States. Use the broadest code that is true: if one English page serves everyone, use 'en'. Add regions only when you have genuinely different pages per country, such as different prices, currency or delivery terms.

Should I use head tags, HTTP headers or the sitemap?

›

Google treats them as equivalent. Head tags are easiest to debug and suit most sites. HTTP headers are the only option for PDFs and other non-HTML files. The sitemap suits large sites with many languages. Pick one method per set of pages; spreading one set across methods makes it hard to keep in sync.

Does adding hreflang improve rankings?

›

Not directly. Hreflang helps Google show the right version to the right searcher and keeps near-identical regional versions from being treated as competing duplicates. Any traffic gain comes from people landing on the version written for them, not from a ranking boost.

Related tools

More Technical SEO tools

See all Technical SEO tools · All free SEO tools

Related guides

↳ full site audit190+ checks · AI fix instructions · yearly plans