Make sure you generate hreflang correctly by building one complete locale-to-URL set, including every alternate and each page’s self-reference, then installing and testing that identical set on every localized page.

Hreflang describes relationships among substantially equivalent pages. A clean-looking tag is only one part of the job: the locale must make sense for the content, every member of the language cluster must publish the complete set, and the live URLs must point to useful pages that link back to one another.

The Hreflang Generator handles the input, validation, canonical locale casing, HTML escaping, and link-block generation. It cannot inspect remote pages or prove that reciprocal links were deployed correctly, so a live verification stage remains essential.

how do i make sure i generate hreflang correctly
How Do I Make Sure I Generate Hreflang Correctly?

What a correct hreflang set must satisfy

Use “correct” as a set of testable conditions rather than treating successful code generation as the finish line. Every correct implementation should meet all of these conditions:

  • Each equivalent localized page appears once, including the page currently being edited.
  • Every localized page publishes the same complete set of alternate references.
  • Each page has a self-reference and return links to all other members of the set.
  • Every listed URL is fully qualified and resolves to a useful page.
  • Each locale accurately represents the language, script, region, and audience of its destination.

Google’s localized versions guidance explains why self and return links matter: a one-way declaration can be ignored because another site must not be able to claim your page as an alternate unilaterally.

Build one source-of-truth inventory

Start with a single list of the pages that are genuinely equivalent. Include the current page, even when it feels redundant, because a self-reference is part of the relationship. Organize the inventory before generating markup so every page can receive the same set without manual drift.

Locale formMeaningExample
LanguageGeneric language targeten
Language-regionLanguage used for a particular regionfr-CA
Language-scriptLanguage distinguished by writing systemzh-Hans
Language-script-regionLanguage, script, and regional targetzh-Hant-TW
x-defaultFallback for unmatched user settingsx-default

The locale field accepts a two-letter language followed by an optional four-letter script and an optional two-letter region. A country code cannot stand alone in the first position; fr-CA is valid, while a region-first value is not. The tool canonicalizes casing, so en-us becomes en-US and zh-hant becomes zh-Hant. A generic language such as fr can be useful when several country-specific French versions exist.

Enter one row per destination in the format locale | fully qualified URL. URLs must begin with http:// or https:// and include the host. Relative and scheme-relative references are rejected, as are URLs containing credentials or fragments. Browser URL parsing normalizes the address, while the generated HTML escapes ampersands and other attribute-sensitive characters.

Include only one x-default row, and add it only when a genuine fallback exists. It is not a language and is commonly used for a country selector or generic landing page. Duplicate locale values are rejected case-insensitively after normalization, which prevents two differently cased entries from silently producing competing tags.

Generate, install, and test the shared set

  1. Inventory the complete language cluster. List every equivalent localized page and the URL currently being edited. Do not generate only the links that are missing from the current page.
  2. Prepare the rows. Use one locale and one absolute HTTP(S) URL per line, separated by a single vertical bar. Each line must contain exactly one separator, and the set must contain at least two rows, including the current page. The generator supports up to 100 rows.
  3. Generate the full HTML block. The tool returns one escaped rel="alternate" element for each row. It rejects malformed input as a whole set, preventing a partial block from being copied while a locale is silently omitted.
  4. Review the generated values. Check canonical locale casing, the destination URLs, and the presence of the self-reference. Confirm that every language and region is supported by current guidance and appropriate for the actual content audience.
  5. Install the identical block everywhere. Place the same complete set in the head of every localized page. Do not create a page-specific subset or alter the order or content independently in each template.
  6. Test the delivered pages. Crawl the live pages and confirm that each one exposes the full set, includes itself, links reciprocally to every alternate, and points to useful 200 pages. The generator cannot perform this remote verification for you.

Verify the locale values separately

The generator checks locale-tag shape and canonicalizes casing, but it does not validate the complete current ISO language and country registries used by any particular search engine. A structurally tidy value can still be unsupported or inappropriate for the page’s real audience.

Check the intended locale against current Google documentation before deployment. Pay particular attention to the difference between a generic language page and a regional page, and to script subtags when the same language is published in different writing systems. The URL structure, visible content, and targeting decision should all support the same locale choice.

Do not use x-default merely to fill an unused slot. It represents a fallback destination for users whose settings do not match another listed alternate. If no suitable fallback page exists, leave it out rather than pointing it to an unrelated page.

Choose one declaration method

Google treats hreflang declarations in HTML, HTTP headers, and XML sitemaps as equivalent implementation methods. The WHATWG alternate-link guidance provides the relevant format reference for an HTML implementation.

MethodWhere declarations appearKey implementation concern
HTML headLink elements in each pageEvery alternate must publish the same complete block
HTTP response headerHeader returned with the pageThe server configuration must generate a synchronized set
XML sitemapAlternate annotations in sitemap XMLThe sitemap process must include every relationship

The Hreflang Generator specifically produces HTML head elements; it does not create HTTP headers or XML sitemap entries. Do not combine inconsistent sets across these methods, because Google considers the methods equivalent and duplicate implementations can drift apart. Choose the method your publishing system can keep complete and synchronized.

Audit what search engines can fetch

Validate the served result rather than assuming the template or copied block appears correctly on every page. After installation, crawl a sample from every language cluster and compare the sets mechanically. The delivered HTML should show the same locale-to-URL relationships everywhere.

  • Confirm that every alternate page contains the full list, including its own row.
  • Confirm that each alternate URL returns a useful 200 response and represents the intended final destination.
  • Check that every member of the cluster links back to every other member.
  • Check that only one x-default row exists when a fallback has been intentionally included.
  • Compare locale values after normalization so casing differences do not conceal duplicate targets.

This live stage catches problems that syntax generation cannot, including a conditional template omission, a stale URL, a redirecting destination, or one page that was never updated. Because the tool cannot access remote pages, keep this crawl or source inspection as a separate release check.

Keep correctness through future changes

Hreflang is an ongoing relationship, not a one-time page setting. When a locale is added, removed, redirected, or moved to a new canonical URL, update every member of the cluster and regenerate the shared set. Record the locale inventory in one place so the same source drives the page implementation.

Finally, separate technical correctness from content quality. Hreflang does not translate content, detect a page’s language, or guarantee a search result. The linked pages should contain substantially equivalent, properly localized primary content. Code validation can confirm the relationship you entered, but it cannot make unrelated or insufficiently translated pages equivalent.

For a deeper look, see How to Plan the Steps Needed to Generate Hreflang.