🌐 Hreflang Tag Generator
By ToolNimba SEO Team · Updated 2026-06-19
Use a language code (en), optionally with a region (en-GB). Each URL should be the absolute, canonical address of that version. Leave a row blank to skip it.
x-default points to the page shown when no other language fits the visitor. Often your homepage or a language picker. Leave the URL blank to omit it.
Add a language and URL to build your hreflang tags.
Hreflang tags tell search engines which language and regional version of a page to show each visitor. This generator turns a simple list of language-region codes and URLs into valid <link rel="alternate" hreflang="..."> tags, including an optional x-default entry. Add a row for each version, copy the output, and paste it into the <head> of every page in the set. Everything runs in your browser, so your URLs never leave your device.
What is the Hreflang Tag Generator?
Hreflang is an HTML attribute (and an equivalent sitemap or HTTP-header signal) that Google and Yandex use to serve the right language or regional URL in search results. A page about the same product in English, British English, and Spanish is three separate URLs, and without hreflang a search engine might show the wrong one to a user, or treat the near-duplicate pages as competing for the same query. Hreflang resolves this by mapping each URL to a language code (like es) or a language-region code (like en-GB), so the engine can match the page to the user's own language and location settings.
The value has two parts: a language in ISO 639-1 (two letters, such as en, es, de) and an optional region in ISO 3166-1 Alpha-2 (such as GB, US, MX) joined by a hyphen. The language comes first and is required, the region is optional and refines it. So en targets all English speakers, while en-GB targets English speakers in the United Kingdom specifically. A common mistake is using a country code on its own (using uk or gb instead of en-GB), which is invalid because the first subtag must be a language.
Two rules make or break an hreflang setup. First, the tags must be reciprocal: if page A links to page B with hreflang, page B must link back to page A, or search engines ignore the annotations. Second, every page in the cluster should be self-referencing, meaning it includes an hreflang tag pointing to its own URL alongside the tags for its alternates. The special value x-default is not a language at all, it marks the fallback page (often a homepage or a language selector) shown when none of the listed languages matches the visitor.
When to use it
- Telling Google to serve the British English page to UK visitors and the US English page to American visitors instead of mixing them up.
- Stopping near-duplicate language versions of the same page from competing against each other in search results.
- Setting an x-default fallback so visitors whose language is not covered land on a sensible homepage or language picker.
- Generating the matching reciprocal tags for a small set of localized pages before pasting them into each page head.
How to use the Hreflang Tag Generator
- Add a row for each language version: enter the code (en, en-GB, es-419) and that version's absolute URL.
- Use the + Add language button for as many versions as you have.
- Tick "Add an x-default entry" and enter the fallback URL if you want a catch-all version.
- Copy the generated tags and paste them into the <head> of every page in the set, then confirm each page links back to all the others.
Formula & method
Worked examples
A shop has one page in three versions: generic English, British English, and Spanish, with a homepage fallback.
- Add row 1: code en, URL https://example.com/
- Add row 2: code en-GB, URL https://example.com/en-gb/
- Add row 3: code es, URL https://example.com/es/
- Tick x-default and set its URL to https://example.com/
- Copy the four <link> lines into the <head> of all three pages.
Result: <link rel="alternate" hreflang="en" href="https://example.com/" />, <link rel="alternate" hreflang="en-GB" href="https://example.com/en-gb/" />, <link rel="alternate" hreflang="es" href="https://example.com/es/" />, <link rel="alternate" hreflang="x-default" href="https://example.com/" />
A regional rollout targets Spanish in Spain, Mexico, and Latin America generally.
- Add row 1: code es-ES, URL https://example.com/es-es/
- Add row 2: code es-MX, URL https://example.com/es-mx/
- Add row 3: code es-419 (Latin America), URL https://example.com/es-419/
- Each page must include all three tags plus a tag pointing to itself.
Result: Three reciprocal <link rel="alternate" hreflang="es-ES | es-MX | es-419"> tags, each present on every page in the cluster.
Common hreflang values and what they target
| hreflang value | Meaning |
|---|---|
| en | English, any region |
| en-US | English, United States |
| en-GB | English, United Kingdom |
| es | Spanish, any region |
| es-419 | Spanish, Latin America (UN M49 region code) |
| fr-CA | French, Canada |
| x-default | Fallback for unmatched languages or regions |
The three ways to declare hreflang (pick one method per page set)
| Method | Where it goes | Best for |
|---|---|---|
| HTML link tags | In the <head> of each page | Most sites and static pages |
| XML sitemap | xhtml:link entries in the sitemap | Large sites, keeps page <head> light |
| HTTP header | Link: header in the server response | Non-HTML files such as PDFs |
Common mistakes to avoid
- Using a country code as the language. The first subtag must be a language (ISO 639-1), not a country. Writing hreflang="uk" targets Ukrainian, not the United Kingdom. For British English use hreflang="en-GB".
- Missing return (reciprocal) tags. If page A points to page B but B does not point back to A, search engines drop the annotation. Every page must link to every other version in the set, including itself.
- Forgetting the self-referencing tag. Each page should include an hreflang tag for its own URL. Listing only the other versions is incomplete and weakens the cluster.
- Using relative or non-canonical URLs. hreflang URLs must be absolute (starting with https://) and should point to the canonical, indexable version of each page, not a redirect or a noindex URL.
- Treating x-default as a language. x-default is a fallback marker, not a locale. Use it once for the page shown when no listed language matches, typically a homepage or a language selector.
Glossary
- hreflang
- An attribute that tells search engines the language and optional region a page targets, so they can serve the right version.
- rel="alternate"
- The link relationship that marks a URL as an alternate version of the current page, used together with hreflang.
- x-default
- A special hreflang value marking the fallback page shown when none of the listed language or region versions matches the visitor.
- ISO 639-1
- The two-letter language code standard (en, es, de) used for the first part of an hreflang value.
- ISO 3166-1 Alpha-2
- The two-letter country code standard (US, GB, MX) used for the optional region part of an hreflang value.
- Reciprocal (return) tags
- The requirement that every page in a language set links back to every other page, or search engines ignore the hreflang signals.
Frequently asked questions
What is an hreflang tag?
An hreflang tag is a <link rel="alternate" hreflang="..."> element that tells search engines which language and regional version of a page to show a given user. It connects the different language versions of the same content so Google and Yandex serve the right URL.
Do I need a region code, or is the language enough?
The language code alone is enough and is required (for example es). The region is optional and only needed when you have different content for the same language in different countries, such as en-GB versus en-US. Do not add a region unless the pages actually differ by country.
What does x-default do?
x-default marks the fallback page shown when none of your listed languages or regions matches the visitor. It is usually a homepage or a language-selector page. It is optional but recommended, and you use it once across the set.
Where do I put the generated tags?
Place the tags in the <head> section of every page in the language set. Each page must include the full set, including a tag pointing to its own URL, and every page must link back to all the others for the annotations to count.
Why are my hreflang tags being ignored?
The most common cause is missing return tags: if page A points to page B but B does not point back to A, search engines discard the annotation. Other causes are relative URLs, pointing to redirected or noindex pages, or using a country code where a language code belongs.
Does hreflang replace a canonical tag?
No. They work together. Each language version should be self-canonical (its canonical points to itself), while hreflang links the versions to each other. Pointing a canonical at a different language version cancels the hreflang signal, so keep them consistent.
Sources
- Tell Google about localized versions of your page , Google Search Central
- rel="alternate" hreflang="x" (BCP 47 language tags) , IETF / W3C