Skip to content
Toolew.com

Hreflang Tag Generator

Generate hreflang alternate tags as HTML link elements, XML sitemap entries or an HTTP header, with language and region code checks.

Runs in your browser. Your data is not uploaded.
Loading tool…

Tool guide

What this tool does

Hreflang Tag Generator turns a list of language or region codes and URLs into the alternate markup search engines use to serve the right version of a page. It validates ISO 639-1 language codes and ISO 3166-1 region codes, catches common mistakes such as UK instead of GB, and outputs HTML link tags, XML sitemap xhtml:link entries or an HTTP Link header for non-HTML files such as PDFs.

When a site publishes the same content in several languages or for several regions, search engines need a way to know those pages are alternates of each other rather than duplicate content. The hreflang annotation does that job, but the codes are easy to get wrong: countries are sometimes used where a language is required, region codes get typed as the everyday abbreviation rather than the ISO standard, and a set of pages that is not fully reciprocal silently stops working.

This generator takes a plain list of “code URL” pairs, normalises the casing of each code and checks the language portion against ISO 639-1 and the optional region against ISO 3166-1, rejecting values such as UK, EU or UN that are not real country codes. It then builds the three forms a site might need: HTML link elements for a page head, xhtml:link entries for an XML sitemap, or a single HTTP Link header for files that have no head element at all, such as a hosted PDF.

How to use Hreflang Tag Generator

  1. List each language version as “code URL”, one per line, for example “en-GB https://www.example.com/uk/”.
  2. Use a language-only code such as “de” for a version aimed at all speakers of a language, and a language-region code such as “fr-CA” for a specific country.
  3. Set an x-default URL for visitors whose language or region is not listed, or leave it empty if every case is covered.
  4. Choose the Output format: HTML link tags for a page head, XML sitemap entries, or an HTTP Link header for non-HTML files.
  5. Check the preview for languages that have no generic, language-only fallback and for the x-default warning.
  6. Copy the result onto every page in the set, since each alternate must list the full set including itself.

Tips for better results

  • Add every page in the set to the markup on every page in the set; a one-way link is ignored because hreflang must be reciprocal.
  • Use a language-only code such as “en” alongside region codes such as “en-GB” and “en-US” to catch visitors from countries you have not listed individually.
  • Set an x-default for a language or country selector page, or for a global version meant for everyone else.
  • Put the same hreflang set in the XML sitemap instead of the page head when a site has thousands of translated pages, to avoid repeating the tags on every request.

Common use cases

  • Linking the UK, US and generic English versions of a product page together.
  • Publishing hreflang entries inside a sitemap for a large multilingual catalogue.
  • Adding a Link header to a translated PDF or other non-HTML document that has no head element.
  • Checking a drafted set of codes before sending them to a developer to paste into page templates.

Common mistakes to avoid

  • Using UK as a region code; the ISO 3166-1 code for the United Kingdom is GB, so the correct pair is en-GB.
  • Writing a region code without a language, such as just “GB”; hreflang always needs a language first.
  • Forgetting to add the same set of alternate links to every page in the group, breaking the required reciprocity.
  • Pointing hreflang at a redirecting or noindexed URL instead of the final, indexable page.

Frequently asked questions

What is the difference between hreflang="en" and hreflang="en-GB"?

"en" targets any English-speaking visitor regardless of country, while "en-GB" targets English speakers specifically in the United Kingdom. Sites often use both: a generic version plus one or more region-specific ones.

Do hreflang tags need to be reciprocal?

Yes. Every page in a set must list all the others, including itself. If page A links to page B but B does not link back to A, search engines treat the whole set of annotations as unreliable and may ignore it.

What does x-default do?

x-default marks the page to show visitors whose language or region does not match any of the listed alternates, commonly a language selector page or an international version aimed at everyone else.

Can hreflang go in a sitemap instead of the page head?

Yes. Adding xhtml:link entries to an XML sitemap is the recommended approach for large sites, since it avoids repeating the same tags inside every page’s HTML.

Feedback & suggestions

Help us improve Hreflang Tag Generator. We read every message.

Rating (optional)
Necessary
Required for security, language and theme preferences. Always on.