Hreflang Generator
Turn language-and-URL pairs into hreflang link tags, validating each language tag and URL and refusing a duplicate language.
What the Hreflang Generator does
A language tag is checked against the BCP 47 shape ll, ll-CC or ll-Script-CC, plus x-default. The URL must parse as absolute, and it is normalised by the URL parser so a trailing slash and an encoded character are written once, in one form.
If no x-default entry is present the page says so: without it, a visitor whose language you do not publish has no page offered to them.
The tags are the whole output — where they go and whether the pages actually exist is your job. The page cannot check that a URL returns the language it claims, and it does not fetch anything.
How to use it
Paste one language URL pair per line into the Language and URL pairs box, or press Run with the example already there.
Read the hreflang tags below: one tag per line, in the order you listed them.
Check the note under the hreflang tags — without an x-default entry the page tells you to add one.
Worked example
Input:
en-GB https://example.com/gb
fr https://example.com/fr
Output:
<link rel="alternate" hreflang="en-GB" href="https://example.com/gb">
<link rel="alternate" hreflang="fr" href="https://example.com/fr">
Note: no x-default entry; add one for visitors whose language you do not publish.
Why it runs in your browser
The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.
One `<link rel="alternate" hreflang="…" href="…">` per language you list, with the language tag validated and each URL required to be absolute.
A language listed twice is refused, because two tags for one language make the choice depend on document order — the one thing hreflang exists to remove.
What it does, and what it does not
A language tag is checked against the BCP 47 shape `ll`, `ll-CC` or `ll-Script-CC`, plus `x-default`. The URL must parse as absolute, and it is normalised by the URL parser so a trailing slash and an encoded character are written once, in one form.
If no `x-default` entry is present the page says so: without it, a visitor whose language you do not publish has no page offered to them.
The tags are the whole output — where they go and whether the pages actually exist is your job. The page cannot check that a URL returns the language it claims, and it does not fetch anything.
How to use Hreflang Generator
Paste one `language URL` pair per line into the Language and URL pairs box, or press Run with the example already there.
Read the hreflang tags below: one tag per line, in the order you listed them.
Check the note under the hreflang tags — without an x-default entry the page tells you to add one.
What to Expect
Best for
- Writing the hreflang block for a translated page
- Checking a language tag's shape
Not ideal for
- Verifying that a translated URL exists
- Deciding which language versions to build
What this tool keeps
- Your pair order
- Each URL normalised by the URL parser
What may need cleanup
- Add an x-default entry by hand when you have a fallback
- Place the tags in the head of every version
Common errors
- The page refuses it: "en" is listed twice
Example use cases
- Writing hreflang for a two-language site
- Reviewing a translated section before launch
Sample input
Language and URL pairs: en-GB https://example.com/gb …
Sample output
hreflang tags: <link rel="alternate" hreflang="en-GB" href="https://example.com/gb"> …
Who this is for
- SEO specialists building a multilingual site
- Developers adding alternate links
Frequently asked questions
Is a region required?
No. fr targets French in any region, while fr-CA targets French in Canada. Use the region only when the content actually differs by region.
Why is a duplicate language refused?
Two tags with one hreflang value make the chosen URL depend on document order. The page refuses the second and names the tag.
What is x-default for?
It is the page offered when no listed language matches the visitor. Without it, a visitor whose language you do not publish is offered nothing, so the page notes its absence.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.