Hreflang Generator — Create hreflang tags for multilingual sites
Without hreflang, Google may treat your translated pages as duplicates and show the wrong language version in search. Turn a set of language URLs into hreflang markup in three forms: <link> tags, HTTP Link header and sitemap <xhtml:link>. Steps: paste each language URL with its code, choose a form, copy the generated snippet. Every URL gets its own self-referencing hreflang, and an optional x-default fallback can be added. Runs entirely on your device—nothing is uploaded. Example: en, es and ja versions of one page.
How it works
The generator parses each line into a language code and a URL, then renders the same set of relationships in three forms. The <link> form goes into the <head> of each page. The HTTP Link header form is set on the server response. The sitemap form embeds <xhtml:link> inside each <url> block. Every URL gets a self-referencing hreflang so each language version points back to itself, and the optional x-default entry covers visitors whose language is not listed.
Rules used by the generator
These rules come from Google Search Central and the BCP 47 language tag standard.
- Each language version must include a self-referencing hreflang that points back to its own URL. Skipping it weakens the signal.
- Every URL must be listed from every language version: the full set of alternates appears on each page, not just one direction.
- Language codes use BCP 47: a two-letter language, optionally a region (en-US) and optionally a script (zh-Hans). x-default is the special fallback code.
- x-default points to the page shown when no listed language matches, for example an English root page. Google may use it as a fallback for all undetected languages.
- Choose one delivery form per set: the <link> tags in HTML, the HTTP Link header, or sitemap xhtml:link. Do not mix forms for the same page set, or signals can contradict.
Example
The sample lists three versions of one page: https://example.com/ (en), https://example.com/es/ (es) and https://example.com/ja/ (ja). The generated <link> tags include self-references for each language plus an optional x-default pointing to the English root.
Good use cases
- Launching a multilingual site: generate the <link> tags for each template once and verify every language version lists the full set.
- After a site restructure, regenerate the markup so the URL mapping stays consistent across languages instead of drifting.
- When search results show the wrong language, check that self-references and x-default exist and that the URLs point to canonical pages.
Frequently asked questions
Which of the three forms should I use?
Use the <link> tags when you can edit the page HTML. Use the HTTP Link header when pages are served by a server you control and HTML is hard to change. Use the sitemap form when you prefer keeping it in the XML sitemap.
When should I add x-default?
x-default tells Google which version to show when the visitor language does not match any listed code. Add it when you have a root or fallback page, usually English.
Does every URL need a self-referencing hreflang?
Yes. Each language version must include its own URL in the set, with a self-referencing hreflang pointing back to itself. Google uses the complete set to pick the right page per language.
What language code format is valid?
BCP 47 codes: a two- or three-letter language, optionally a region (en-US) and optionally a script (zh-Hans). Lowercase the language, and do not invent codes such as "en-us-en".
Should hreflang go in <head> or in the sitemap?
Either works, but use one consistent form per page set. The <link> tags live in <head>, the HTTP Link header is sent with the response, and the sitemap uses xhtml:link blocks.
Are my URLs uploaded anywhere?
No. The generator runs entirely in your browser and nothing is uploaded.
Questions or feedback
Something unclear, broken, or missing? Draft a message below — we read every note about these tools.