Free tool
Hreflang Tag Generator
Enter each language version of a page and get the hreflang tags for your HTML head or XML sitemap, checked against the codes Google accepts.
Language versions
One row per URL. Code examples: en, en-GB, es-MX, zh-Hant-TW
Add this to the <head> of every page in the set
Or use your XML sitemap instead
How to use the hreflang generator
- Enter the full URL of each language or regional version of the same page, starting with
https://. - Next to each URL, enter its code: a language (
de), or a language and a country (de-AT). The field suggests common codes. - Choose whether to add
x-defaultand which URL it should use. - Copy the HTML block into the
<head>of every page in the set, or use the XML sitemap version instead.
The generator checks every code against the lists Google accepts: ISO 639-1 for the language, optionally an ISO 15924 script (zh-Hant), and ISO 3166-1 alpha-2 for the country. It flags duplicate codes, relative URLs and frequent mistakes such as en-UK.
The rules the generator follows
Google’s documentation on localized versions sets out the rules, and the tool applies them:
- Fully qualified URLs.
https://example.com/de/, never/de/. - Every version lists every version, including itself. That is why the same block goes on all the pages.
- Return links. If the English page points to the German page, the German page must point back.
- Country codes are optional, language codes are not.
detargets German speakers anywhere;de-ATtargets German speakers in Austria. You can’t target a country without a language. - One URL per code. The same
en-GBcan’t point to two pages.
Mistakes we see most often
Missing return links, hreflang pointing at redirected or non-canonical URLs, and invalid codes are the classic errors. In Ahrefs’ study of 374,756 domains, 67% of domains using hreflang had at least one issue.
If you are planning a multilingual site, hreflang is one part of the job:
Frequently asked questions
Do hreflang tags need to be on every language version?
Yes. Every version in the set must list all the versions, including itself, and the annotations must point back to each other. If page A links to page B but B doesn't link back to A, Google may ignore the pair.
Should I use en-UK or en-GB for the United Kingdom?
en-GB. Region codes are ISO 3166-1 alpha-2 country codes, and the code for the United Kingdom is GB. UK is a common mistake that makes the annotation invalid.
What is x-default in hreflang?
x-default tells Google which page to show to users whose language or region doesn't match any of your versions, often a language selector or your main international page. It is optional but recommended.
Is it better to put hreflang in the HTML or in the sitemap?
Both are supported and equivalent for Google. HTML link tags are easier for small sites; the sitemap is easier to maintain for large sites because the pages' HTML doesn't change. Use one method consistently.
Can hreflang point to a page with a different canonical?
No. Each language version should have a self-referencing canonical, and hreflang should point to those canonical URLs. Pointing hreflang at non-canonical or redirected URLs is one of the most common errors.
Related guides
Free SEO Tools
Four free tools for international and technical SEO. They run entirely in your browser: nothing you enter is sent to us.
2 min read
