Hreflang Tag Generator
Enter each language or country version of a page and get the complete hreflang set two ways: HTML link tags for the head, or xhtml:link entries for an XML sitemap. The tool validates every row as you type — relative URLs are rejected, malformed codes get a suggested fix (the classic en-UK → en-GB), duplicate locales are flagged, and a missing x-default triggers a warning.
Add at least one row with an absolute URL and a language code to generate tags.
How to use the hreflang tag generator
- Add one row per page version: the absolute URL, a 2-letter ISO 639-1 language code, and optionally a 2-letter ISO 3166-1 region code. Use bulk paste (url,lang-REGION per line) for large groups.
- Mark one row as x-default — the page visitors should land on when no locale matches.
- Fix any red errors and review the amber warnings (wrong codes, duplicates).
- Copy the HTML tab into the <head> of every page in the group, or the XML tab into your sitemap — remembering each URL needs its own <url> entry carrying the full link set.
Worked example: one page, three locales
A pricing page with a US English version, a British English version, and a Spanish version. Every one of the three pages must carry this exact block (note the self-reference — each page lists itself too):
<link rel="alternate" hreflang="en-US" href="https://example.com/pricing" /> <link rel="alternate" hreflang="en-GB" href="https://example.com/uk/pricing" /> <link rel="alternate" hreflang="es" href="https://example.com/es/pricing" /> <link rel="alternate" hreflang="x-default" href="https://example.com/pricing" />
The format is always language first (ISO 639-1, lowercase), then an optional region (ISO 3166-1 alpha-2, conventionally uppercase), joined by a hyphen. Region-only values like hreflang="US" are invalid — a language is mandatory. And the single most copied mistake on the internet: the United Kingdom is GB, not UK, so British English is en-GB.
Frequently asked questions
What are the three hreflang errors that dominate audits?
First, missing return tags: if page A lists page B as an alternate, page B must list page A back, or Google ignores the annotation entirely — this is why you paste the complete identical block on every page in the group. Second, invalid codes: en-UK instead of en-GB, jp instead of ja, or using a country code where a language code belongs. Third, relative URLs: hreflang href values must be absolute, including protocol. These three account for the large majority of hreflang failures in Semrush and Ahrefs audit data.
Do I need hreflang if my site is only in English?
Only if you target different countries with separate English pages — for example example.com/us/ and example.com/uk/ with different prices, currencies, or spellings. Then en-US and en-GB annotations stop Google from treating them as duplicates and showing the wrong one. A single English site serving everyone needs no hreflang at all; do not add it ritually.
What does x-default actually do?
It names the fallback page for users whose language or region matches none of your alternates — a Japanese searcher when you only have English, Spanish, and German versions. It usually points to your global or English page, or to a language-selector page. It is optional in the spec but strongly recommended in practice, and this tool warns when it is missing. The x-default URL can be the same URL as one of your language rows; that is a valid and common pattern.
Should I put hreflang in the head or in the XML sitemap?
Functionally they are equivalent — pick one and be consistent (using both invites contradictions). Head tags are easier to template for small sites. Sitemaps win for large sites: with 30 locales, head tags add 30+ lines of markup to every page (bytes on every request), while the sitemap centralizes the mapping and is easier to regenerate from a database. Sites above a few thousand pages per locale almost always choose the sitemap route.
Can the same URL appear with two different hreflang values?
Yes — that is a valid pattern. A single page can serve, say, both en and en-US (one URL listed twice with different hreflang values), and the x-default typically duplicates an existing URL too. What you cannot have is the reverse: one locale pointing at two different URLs, which is the duplicate-locale warning this tool raises.
Does hreflang boost rankings?
No. Hreflang is a swapping signal, not a ranking signal: when any version of the page ranks, Google swaps in the most appropriate locale version for that searcher. Rankings are shared across the group via canonical-like consolidation, but you will not rank higher just by adding hreflang — you will stop showing German users the French page, which lifts CTR and cuts pogo-sticking.
Related tools
- Open Graph Meta Tag GeneratorGenerate Open Graph and Twitter Card meta tags with live social previews for Facebook, X, LinkedIn, and Discord — copy the HTML in one click.
- FAQ Schema GeneratorGenerate FAQPage JSON-LD schema: add questions and answers, get valid markup with inline validation, and copy or download the script tag.
- SERP Snippet Preview & Meta Length CheckerPreview your Google snippet pixel-accurately and check title tag and meta description lengths before you publish — desktop and mobile views.
- Robots.txt GeneratorGenerate a robots.txt file visually — user-agent groups, Allow/Disallow rules, AI-bot blocking presets, sitemap lines. Copy or download instantly.
- Article Schema GeneratorGenerate Article, NewsArticle, or BlogPosting JSON-LD schema with author, publisher, and dates. Copy valid markup for Google article rich results.
- Conversion Rate CalculatorCalculate conversion rate from conversions and visitors, solve for the conversions or traffic you need, and get revenue per visitor from your AOV.