How to use the hreflang tag generator
- Enter one version per line: a language code, a space and the full URL of that version. Use codes like en, en-US, pt-BR, zh-Hant or x-default.
- Choose the format: HTML link tags, XML sitemap links or an HTTP Link header.
- Read the tags the page builds. Problems are listed by line number, and notes remind you about missing pieces.
- Copy the tags into the head of every version of the page, into your sitemap, or into your server settings, and download them if you like.
What the tags say
A hreflang tag tells software that reads a page that it has other versions for other languages or regions, and where they are. Each tag names a language, and optionally a script and a region, with the address of that version. The special code x-default names the version to use when no listed language fits. For a site with English for the United States and the United Kingdom, French and a general page, you list four rows, one tag per version.
Codes are tidied to the usual capitalization: language in lowercase, script with a capital first letter and region in capitals. So EN-us becomes en-US and zh_hant becomes zh-Hant. Names such as english are refused, since the tag needs a code. Each language and region may appear only once, and the page names a repeated code with the line where it was first listed.
The rules that make the set work
Every version must list the whole set, including itself, so the same block of tags goes on every page in the group. If page A points to page B but page B does not point back, the link is usually ignored. Addresses must be full URLs starting with https:// or http://, with no spaces, so the page rejects relative paths and other schemes. The page does not visit the addresses or check that they exist, so confirm each one loads.
For the same list the page can write three formats. The HTML form goes in the head of each page, for example a link tag with rel alternate, an hreflang value and an href. The sitemap form uses the xhtml link element inside each URL entry of a sitemap, and the header form is a single Link line for files such as PDFs where there is no head. Ampersands and quotes are escaped for you.
Related tools and privacy
The Meta Tag Generator builds the other head tags for each version, the Robots.txt Generator controls crawling, the Htaccess Redirect Generator redirects old addresses and the JSON-LD Schema Generator describes a page. Everything runs in your browser and nothing is uploaded or visited.
Assumptions and limits
- Codes follow a simple pattern of language, optional script and optional region, or x-default. Not every valid tag form is accepted.
- Addresses start with https:// or http://. They are not fetched or checked for existence.
- Up to 200 rows are read. Each code can appear once.
- Nothing is uploaded or stored.
Frequently asked questions
How do I write an hreflang tag?
Use a link element with rel="alternate", an hreflang value with the language and region, and the href of that version. The page builds one for each row you enter and puts the same set on every version.
What is x-default?
It is a special value naming the version to show when no listed language fits the visitor. It is optional, and often points to a language selector or a main page.
Do I have to include the page itself?
Yes. Each version should list every version of the set, including itself, and the same set goes on all of them. A version that only lists the others is incomplete.
Does the page check that my URLs work?
No. It never visits an address. It checks only that each one is a full http or https URL with no spaces, so open each address yourself to confirm it loads.