Hreflang Generator
FREE TOOL · NO SIGN-UP
This hreflang generator builds a complete, consistent hreflang set for multilingual and multi-region pages. Add each language-region code with its page URL, set an x-default fallback, and choose your output: HTML link tags for the head, an XML sitemap block, or an HTTP Link header. The tool checks every code and URL as you go, warns about common errors like “en-uk”, and reminds you that each version must list all the others. Copy or download the result.
What Hreflang Tells Search Engines
Hreflang is an HTML attribute, used with rel="alternate", that tells search engines a page has equivalent versions in other languages or for other regions. It answers one question: “Which version should this searcher see?”
Imagine a store with English pages for the US and UK, plus a Spanish version for Mexico. Without hreflang, Google might show the US page to UK shoppers, with prices in dollars, or rank the English page for a Spanish search. With hreflang, Google can swap in the right localized page for each searcher’s language and location.
Hreflang also helps with duplicate content in international SEO. Pages for en-us and en-gb are often nearly identical. Hreflang marks them as alternates for different audiences rather than copies competing with each other.
Google and Yandex use hreflang. Bing has said it relies more on the content-language meta tag and the HTML lang attribute, so many multilingual websites set both.
Hreflang is a signal for choosing between versions. It doesn’t boost rankings or force Google to show a page; it helps the right language version appear where your site already ranks.
Rules of a Valid Hreflang Set
A working hreflang set follows a few strict rules:
- Every URL must be absolute, including
https://. - Each code must use a valid language code, optionally followed by a region.
- Every page in the set must list all versions, including itself.
- Annotations must be reciprocal: if page A points to page B, page B must point back to A.
- Each URL should be indexable and return a 200 status, not a redirect or noindex page.
Break one rule and Google may ignore part of the set or all of it.
Language and region codes that Google accepts
The language code comes first, in ISO 639-1 format: en, es, fr, de, ar, ur, zh. A region is optional and follows a hyphen, in ISO 3166-1 alpha-2 format: en-us, en-gb, es-mx, ur-pk.
You can also add a script for languages written in more than one, such as zh-hant for Traditional Chinese.
Common errors to watch for:
en-uk: the United Kingdom’s code isgb, so useen-gb. The generator warns you about this one.- Underscores:
en_USbelongs in Open Graph, not hreflang. The generator flags it as an invalid code; use a hyphen. - Region alone:
gbon its own is read as a language code, not a country. Always start with the language.
Codes are case-insensitive; the tool writes them in lowercase.
Self-referencing and return links
Each page must include a hreflang tag pointing to itself, alongside the tags for every other version. If you have three versions, every one of the three pages carries the same three tags (plus x-default if used).
Return links are the most common failure point. If the English page lists the Spanish page but the Spanish page doesn’t list the English page back, Google can’t confirm the relationship and may ignore those annotations.
The simplest approach is to use one identical block on every page in the set. That is exactly what this generator produces.
When to add x-default
x-default names the fallback page for searchers who don’t match any listed language or region. It is often a language selector page or your main international version.
For example, if you have en-us, en-gb and es-mx, a searcher in Germany using German matches none of them. With x-default set to your global English page, Google knows where to send them. It is optional but recommended for most international sites.
How to Build Tags With the Hreflang Generator
- Add your first language version. Enter the language-region code, such as
en-us, and its full page URL. - Add more versions. Click “+ Add language” for each translated or localized version. Use the ✕ button to remove a row.
- Set the x-default URL. Enter the fallback page URL. The tool marks this as recommended.
- Choose an output format. Pick HTML
<link>tags, XML sitemap or HTTP headers. - Click Generate hreflang. The code appears with any warnings above it: invalid codes, non-absolute URLs or
en-uk. - Fix any warnings and generate again.
- Copy or download the output.
- Add the same set to every version. Paste the identical block on each page in the set, or use the sitemap output once for all.
Everything runs 100% in your browser. Nothing you enter is uploaded.
Head Tags, HTTP Headers or XML Sitemap
Google supports three implementation methods. Pick one per set rather than mixing them.
HTML head tags are the most common choice. Each page carries <link rel="alternate" hreflang="..." href="..." /> lines in its HTML head. They are easy to check in the page source but add weight to every page on sites with many languages.
HTTP headers use a Link: header sent by the server. This is the only method for non-HTML files such as PDF files, because they have no head section. It requires server configuration.
XML sitemap annotations list each URL with <xhtml:link> children for every alternate. This keeps page code light and puts all relationships in one file, which suits large sites. The generator outputs a complete urlset with the right namespace, with one entry per language version.
How Hreflang Works With Canonical Tags
Hreflang and canonical tags must work together, not against each other. Each language version should have a self-referencing canonical, pointing to its own URL.
A common mistake is setting the canonical of every translated page to the English version. That tells Google the translations are duplicates of the English page, which conflicts with hreflang saying they are alternates. Google will usually trust the canonical and drop the other versions from results.
Also make sure every URL in your hreflang set is the canonical version. If a listed URL redirects or canonicalizes elsewhere, the annotation breaks.
Implementation Errors That Break Hreflang
- Missing return links. Each page must point back to the others.
- No self-reference. Every page must list itself.
- Invalid codes.
en-uk, underscores, or a country code used without a language. - Relative URLs. Hreflang URLs must be absolute.
- Pointing to redirects or 404s. Every URL needs a 200 status.
- Noindexed alternates. A noindex page can’t be swapped into results.
- Cross-language canonicals. Canonicals should be self-referencing.
- Mixing methods inconsistently. Head tags saying one thing and a sitemap another.
- Tags in the body. Hreflang link tags only work in the head.
- Partial sets. Adding a new language to one page but not to the others.
When a Site Does Not Need Hreflang
Hreflang isn’t required if your site has only one language and one target market. It also adds little when you have translations but each language targets a completely different audience with distinct, well-linked content.
Small sites with two clearly separated languages can often get by with good internal linking, a clear language switcher and the HTML lang attribute. Hreflang becomes important when you have similar content for several regions in the same language, or many language versions competing in search.
Validating Tags After Launch
Once live, check a few pages in each language. View the source and confirm every version lists all the others plus itself. Use a site crawler or a hreflang checker to scan the full set for missing return links and invalid codes. In Google Search Console, use URL Inspection to confirm each localized page is indexed with its own canonical, and review traffic by country in the Performance report.
Keeping Every Language Version in Sync
Whenever you add, move or remove a localized page, update the hreflang set on every version at once. Pair it with clean canonical tags from the Meta Tag Generator, a full URL list from the XML Sitemap Generator, and correct redirects from the .htaccess Redirect Generator. See all tools on the FHSEO Hub free SEO tools page.
