Hreflang Tag Generator
Generate hreflang link tags for a multilingual site, x-default included.
Remember the reciprocity rule
Every page in the group must include the full hreflang tag block, including itself. If docuboxer.com/en links to the Spanish version, the Spanish page must link back to /en and to itself too — otherwise search engines ignore the tags.
Add at least one valid code and URL to generate the block.
How do you generate hreflang tags for a multilingual website?
Pair a language code (with an optional region or script) to the absolute URL of each version, and let a generator assemble the <link rel="alternate" hreflang="..." href="..." /> block already sorted and free of syntax mistakes. Hand-written hreflang is one of the most common sources of international SEO bugs: an underscore instead of a hyphen, a lowercase region code, or a relative URL is enough for search engines to silently discard the whole block. This tool validates every code against ISO 639-1 (language), ISO 3166-1 (region), and ISO 15924 (script, for cases like zh-Hans), flags duplicates and malformed URLs row by row, and outputs both the <head> variant and the sitemap.xml (xhtml:link) variant. Everything runs in your browser — nothing is uploaded — and it's free, with no signup and no row limit.
How to use Hreflang Tag Generator
- Add one row per language version of the page: the hreflang code (en, en-GB, es-MX, zh-Hans...) and its full absolute URL, starting with http:// or https://.
- If the group needs a fallback version for visitors whose language or region doesn't match any listed URL, check the x-default box and pick which URL it should point to.
- Fix the red warnings as they appear: a malformed code or a non-absolute URL is flagged instantly, row by row, before you generate anything.
- Copy the <link> tag block and paste it into the <head> of every page in the group — or switch to the sitemap tab for the <xhtml:link> variant, ready to insert inside each <url> entry of your sitemap.xml.
- Repeat the full process on every page in the group, including the page itself: Google's reciprocity rule requires every page to declare the same complete block, not just the ones linking outward.
Common use cases
Launching an English version of a Spanish-first site
When you publish /en alongside your Spanish pages, both versions need to declare each other in hreflang so Google treats them as language alternatives instead of duplicate content competing against each other in the same market.
Serving the same product page to multiple English-speaking regions
A catalog with en-US, en-GB and en-AU for the same product family avoids cannibalization between regions: each URL stays relevant to its local market (pricing, shipping, spelling) instead of Google arbitrarily picking one to rank.
Migrating from language subfolders to subdomains
Moving /en and /es to en.yoursite.com and es.yoursite.com changes every absolute URL in your existing hreflang block; regenerating it from scratch per page avoids carrying over stale URLs that would break the cross-references.
Adding hreflang to a large sitemap.xml
On sites with hundreds of URLs, declaring hreflang inside the sitemap.xml itself is more practical than per-page <head> tags — and hand-writing the <xhtml:link> XML at that scale is exactly where syntax errors creep in.
Trusting the block before you ship it
Docuboxer itself serves its site in Spanish and English (docuboxer.com and docuboxer.com/en) with real hreflang in production, generated with the same validation logic this tool exposes — if it catches a malformed code or URL in our own block, it catches one in yours.
Frequently asked questions
What is a hreflang tag and what does it do?
It's an annotation that tells search engines which language or regional version of a page to show each user. Without it, Google may index only one version or treat the others as duplicate content, hurting rankings in the markets you're not targeting.
What's the correct format for a hreflang code?
A lowercase two-letter ISO 639-1 language code (en, es), optionally followed by an uppercase two-letter ISO 3166-1 region (en-GB, es-MX) or a four-letter ISO 15924 script (zh-Hans). The tool normalizes casing automatically as you type.
What is x-default and when should I use it?
It's the special value marking the page shown when a visitor's language or region doesn't match any of the listed URLs — usually a language selector or the English version. It isn't required, but it prevents users from unsupported markets from landing on the wrong page.
Should hreflang go in the <head> or in the sitemap.xml?
Either works, but never both at once for the same URLs. The <head> is simpler on small sites; sitemap.xml scales better on sites with many pages because it centralizes every hreflang annotation in a single file.
Why does Google still ignore my hreflang even though the code is correct?
The most common cause is missing reciprocity: if page A declares hreflang to page B, but B doesn't declare back to A (and to itself), Google discards the entire block. Check that every page in the group, without exception, ships the same set of tags.
Can I use three-letter language codes or underscores, like en_US?
No. hreflang follows BCP 47: a two-letter ISO 639-1 language code and hyphen separators, never underscores. A code like en_US or eng-US is invalid, and the generator flags it as an error instead of silently trying to fix it.