Skip to content
MrKeyword
Free hreflang tag generator

Hreflang tag generator: build link tags, headers and sitemap entries.

Add a language code and full URL for each version of a page, plus an optional x-default, and copy correct hreflang markup for the HTML head, an HTTP header or your XML sitemap, with warnings for invalid codes, built in your browser.

Free, no account needed. Hreflang tags are built in your browser and never sent to MrKeyword.

Built on first-party data from Google and Bing
Search ConsolePageSpeed InsightsBing Webmaster Tools
An explorer discovering useful search ideas with a magnifying glass
A little curiosity goes a long way.
What it builds

What does hreflang do?

hreflang tells Google which language or regional version of a page to show to each searcher, so a visitor in the UK gets your /uk/ page and a visitor in France gets /fr/. hreflang does not merge rankings or fix duplicate content on its own; it swaps in the right URL where a version already ranks.

The code is a language, optionally followed by a region: a two-letter ISO 639-1 language such as en, fr or ja, then a hyphen and a two-letter ISO 3166-1 region such as gb, us or ca (or 419 for Latin America). The region alone is not valid, and common slips like en-uk (use en-gb) or jp (use ja) make Google ignore the line. For Bing, set language metadata as well: the Content-Language header and the HTML lang attribute are language signals too.

x-default names the page for everyone else, usually a language picker or your main version. Return links matter most: every page in the set must list every other page and itself, or Google may drop the pairing. That is why this tool gives one identical block to paste on every version. Read the hreflang tags guide for the full picture, then test live pages with the hreflang checker.

In the result

Clear answers,
with the reason shown.

Three outputs

HTML head, HTTP header and XML sitemap.

The same set of alternates as link tags for the page head, one Link header for PDFs and other files, and sitemap url blocks with xhtml:link entries.

  • x-default added when you enter a URL
  • Codes normalised to lower case with a hyphen (en_GB becomes en-gb)
Code checks

Invalid, duplicate and relative entries flagged.

Each code is checked against ISO 639-1 languages and ISO 3166-1 regions; duplicate codes, relative URLs and one URL used for two codes are called out before you publish.

  • Catches en-uk, jp and region-only codes
  • Rows with errors are left out of the copy blocks
Worked example

A site with UK, US and French pages plus a language picker.

The fictional northwind-plumbing.example has British English at /uk/, American English at /us/ and French at /fr/, with the language picker on the home page as x-default:

HTML head

Paste inside the <head> of every page in the set.

<link rel="alternate" hreflang="en-gb" href="https://northwind-plumbing.example/uk/" />
<link rel="alternate" hreflang="en-us" href="https://northwind-plumbing.example/us/" />
<link rel="alternate" hreflang="fr" href="https://northwind-plumbing.example/fr/" />
<link rel="alternate" hreflang="x-default" href="https://northwind-plumbing.example/" />
HTTP header

For PDFs and other non-HTML files: send this Link header with each version.

Link: <https://northwind-plumbing.example/uk/>; rel="alternate"; hreflang="en-gb", <https://northwind-plumbing.example/us/>; rel="alternate"; hreflang="en-us", <https://northwind-plumbing.example/fr/>; rel="alternate"; hreflang="fr", <https://northwind-plumbing.example/>; rel="alternate"; hreflang="x-default"
XML sitemap

Or list the alternates in your XML sitemap instead of the page head.

<!-- Add xmlns:xhtml="http://www.w3.org/1999/xhtml" to the <urlset> tag of your sitemap. -->
<url>
  <loc>https://northwind-plumbing.example/uk/</loc>
    <xhtml:link rel="alternate" hreflang="en-gb" href="https://northwind-plumbing.example/uk/" />
    <xhtml:link rel="alternate" hreflang="en-us" href="https://northwind-plumbing.example/us/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://northwind-plumbing.example/fr/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://northwind-plumbing.example/" />
</url>
<url>
  <loc>https://northwind-plumbing.example/us/</loc>
    <xhtml:link rel="alternate" hreflang="en-gb" href="https://northwind-plumbing.example/uk/" />
    <xhtml:link rel="alternate" hreflang="en-us" href="https://northwind-plumbing.example/us/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://northwind-plumbing.example/fr/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://northwind-plumbing.example/" />
