Hreflang Tags Generator: Free HTML & XML Code

Hreflang Tags Generator

Generate hreflang tags for international SEO. Add language/region pairs and copy ready-to-paste markup.

Optional. Used as the fallback for users whose language/region does not match any other tag.


                        

                        

A hreflang tags generator builds the language and region annotations that tell Google which version of a page to show each searcher. With this free tool, you enter a language code and URL for each version, add an optional x-default fallback, and copy ready-to-paste HTML link tags or an XML sitemap fragment.

What Is a Hreflang Tag and What Is It Used For?

A hreflang tag is an annotation, written as rel="alternate" plus an hreflang value, that tells search engines which URL serves which language or region. Its job is matching: a searcher in Germany who types in German should see your German page, not your English one.

Each value has up to two parts. The first is a language code such as en, es or de. The second, optional part is a region code such as US, GB or MX, joined with a hyphen (en-GB). A special value, x-default, marks the fallback page for everyone who matches none of your listed versions.

Hreflang does not boost rankings by itself. Google's Search Central documentation describes it as a way to help the right localized version appear, and to reduce the chance that near-identical pages in the same language compete with each other.

Three ways to declare hreflang

Google accepts hreflang in the HTML head, in HTTP headers, or in an XML sitemap. All three are treated the same, so pick the one you can maintain. This generator outputs the first and last: link tags for the head and a sitemap fragment.

How to Use the Hreflang Tags Generator

You only need your page versions and their full URLs. The output updates as you type, so there is no submit button.

  1. Type your fallback page into Default URL (x-default), for example your global homepage or a language selector. This field is optional.
  2. Click Add language/region to create a row.
  3. In the left box, type or pick a code from the suggestions, such as en-US or fr-CA. In the right box, enter the full URL of that version.
  4. Repeat for every version of the page, including the page you are on. Use the trash icon to remove a row you do not need.
  5. Read the issues list below the output. Fix anything it flags before copying.
  6. Click Copy under Generated HTML and paste the lines into the head section of the page. Or click Copy under XML Sitemap fragment to add the entry to your sitemap.

Worked Example: A Store With Three Versions

Say you run a store with a US English page, a UK English page and a German page, plus a global homepage as the fallback. You would enter this:

  • Default URL (x-default): https://example.com/
  • Row 1: en-US and https://example.com/en-us/
  • Row 2: en-GB and https://example.com/en-gb/
  • Row 3: de-DE and https://example.com/de/

The Generated HTML box then shows one link line per entry, including the x-default line, for example <link rel="alternate" hreflang="x-default" href="https://example.com/" />. The XML box shows the same set formatted for a sitemap.

What this means in practice: paste the identical set of lines into the head of all four pages. The US page lists itself, the UK page, the German page and the fallback. The UK page lists the same four. That mutual listing is what search engines call reciprocal, or return, links, and it is the most common thing people get wrong.

How to Read the Results and Fix Issues

The issues list under the output flags the input problems that most often break hreflang. No messages means the rows are complete, but it does not prove the live pages are set up correctly.

MessageWhat it meansFix
Missing language codeA row has a URL but no codePick a code such as en-US
Missing URLA row has a code but no addressEnter the full page URL
URL should start with http:// or https://The address is relative or incompleteUse the full absolute URL
Duplicate language codeTwo rows use the same codeKeep one URL per code

A good result has one row per version, absolute https URLs, no repeated codes and an x-default that points to a real fallback page. A poor result has gaps, relative paths such as /de/, or the same code used for two different pages.

Which Language and Region Codes Should You Use?

Use a language-only code when one page serves every speaker of that language, and add a region only when the content truly differs. A single Spanish page for everyone is es. Separate pages with different currency, shipping or spelling are es-MX and es-ES.

These mistakes show up constantly:

  • Region without language. A value like US alone is invalid. Write en-US.
  • Wrong region code. The United Kingdom is GB, so en-UK is wrong. Write en-GB.
  • Underscores. Use a hyphen, as in pt-BR, not pt_BR.
  • Language names. Use de, not german.

The suggestion list covers common codes, including Chinese variants (zh-CN, zh-TW, zh-HK) and Portuguese variants (pt-PT, pt-BR). You can also type a code that is not listed.

