By · Updated

hreflang Generator

Language Code and URL Pairs as Link Tags, HTTP Headers or Sitemap XML

No ratings yet

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the Hreflang Generator works

This hreflang generator writes the link tags for each language version. Type one line per language version — en-GB | https://example.com/uk/, fr | https://example.com/fr/ — and the tool writes the complete reciprocal set of hreflang annotations in whichever form your site can emit: <link> tags for the <head>, a Link: HTTP header for PDFs and other non-HTML files, or an XML sitemap with xhtml:link entries. Codes are validated against the ISO formats Google accepts, absolute URLs are enforced, and an x-default is added if you did not list one.

Hreflang generator: codes and x-default

hreflang tells search engines that a set of pages are the same content in different languages or for different regions, so that a searcher in Paris is shown the French page and one in Sydney the Australian one rather than whichever version happened to rank. It only works when every page in the set lists every other page, including itself, with exactly matching URLs — which is why the tags are best generated rather than typed.

Codes. The language is a two-letter ISO 639-1 code in lower case: en, fr, de, ja. An optional region is a two-letter ISO 3166-1 alpha-2 code in upper case, joined with a hyphen: en-GB, en-US, pt-BR, es-MX. A script subtag can sit between them for languages written in more than one script: zh-Hans-CN, zh-Hant-TW. The classic mistakes are all caught: en-UK (the code for the United Kingdom is GB), en-gb (region must be upper case, though Google tolerates it), uk on its own (that is Ukrainian), and three-letter language codes. You cannot target a region without a language — GB alone is invalid.

x-default. The x-default alternate is the page shown when no other version matches the searcher's language and region — typically the language selector, or the English page if there is no selector. Google recommends including one in every set. If you do not list it, the tool uses the first URL you typed, which is usually the primary language; choose "Only if listed" to suppress that.

Reciprocity. Every page in the set must carry the same full list. If the French page links to the English one but the English page does not link back, Google ignores the French annotation. That is why the output is the whole set rather than "the tags for this page": paste the same block into every page. The self-referencing entry is required, not optional.

Which format. <link> tags in the <head> are simplest for HTML pages served by a template. The Link: HTTP header does the same job for files that have no <head> — PDFs, images — and for cases where you cannot touch the HTML. The sitemap form scales best: on a site with twenty languages, twenty <link> tags on every page is a lot of bytes, whereas the sitemap lists each page once with its alternates and the pages stay clean. Pick one method per page set; mixing them is allowed but makes conflicts likely.

Sitemap output. Each page becomes a <url> element with its own <loc> and the complete list of xhtml:link alternates, including itself and x-default. The x-default URL does not get its own <url> entry unless it is also a real language page you listed separately; it is referenced from the others. The namespace declaration on <urlset> is included; if you are merging into an existing sitemap, make sure xmlns:xhtml is declared there.

Interaction with canonical. Each language page should be its own canonical. A French page whose canonical points at the English one is telling Google the French page is a duplicate, which cancels the hreflang. The one exception is x-default pointing at a page that is also in the set, which is fine. Generate the canonicals with the canonical URL generator, one per language.

FAQ

Do I need hreflang if each language is on its own domain?

Yes, if the pages are translations of each other. hreflang works across domains — example.fr and example.de can annotate each other — and it is how Google learns they are one set rather than two competing sites. All URLs must be absolute for this reason; there is no relative form.

Should I use en or en-US and en-GB?

Use the plain language code unless the versions genuinely differ by region — different prices, spellings, legal text, stock. en matches any English speaker; en-GB matches British searchers preferentially and, if it is the only English page, still serves the rest. Listing both en and en-GB is fine when the pages exist; listing en-GB and en-US with identical content is more work for no gain.

Where does x-default point?

At the page you want shown when nothing else matches. On sites with a language chooser that is the chooser; on most sites it is the main language home page. It can be a URL that is also listed under a language code — it is common for x-default and en to be the same URL.

How can I check that a live site's tags are reciprocal?

Fetch each page in the set and confirm they all carry identical alternates. The meta tag checker on this site reads the hreflang links out of pasted HTML; the sitemap validator counts xhtml:link entries in a sitemap. Google Search Console's international targeting report lists pages with missing return links.

Can I paste the lines in a different format?

Any of code | URL, code, URL, tab-separated, or code URL with a space works. Order is preserved in the output and the first line becomes x-default unless you list one yourself.

See also: all SEO tools, Dev Utilities, Formatters & Validators, Data & Encoding, Security & Identifiers, Accessibility, AI.

Related tools