Hreflang Tag Generator
Build hreflang clusters from locale and URL rows, then copy head tags, sitemap XML, or HTTP headers with self-reference audits.- {{ issue }}
{{ headTags || emptyHeadMessage }}
{{ sitemapXml || emptySitemapMessage }}
{{ httpHeader || emptyHeaderMessage }}
| Locale | URL | Label | Status | Copy |
|---|---|---|---|---|
| No alternate rows are ready yet. | ||||
| {{ row.locale }} | {{ row.url }} | {{ row.label || '—' }} | {{ row.status }} {{ row.note }} | |
| Check | Status | Detail | Copy |
|---|---|---|---|
| {{ row.check }} | {{ row.status }} | {{ row.detail }} |
Introduction:
International SEO becomes fragile when several URLs answer the same search intent for different audiences. A retailer may have one product page for the United States, another for the United Kingdom, a Malay version for Malaysia, and a neutral selector for everyone else. Search engines need more than visible language to understand that these URLs are alternatives, not accidental duplicates.
Hreflang annotations describe that relationship. Each annotation connects a locale code with the URL that serves that language or language-region audience. A complete cluster lets search engines choose a better result for a user in London, Kuala Lumpur, or Toronto while keeping the equivalent pages tied together as one international content set.
Hreflang is not a redirect rule, a translation checker, or a replacement for canonical tags. It does not force a search engine to index a page, and it does not repair thin localization. The pages still need crawlable final URLs, sensible canonicals, useful localized content, and return links that repeat the same alternate set from every version.
- Locale code
- The language or language-region value, such as
en,en-GB,fr-FR, orzh-Hant-TW. - Alternate URL
- A fully qualified
httporhttpsURL for a localized version of the same content intent. - Self-reference
- The current localized page includes its own locale and URL in the alternate set.
- Return link
- Each localized page points back to every other page in the same cluster, not only outward from one master page.
- x-default
- A reserved fallback for users whose language or region is not covered by the explicit locale rows.
x-default for a real fallback destination.Hreflang can be published in three common places: link elements inside an HTML head, alternate entries inside an XML sitemap, or HTTP Link headers for resources without an HTML head. Those methods express the same relationship, so one maintained source is usually safer than three separate copies that can drift.
The mistakes are often small: region-only values such as US, relative paths such as /fr/, missing self-references, a selector page without x-default, or one localized page listing alternates that the others do not return. Hreflang works best as a complete reciprocal map, not as a tag added to one preferred URL.
How to Use This Tool:
Start with the locale and URL rows you intend to publish, then use the generated code and audit output to catch row errors before the cluster reaches page templates, sitemaps, or response headers.
- Paste Locale URL rows with one locale and one fully qualified URL per line. CSV, tab, pipe, and first-space separated rows are accepted, and a third value can be used as a human label.
- Set Current page locale to the locale of the page where this alternate set will be installed. The summary and Implementation Audit use that value to check the self-reference.
- Keep Add x-default fallback when missing enabled when you have a language selector, global home page, or accepted default URL for unmatched users. The fallback URL must be complete and use
httporhttps. - Open Advanced when pasted rows need cleanup. Normalize locale case converts values such as
EN_ustoen-US, Output order controls generated ordering, and Duplicate locale policy chooses whether the first or last valid duplicate row feeds the output. - Use Normalize rows when you want to rewrite the textarea from the current valid non-
x-defaultrows. This is useful after importing mixed separators or inconsistent locale case. - Check the summary before copying. Needs fixes means row errors or an empty valid set block code copying. Cluster review means code exists, but warnings such as missing self-reference, missing
x-default, duplicate locales, or missing language-wide fallback rows need judgment. - Copy Head Tags for HTML page heads, Sitemap XML for sitemap-managed alternates, or HTTP Header for non-HTML resources. Use Alternate Ledger and Implementation Audit to confirm which rows were kept, skipped, warned, or blocked.
Interpreting Results:
The generated code tabs are different serializations of the same valid alternate set. Head Tags belongs inside the HTML <head>. Sitemap XML repeats the alternate set under each URL entry. HTTP Header formats the same relationship as a response header for files or systems where page-head markup is not available.
The Alternate Ledger explains each source row. A Ready row can appear in the generated cluster. A Warning row is still eligible but needs review, often because a locale is unusual or a duplicate row was kept. A Skipped row was valid but lost to the selected duplicate policy. An Error row does not feed the output.
The Implementation Audit is a pre-publication checklist, not a live crawl. A clean audit does not prove that the final URLs are indexable, self-canonical, installed in the rendered head, returned from every alternate URL, or accepted by Google. After publishing, inspect the final head, sitemap, or response header from each localized URL.
Treat missing x-default and language-wide fallback warnings as review prompts. They are not always wrong, but they often reveal a poor experience for users outside the listed regions.
Technical Details:
An hreflang annotation combines an alternate relationship, a language tag, and an absolute destination URL. The relationship says the URLs are equivalent choices for the same content intent. The language tag identifies the target language or language-region audience. The URL must be final and fully qualified because a search engine cannot interpret a relative path without the current page context.
Google's public guidance centers on two-letter ISO 639-1 language codes with optional ISO 3166-1 Alpha 2 region codes. Script subtags can appear in language tags, but a region by itself is not a language target. Values such as EU, UN, and UK are warned because they look meaningful in a spreadsheet while not behaving like normal assigned country-code targets for hreflang.
Transformation Core:
| Stage | Mechanism | Practical result |
|---|---|---|
| Row parsing | The first cell becomes the locale, the second cell becomes the URL, and remaining text becomes a label. Rows may use CSV, tabs, pipes, or first whitespace separation. | Spreadsheet rows work when locale and URL stay in the first two positions. |
| Locale cleanup | Underscores are converted to hyphens. When normalization is enabled, language subtags are lowercased, two-letter regions are uppercased, four-letter scripts are title-cased, and x-default stays lowercase. |
EN_us becomes en-US, making source review and duplicate detection easier. |
| URL validation | Only complete http and https URLs are allowed into the valid alternate set. |
Relative paths, protocol-relative URLs, blank URLs, and malformed addresses are reported before generated code is copied. |
| Fallback insertion | When enabled and no valid source row already uses x-default, a fallback row is added from the fallback URL field. |
A selector page or global default can be included without adding another source row. |
| Duplicate selection | Duplicate locales are flagged, then the selected first-or-last policy decides which valid row appears in the generated cluster. | Accidental duplicate rows stay visible in the ledger instead of silently overwriting each other. |
| Cluster ordering | The valid alternate set can keep input order or sort by locale or URL. | Input order matches a spreadsheet review; locale order is easier to compare in source control. |
Rule Core:
| Rule | Ready condition | Common fix |
|---|---|---|
| Absolute URL | Every generated alternate has a complete http or https URL. |
Replace /fr/ or //example.com/fr/ with the final canonical URL. |
| Self-reference | The current page locale appears in the valid alternate set. | Add the current page's locale and final URL to the source rows. |
| Return links | Each localized page publishes the same set of alternates, including itself. | Install the identical cluster on every equivalent page and test the rendered output. |
| Language fallback | Several regional pages for one language have a generic language row when that fallback page exists. | Add a generic en, fr, or similar row for users outside the listed regions. |
| Unmatched users | x-default points to a neutral selector, global page, or accepted default page. |
Use a real fallback destination rather than a random localized version. |
Publishing Methods:
| Method | Shape | Best fit |
|---|---|---|
| HTML head | <link rel="alternate" hreflang="en-GB" href="https://example.com/gb/" /> |
Template-managed HTML pages where each localized page can render its own head tags. |
| XML sitemap | A <url> entry with repeated <xhtml:link> children and the xhtml namespace declared. |
Large URL inventories where localization data is easier to manage centrally. |
| HTTP header | One Link header value containing each alternate URL with rel="alternate" and hreflang. |
Non-HTML resources or systems that cannot add link elements inside a page head. |
Worked Mechanism Path:
A pasted row of EN_us, https://example.com/us/, United States separates into locale, URL, and label. With locale normalization enabled, the locale becomes en-US. The URL passes because it has an https scheme and a hostname. If no earlier valid en-US row exists under a keep-first duplicate policy, the generated head tag uses that normalized locale and URL.
No numeric formula is involved. The auditable logic is row parsing, locale normalization, URL validation, duplicate selection, fallback insertion, and cluster completeness.
Accuracy Notes:
The generated output checks the rows you provide, not the live web. It does not fetch pages, crawl return links, inspect canonical tags, or confirm that search engines have accepted the annotations.
- Use the audit to catch local row problems before publication.
- After publication, inspect the rendered head, sitemap, or response header from the final public URL.
- Avoid sharing copied code, exported JSON, or screenshots when they contain private staging hostnames.
Worked Examples:
Regional product pages. Rows for en-US, https://example.com/us/product/, en-GB, https://example.com/gb/product/, and fr-FR, https://example.com/fr/produit/, plus an x-default selector URL, produce four alternates. If Current page locale is en-US, the self-reference audit is ready because the current page is present in the generated cluster.
Duplicate spreadsheet row. If two valid rows both use en and Duplicate locale policy is set to keep the first valid row, Alternate Ledger marks the first duplicate as kept and the later duplicate as skipped. Implementation Audit keeps the duplicate warning visible so the spreadsheet can be cleaned before deployment.
Relative path blocked. A row such as ms-MY, /my/ triggers a row error because the URL is not fully qualified. The summary moves to Needs fixes, code copy actions are disabled, and the fix is to replace the path with a final URL such as https://example.com/my/.
Regional fallbacks reviewed. A set with en-US, en-GB, and en-AU but no generic en row can still generate tags. The audit warning is a reminder to decide whether a language-wide English page should exist for users outside those listed regions.
FAQ:
Do hreflang tags replace canonical tags?
No. Hreflang declares localized alternates, while canonical tags describe the preferred indexing URL. Localized pages usually need canonicals that agree with the intended indexable page.
Should every page include itself?
Yes. The self-reference check compares Current page locale with the generated alternates because each version should list itself and all other versions.
When should I add x-default?
Add x-default when you have a language selector, global landing page, or accepted default page for users whose language or region is not covered by explicit alternates.
Can alternate URLs be on different domains?
Yes. Cross-domain alternates are allowed when the relationship is real and every page returns the same alternate set. The audit notes domain spread so you remember to test both sides after publication.
Why are my tags not available to copy?
Code copying is blocked when there are row errors or no valid alternates. Check the warning box and Alternate Ledger for blank locales, invalid rows, relative paths, or URLs without http or https.
Should I publish head tags, sitemap XML, and HTTP headers together?
Usually no. Google treats the methods as equivalent signals, so one maintained source is easier to keep correct. Use a different method only when the page type or platform needs it.
Glossary:
- Hreflang
- A language or region annotation that connects equivalent localized URLs.
- Locale code
- The language, region, or script value assigned to an alternate URL, such as
enorzh-Hant-TW. - Alternate URL
- A localized URL that represents the same content intent as the other URLs in the cluster.
- Self-reference
- The row that points from a localized page back to its own locale and URL.
- Return link
- The reciprocal annotation that lets each localized page point back to the other pages in the same cluster.
- x-default
- The reserved fallback value for users whose language or region is not covered by the explicit alternates.
References:
- Tell Google about localized versions of your page, Google Search Central.
- How x-default can help you, Google Search Central Blog.
- Sitemaps XML format, sitemaps.org.
- RFC 8288: Web Linking, IETF.