Publish the same page in English and French and a search engine faces a problem it cannot solve by reading alone: which version should a French speaker see, and which one belongs to everyone else? Guess wrong and the French page surfaces for English queries while the English page sits unused. Hreflang annotations exist to remove that guess. They are a small set of tags that name every language and region version of a page, and the audience each version is for.

This guide builds one set with the free Hreflang Tag Generator on Ovatly and places it both ways the generator supports: as link tags in the <head> of each version, and as a block inside an XML sitemap. One limit deserves saying at the start. Hreflang can also be delivered through HTTP response headers, and this guide's title names that route because people ask about it, but this generator does not produce a header version. What follows covers the two outputs it does produce, in full.

Contents

  • Quick answer
  • The two outputs the generator gives you
  • The rules every placement shares
  • How to build and place the tags, step by step
  • Worked example: an English page and its French version
  • Tags or sitemap: choosing a placement
  • Limitations
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Open the Hreflang Tag Generator, add one row for every language or region version of the page (including the original), give each row its code and full URL, and optionally set an x-default URL. Then either copy the generated link tags into the <head> of every version, or paste the generated sitemap block into your sitemap file instead. Both outputs describe the same set, and search engines treat them as equivalent. There is no header output: if your site serves hreflang in HTTP response headers, that version has to be written separately on the server.

The two outputs the generator gives you

The HTML output is a set of <link> tags, one per version. Each tag carries a rel="alternate" attribute, an hreflang code, and the version's URL in its href. The whole set goes into the <head> section of a page, and because the annotation is reciprocal, the identical set goes into the head of every version, not just the original.

The sitemap output expresses the same information inside your XML sitemap. Instead of link tags, each <url> entry lists all of its versions as xhtml:link alternates, so a crawler reading the sitemap learns the full set without opening each page's head.

The header route is the one gap. Some sites send hreflang as Link headers in the HTTP response. This generator does not write those lines, and nothing in its output is formatted for a server configuration. If that is the placement your site uses, the header lines have to be produced some other way; the generator's contribution stops at the checked list of codes and URLs, the tag set, and the sitemap block.

The rules every placement shares

Whichever placement you choose, the set itself obeys the same rules.

First, reciprocity. Every version must list every other version, including itself. If the French page names the English page but the English page never names the French one back, search engines may ignore the set entirely. The generator builds the full set from your rows, which is why the first step asks for every version, not just the new one.

Second, real codes. The generator validates language codes against the ISO 639-1 list, so a code like en or fr passes and an invented one does not. Region codes are format-checked: two letters, as in en-GB, or three digits, as in es-419 for Latin America.

Third, full URLs. Each row takes the complete address of a version, protocol included, because the output is copied verbatim into pages and sitemaps, where a partial address would point nowhere.

Fourth, real pages. Each version must be a reachable page in its own right, with a canonical tag pointing at itself. Hreflang tells engines which version fits which audience; it does not merge pages together or rescue a version that does not properly exist.

How to build and place the tags, step by step

  1. Open the Hreflang Tag Generator and add a row for every language or region version of the page, including the original.
  2. In each row, enter the version's code and its full URL: codes like en, en-GB or es-419, and the complete address of that version.
  3. Optionally set an x-default URL, the fallback for visitors whose language matches none of your versions.
  4. Take the output in whichever form you are placing. For tags, copy the link tags into the <head> of every version of the page. For the sitemap route, use the sitemap version in your sitemap file instead.

Worked example: an English page and its French version

Say one page exists in English at https://example.com/page and in French at https://example.com/fr/page, and the English page should also be the fallback for everyone else. The rows are en = "https://example.com/page", fr = "https://example.com/fr/page" and x-default = "https://example.com/page".

The HTML output includes these tags, and the identical set goes into the <head> of both pages:

<link rel="alternate" hreflang="en" href="https://example.com/page">
<link rel="alternate" hreflang="fr" href="https://example.com/fr/page">
<link rel="alternate" hreflang="x-default" href="https://example.com/page">

The sitemap output carries the same set in a different shape. Each <url> entry lists all of the versions as xhtml:link alternates, so the entry for the English URL looks like this, and the French URL gets its own entry listing the same three alternates:

<url>
  <loc>https://example.com/page</loc>
  <xhtml:link rel="alternate" hreflang="en" href="https://example.com/page"/>
  <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/page"/>
  <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/page"/>
</url>

Notice what the example does not contain: a third output for HTTP headers. If this site delivered its annotations in response headers, those lines would have to be written from these same rows by whoever manages the server.

Tags or sitemap: choosing a placement

The generator's own guidance is that the two placements are equivalent to search engines, so the choice is practical rather than strategic. Tags are easier when a page has a handful of versions and you control the templates. The sitemap version scales better on a large site, because the whole set lives in one file instead of being edited into every template. What matters is not which one you pick, but that the set stays identical and complete wherever it appears.

Limitations

  • The generator produces link tags and a sitemap block only. It does not produce HTTP header lines, and it does not insert anything into your pages or your sitemap for you; placing the output is your job.
  • Hreflang targets language and region. It is not a tool for showing different content to people who share the same language and region, and it does not sort out currency or content differences within one audience.
  • A complete, correct set is a signal, not a command. Search engines may still ignore a set that breaks the reciprocity rule, and each version still has to earn its place as a real, reachable page.

Common mistakes

  • Placing the set on one version only. Reciprocity is the whole mechanism. A set that appears on the English page but not the French one can be ignored.
  • Leaving the page itself out of its own set. Every version lists itself as well as the others.
  • Shortened or relative URLs. Rows take full URLs, and the output is copied verbatim, so a partial address ships as a broken one.
  • Invented codes. Language codes are checked against the ISO 639-1 list and region codes against their format. A plausible-looking code that fails those checks undermines the set.
  • Region codes for identical content. Add a region such as en-GB only when the content genuinely differs by country; otherwise a plain en covers all English speakers with one page to maintain.

FAQs

What is x-default for? It names the fallback page for users whose language or region matches none of your versions, often a language selector page or your main English page.

Tags or sitemap: which implementation is better? Both are equivalent to search engines. Tags are easier for a few pages; the sitemap version scales better and avoids editing every template, which is why the generator produces both.

Does the generator produce hreflang for HTTP headers? No. It outputs link tags for the page head and a sitemap block. If your site delivers hreflang through HTTP response headers, those header lines have to be written on the server; the generator does not create them.

What happens if one version does not list the others? Hreflang is reciprocal, so an incomplete set risks being ignored. Every version must list every other version, including itself.

Should I use en or en-GB style codes? Use a plain language code (en) when the page targets all speakers of that language. Add a region (en-GB, en-US) only when the content genuinely differs by country.

Conclusion

Build the rows once, check them once, and the generator hands you the same set in the two shapes most sites need: tags for the <head> and a block for the sitemap. Keep every version's copy identical and complete, and the annotation does its quiet work. If your versions are not different languages but different English-speaking countries, the companion guide on setting hreflang for English in the US, UK and Australia covers those codes in detail. More guides like this one live in the SEO Tools archive.