</url>
<url>
  <loc>https://northwind-plumbing.example/fr/</loc>
    <xhtml:link rel="alternate" hreflang="en-gb" href="https://northwind-plumbing.example/uk/" />
    <xhtml:link rel="alternate" hreflang="en-us" href="https://northwind-plumbing.example/us/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://northwind-plumbing.example/fr/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://northwind-plumbing.example/" />
</url>
<url>
  <loc>https://northwind-plumbing.example/</loc>
    <xhtml:link rel="alternate" hreflang="en-gb" href="https://northwind-plumbing.example/uk/" />
    <xhtml:link rel="alternate" hreflang="en-us" href="https://northwind-plumbing.example/us/" />
    <xhtml:link rel="alternate" hreflang="fr" href="https://northwind-plumbing.example/fr/" />
    <xhtml:link rel="alternate" hreflang="x-default" href="https://northwind-plumbing.example/" />
</url>

Example output for a fictional site. It is built by the generator’s own code at build time; replace every URL with your real pages.

Paste the same head block on all four pages so each one lists itself and every alternate; that is what makes the return links match. The codes typed as en-GB and en-US come out as en-gb and en-us. After you publish, run the hreflang checker on each version, and read the hreflang tags guide for edge cases.

Reading the result

How do you read the hreflang tag generator result?

HTML head
One <link rel="alternate" hreflang="…" href="…" /> per version plus x-default. Paste the whole block into the <head> of every page in the set.
HTTP header
A single Link: header listing every version. Use it for PDFs and other files that have no HTML head.
XML sitemap
One <url> block per URL, each listing all alternates as xhtml:link. Add xmlns:xhtml="http://www.w3.org/1999/xhtml" to your <urlset>.
Fix and Note lines
Fix lines are rows left out of the output (bad code, duplicate, relative URL) or problems such as one URL used for two codes. A Note is a tip, such as adding x-default.
Common errors

What are common hreflang mistakes?

Using en-uk instead of en-gb

The region code for the United Kingdom is GB. Google ignores hreflang lines with codes it does not recognise.

Country codes as languages

jp, cn and kr are countries. The languages are ja (Japanese), zh (Chinese) and ko (Korean).

Missing return links

If /fr/ lists /uk/ but /uk/ does not list /fr/, Google may ignore the pair. Use the same block on every version.

Relative URLs

hreflang needs full addresses such as https://example.com/fr/, not /fr/.

Pointing at redirects or noindex pages

Every alternate should return 200, be indexable and carry a self canonical. The hreflang checker shows status codes for each alternate.

When to check

When should you generate hreflang tags?

Generate them when you add a language or country version, change URLs, or find hreflang errors in an audit.

Launching a new country or language
Add the new version to the set and paste the updated block on every page, not only the new one.
After a URL change or migration
Regenerate with the final URLs so no alternate points at a redirect.
When the hreflang checker reports errors
Rebuild the set with valid codes and matching return links.
Serving PDFs in several languages
Use the HTTP header output, since files have no HTML head.
When templates are hard to edit
Use the sitemap output and list the alternates there instead.
Go further

Guides for this check.

More free checkers

Other quick checks.

Questions

About the hreflang tag generator.

What is the correct hreflang format?

A two-letter ISO 639-1 language code, optionally followed by a hyphen and a two-letter ISO 3166-1 region code, for example en, en-gb or es-mx. Use 419 for Latin American Spanish (es-419) and x-default for the fallback page.

Why is en-uk wrong?

UK is not an ISO 3166-1 region code. The United Kingdom is GB, so British English is en-gb. Likewise jp is a country code; Japanese is ja, so use ja or ja-jp.

Do I need x-default?

It is optional but recommended. x-default tells Google which page to show searchers whose language or region you do not list, usually a language picker or your main version.

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

Pick one method per set of pages. Link tags in the head suit most HTML pages, the HTTP Link header suits PDFs and other non-HTML files, and the XML sitemap suits large sites where editing every template is hard.

Does this tool fetch my pages?

No. The tags are built in your browser from the rows you type and nothing is sent to MrKeyword. After you publish, test a live URL with the hreflang checker to confirm return links and status codes.