HTML Link Tags or XML Sitemap: Which Should You Choose?

Choose HTML link tags for small sites and XML sitemap entries for large ones. A site with 3 languages and 20 pages is easy to manage in the head. A catalog with 40,000 URLs and 8 languages is easier to maintain in one generated sitemap file.

Do not mix methods carelessly. If the head and the sitemap disagree, you create conflicting signals that are hard to debug. Pick one method per set of pages.

The XML box produces the fragment for a single page and its alternates. Repeat the process for each page in your sitemap, and make sure your sitemap file declares the xhtml namespace if it does not already.

Who Should Use a Hreflang Generator?

Anyone who publishes the same content for different languages or regions benefits. Typical situations include:

  • Online stores with separate US, UK and Canadian pages that differ in price, spelling or shipping.
  • SaaS companies with translated product pages and documentation.
  • Agencies preparing markup for a client's international launch.
  • WordPress and CMS owners who need correct lines to paste into a theme header or a plugin's custom head field.
  • Publishers with one article translated into several languages.

The tool also suits quick tests. Enter two versions, copy the output and compare it with what your site currently prints.

Best Practices and Troubleshooting

Most hreflang failures come from the setup around the tags, not the tags themselves. Work through this list when results look wrong.

  • Make every set reciprocal. If page A lists page B, page B must list page A. Missing return links are the top reason search engines ignore the annotations.
  • Include the page itself. Each version should list its own URL in the set.
  • Use absolute URLs. Include the protocol and domain, and match your preferred version exactly, including trailing slashes and https.
  • Point only to live, indexable pages. Do not list redirected, blocked or noindexed URLs.
  • Keep canonicals consistent. Each language page should normally be canonical to itself. Run a page through the canonical tag checker to confirm it does not point at another language.
  • Localize titles and descriptions. A translated page with an English title wastes the effort. Use the Google SERP snippet preview to check each version.
  • Verify the live output. After publishing, inspect the page with the meta tags analyzer to make sure your head section is intact.

If the wrong version still appears in search, remember that Google recrawls pages on its own schedule. Changes can take days or weeks to show.

Limitations to Know About

This generator builds markup from the rows you type. It does not crawl your site, confirm that your URLs load, or check that each page already carries the return links. It also does not translate content or decide which regions deserve their own page.

Hreflang is a signal, not a command. Google may still show a different version when other signals, such as a strong local link profile or a mismatched canonical, point elsewhere. Treat the tags as one part of a broader on-page setup, and browse the on-page SEO and meta tags tools for related checks.

Ready to build yours? Add your versions above, fix any flagged rows, and copy the HTML or XML straight into your site. Then paste the same set on every page in the group.

Frequently Asked Questions

What is a hreflang tag used for?
A hreflang tag tells search engines which language or regional version of a page to show a searcher. For example, en-GB points UK visitors to your British English page and de-DE points German visitors to your German page. It helps match users to the right version and avoids similar pages competing.
How do I use the hreflang tags generator?
Enter an optional Default URL (x-default), click Add language/region, and fill in a language code and full URL for each version. Include the page you are on. Then copy the Generated HTML into your page head, or copy the XML Sitemap fragment into your sitemap.
What is x-default and do I need it?
The x-default value marks the fallback page for users who match none of your listed languages or regions. It is optional, but useful when you have a global homepage or language selector. In this tool, enter that page in the Default URL (x-default) field.
Should I use HTML link tags or an XML sitemap for hreflang?
Either works, since Google treats the methods the same. HTML link tags suit small sites with a few pages. An XML sitemap is easier for large sites with many URLs and languages. Pick one method and keep it consistent across the set of pages.
Why does the generator say duplicate language code?
It means two rows use the same code, such as two en-US entries. Each language and region combination should point to only one URL. Remove or change one row. If the pages truly differ, give them different region codes, for example en-US and en-CA.
Is the hreflang tags generator free, and does it check my live pages?
The generator is free and needs no sign-in. It checks your entries for missing codes, missing or incomplete URLs and duplicates, but it does not visit your pages. You still need to confirm each live page lists the full set, including return links.
Recommended

Explore VPN options

A VPN changes your network exit. It does not guarantee anonymity.

Hide Your IP Encryption Network coverage
Protect My IP Now