Canonical & Hreflang Generator
List your language versions and get ready-to-paste canonical and hreflang tags, an HTTP header or sitemap entries. It runs in your browser; nothing is uploaded.
How to use these tags
- List every language version, one per line: the language code, then the full address. Add an
x-defaultline for your fallback page. - Enter this page's own address if you want its canonical tag. Change it to match each page as you copy the output.
- Copy the result into the head of every version (or into one sitemap), then check a few pages in the browser's view-source.
Choosing a method
| Method | Best for |
|---|---|
| HTML link tags | Most sites. Tags go in the head of every language version. |
| HTTP Link header | PDFs and other files that have no HTML head. |
| XML sitemap | Large sites, or sites where editing page templates is hard. |
Apache example for a PDF
To send the header from Apache, add a block like this to your .htaccess. It needs the mod_headers module, which most hosts have on. Use the header output from the tool as the value:
<FilesMatch "^brochure-en\.pdf$"> Header set Link "<https://example.com/files/brochure-en.pdf>; rel=\"alternate\"; hreflang=\"en\", <https://example.com/files/brochure-fr.pdf>; rel=\"alternate\"; hreflang=\"fr\"" </FilesMatch>
Everything here runs in your browser, and your addresses are never uploaded. For the rest of a page's tags, see the Meta Tag Generator.
Frequently asked
What is the difference between canonical and hreflang?
A canonical tag tells search engines which address is the preferred version of a page when the same or very similar content appears at more than one address. Hreflang tells them which language or regional versions of a page exist, so they can show each visitor the right one. They work together: each language version should have a canonical pointing at itself, not at another language.
Do I put the same tags on every language version?
The hreflang lines are the same on every version, and each version must list itself as well as the others. Only the canonical tag changes, because it points at that page's own address. Hreflang also needs return links: if the English page lists the French page, the French page must list the English one, or the pair may be ignored.
What is x-default?
It is the fallback address for visitors whose language or region you have not listed. It is usually a language picker or your main version. It is optional, but recommended when you serve several languages. Use one x-default line per set.
Which language and region codes can I use?
Use a two-letter ISO 639-1 language code such as en, de or fr, optionally followed by a two-letter ISO 3166-1 region code, as in en-GB or pt-BR. A region on its own is not valid, and the United Kingdom is GB, not UK. A script can be added where needed, as in zh-Hans. The tool checks the codes and tells you when it changes one, for example en_us to en-US.
Which method should I use: tags, header or sitemap?
Pick one method per set of pages; you do not need all three. HTML tags are the usual choice. The HTTP header is for files that have no head, such as PDFs. A sitemap suits large sites, because you maintain one file instead of editing every page.
Does this tool check my live pages?
No. It builds the tags from the list you give it and checks the codes and addresses for mistakes, but it does not fetch your pages or confirm that they link back to each other. Use the Search Console international targeting reports or a crawler to check the live result.