To generate hreflang, list every equivalent localized URL with its locale, create one complete set of alternate-link elements, and install that identical set in every localized page’s head.

Each hreflang entry is a relationship, not a translation command: it tells search engines that separate URLs carry substantially equivalent content for particular languages or regions. A generator can produce the markup, but it cannot create translated pages, identify their language, or guarantee a search result. For the markup step, the Hreflang Generator accepts locale-and-URL rows and returns escaped HTML link elements.

how do i generate hreflang
How Do I Generate Hreflang for a Complete Page Set?

What the generated hreflang set represents

For one language cluster, every version needs the same set: a link to itself plus one link to every other equivalent version. Those cross-links make the declarations reciprocal. If the English, French and German pages are alternates, each of those three heads contains links to all three versions; no page receives a page-specific subset.

A one-way declaration is not the same relationship. Google’s localized versions guidance explains why self and return links matter: another site should not be able to claim one of your pages as an alternate without that page participating in the set. The generator can build the declaration, but it cannot fetch live pages or prove that the deployed links return to one another.

For more background on the relationship between language, region and return links, use the hreflang implementation guide before finalizing the cluster inventory.

Prepare the locale-and-URL inventory

Prepare one row per localized page in the exact form locale | fully qualified URL. Include the page you are editing; listing only the other languages is not enough. The URL must include http:// or https:// and the host. Do not submit a relative path such as /fr/page or a scheme-relative reference such as //example.com/fr/page.

  • Put exactly one literal vertical bar on each line. A row with missing or extra separators fails the entire set.
  • Use an absolute HTTP(S) URL. Relative URLs, scheme-relative URLs, URLs with credentials and URLs with fragments are rejected.
  • Submit at least two rows, including the current page, and keep the set at 100 rows or fewer.
  • Avoid repeated locale values. Duplicates are detected after normalization and casing is applied.
  • Add x-default only when a genuine fallback page exists, and include no more than one x-default row.

The browser URL parser normalizes each submitted address, while ampersands and other attribute-sensitive characters are escaped in the generated HTML. The result is ready for the head, but you should still inspect the final URLs. If a row is malformed or a normalized locale duplicates another, the tool rejects the entire set instead of producing a partial block that could quietly leave out one country or language version.

Choose the locale and fallback values

The locale declares the language first and may narrow it with a script or region. The generator canonicalizes casing, so en-us becomes en-US and zh-hant becomes zh-Hant.

Locale example Structure Targeting role
en Language only Generic English where a regional distinction is unnecessary
en-US Language and region English for a United States audience
fr-CA Language and region French for a Canadian audience
zh-Hans Language and script Simplified Chinese
zh-Hant-TW Language, script and region Traditional Chinese for a Taiwan audience
x-default Special fallback token Users whose language or region does not match another listed alternate

A country code cannot stand alone in the first position: the first subtag identifies the language. Generic language pages such as fr can be useful when several country-specific French versions exist, while script subtags distinguish writing systems such as zh-Hans and zh-Hant. The x-default value is not a language; it marks a fallback for users whose language or region does not match a listed alternate, often a selector or generic landing page.

The tool checks tag shape, not the complete current ISO language and country registries supported by a search engine. A structurally tidy code can still be unsupported or inappropriate. Verify every intended language and region against current Google guidance and the actual content audience before deployment.

Generate and install one complete hreflang set

  1. Inventory the cluster. List every localized page that contains substantially equivalent content, including the current page. Decide separately whether a real x-default fallback exists.
  2. Format the rows. Enter one locale and one fully qualified URL per line, separated by a vertical bar. Check that each line has exactly one separator and that no locale appears twice after canonicalization.
  3. Generate the block. Paste the rows into the Hreflang Generator. It creates one rel=alternate element per row, escapes attribute-sensitive characters and returns the complete set for the page head.
  4. Review the output. Confirm that every URL points to the intended page, every locale matches the audience, and the block includes self and return links. Recheck language and region support against current search-engine guidance.
  5. Install the same block everywhere. Put the identical set in the head of every alternate page in the cluster. Do not leave the current page in the set but remove it from another version.
  6. Test the deployed cluster. Crawl a sample from every language cluster, compare the link sets mechanically, and confirm that each alternate resolves to a useful 200 page with its own self-reference and links back to the other versions.

Keep one implementation method synchronized

Google treats HTML link elements, HTTP response headers and XML sitemap entries as equivalent ways to declare localized relationships. The generator specifically creates HTML head elements, so its output should be used in the head workflow rather than treated as a header or sitemap file.

Implementation method Output from this tool Maintenance requirement
HTML head elements Escaped rel=alternate links Install the identical complete set in every alternate page head
HTTP response headers Not generated Maintain one complete, synchronized set in the response configuration
XML sitemap entries Not generated Keep the sitemap implementation synchronized with the same cluster

Do not maintain inconsistent copies across these methods. Multiple implementation routes can drift when a locale is added, changed or removed. Choose the method your publishing system can keep complete and synchronized, especially when the same cluster changes.

Check the live language cluster

The generated markup is only one part of a valid implementation. After deployment, crawl a sample from every language cluster and compare the hreflang sets mechanically. Each listed URL should deliver a useful 200 page, and each page in the set should include the same complete collection of alternate links, including itself.

Keep the inventory under control when a locale is added, removed, redirected or moved to a new canonical URL. Update every page in the affected cluster at the same time so the set does not retain a removed version or point to an obsolete location. The generator cannot access remote pages, test responses or prove reciprocity, so this live crawl remains a separate deployment check.

Understand what hreflang does not do

Hreflang does not translate content, detect the language already on a page or guarantee that a particular localized page will appear in a result. Search engines may identify page language algorithmically and choose among results using many signals. The tags only describe relationships among substantially equivalent localized pages, so they cannot replace translated primary content or a coherent international site structure.

Use the generated set to make an existing relationship explicit and consistent. The safest workflow is to inventory the cluster, generate one complete HTML block, verify the locale choices, install that block everywhere, and crawl the published pages before treating the implementation as finished.

Related reading: How Do I Get Started When I Need to Generate Hreflang?.