Generate hreflang tags for multilingual sites
When the same content exists in several languages or for several countries, hreflang annotations tell Google and Yandex which version to show to which users. Without them, a German visitor may land on your US page, or regional versions may compete with each other. This hreflang generator checks the format of your language codes and outputs the annotations in three formats.
Example
<link rel="alternate" hreflang="en" href="https://www.example.com/en/" />
<link rel="alternate" hreflang="en-GB" href="https://www.example.com/uk/" />
<link rel="alternate" hreflang="de" href="https://www.example.com/de/" />
<link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
Rules that matter
- Codes: an ISO 639-1 language (
de), optionally followed by an ISO 3166-1 region (de-AT). A region alone, such asuk, is invalid — and "uk" is actually Ukrainian. The generator rejects malformed codes and normalises case (en-gb→en-GB,zh-hans-cn→zh-Hans-CN). It checks the shape of a code, not a list of real codes, so a three-letter language such aseng, a numeric region such ases-419and a wrong region such asen-UKare accepted as typed. The same code entered twice, in any letter case, is reported as a duplicate. - Return links: every page in the set must list all versions, including itself. If page A points to B but B does not point back, search engines ignore the pair.
- Absolute URLs are required, and they should be the canonical URLs of each version.
- x-default marks the fallback page, often a language selector or your main international version.
Choosing the hreflang generator output
HTML tags go in the <head> of each page and are the most common choice. XML sitemap entries keep annotations out of your templates, which is convenient for large sites — generate the base sitemap with the XML sitemap generator and add the xhtml namespace. The HTTP Link header is the only option for non-HTML files such as PDFs.
The sitemap and header formats side by side
In a sitemap, each <url> repeats the full set of alternates, and the <urlset> element must declare xmlns:xhtml="http://www.w3.org/1999/xhtml":
<url>
<loc>https://www.example.com/en/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en/"/>
<xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/de/"/>
</url>
For a PDF, the server sends the same information in one header, with the alternates separated by commas:
Link: <https://www.example.com/en/guide.pdf>; rel="alternate"; hreflang="en",
<https://www.example.com/de/guide.pdf>; rel="alternate"; hreflang="de"
Pick one method per page set; mixing them makes errors harder to trace.
Common mistakes
Pointing hreflang at redirected or noindexed URLs, using a canonical tag that points all language versions to one page, and forgetting self-references are the errors seen most often in audits. Check your other head tags with the meta tag generator.
Language or language plus region?
Use a bare language code when a page serves all speakers of that language, such as de for one German site. Add a region only when content really differs between countries — prices in euros versus Swiss francs, different shipping, spelling differences between en-US and en-GB. You can combine both: en as a general English page plus en-GB and en-AU for specific markets. Users whose region is not listed then get the general language version.
Privacy
The tool runs entirely in your browser. Nothing you type or paste is sent to our servers.