You added a Spanish page to your shop last week. Now a customer in Mexico searches for what you sell, and Google shows her the English page. She leaves. Hreflang tells search engines which page belongs to which language. This tool writes the code for it and checks every line.
How to use the generator
- Type a language code and the full address of that page on each row. The three rows already there are an example: replace them with your own.
- Add a row for every other language. Use Add a version or press Enter in the last address.
- Add an x-default row for visitors whose language you do not cover. Most sites point it at the main page.
- Fix anything the checks flag. Each flag says what is wrong, and a button fixes the common ones in one tap.
- Pick a format: HTML tags, HTTP header or sitemap XML. Press Copy, or download the file.
Put the same block on every version of the page. If you have many pages, open Many pages, or tags you already have and paste one address per line. The tool reads the language from the path (/es/), the subdomain (es.example.com) or a ?lang= part, and groups the addresses that belong together. Paste tags, a Link header or a sitemap you already use and it loads them. For a sitemap it also checks that every page lists itself and links back to the pages that list it.
Where hreflang comes from
A search engine sees your English page and your Spanish page as two different pages. It cannot tell they say the same thing for different readers. Hreflang is a label you put on each page that says "this is the Spanish version, and these are the others." It uses short codes: a language like es, and optionally a country, like es-MX for Mexico.
You can put the labels in three places. The head of each page is the usual one. An HTTP header does the same job for files with no head, like a PDF. A sitemap holds them all in one file, which is easier when you have hundreds of pages.
Where it goes wrong
Small typos break it, and nothing tells you. Write en_US with an underscore, or en-UK for the United Kingdom, and the line may be ignored. The country code for the United Kingdom is GB. Use uk as a language and you have asked for Ukrainian.
The rule people forget is the return link. If your English page points to the Spanish one, the Spanish one must point back. A page that lists the others but is not listed by them can be ignored. The easy way to get this right is the same block on every page, which is what this tool gives you. Each page also lists itself.
Two other slips: two languages sharing one address, and a relative address like /es/ where a full one starting with https:// is needed.
What the generator does and does not do
It checks each code against the lists built into this page: 184 two-letter languages from ISO 639-1 and 249 countries from ISO 3166-1. It fixes the case (en-us becomes en-US), warns about retired codes like iw (now he), and flags a country typed in the language place. It accepts a script, as in zh-Hant, and region numbers like es-419. A three-letter language code for a language with no two-letter code is accepted, but this page cannot check it against the full list.
It does not open your pages. Everything runs in your browser, so it cannot see whether a live page carries the tags or whether the address works. After you publish, test one page in Google Search Console. Hreflang does not raise your rank either. It helps search engines show the right version to the right person.
On social media
Hreflang is for web pages. Instagram, TikTok, LinkedIn, YouTube, Pinterest, X and Facebook do not read it, so a caption in Spanish needs no tag. It matters for the pages those posts send people to: your shop, your blog and the page behind your link in bio. If a Reel in Spanish links to a page that shows English first, the click is wasted.
FAQ
What is an hreflang tag?
An hreflang tag is a line of code that tells search engines which language and country a page is for, and where the other versions are. It looks like this: <link rel="alternate" hreflang="es" href="https://example.com/es/" />.
Can two languages share one address?
No. Each language needs its own page, because the point is to send each reader to a page in their language. The one exception is x-default, which can point at the same page as one of your languages, like your English page.
What is x-default for?
The x-default row names the page to show when none of your languages fits the visitor. It is often your main page or a page where people pick a language. It is optional, but it is a good habit.
Which format should I use?
Use HTML tags if you can edit the head of your pages. Use the sitemap if you have many pages or cannot touch the head. Use the HTTP header for files like PDFs. Pick one way and use it on every page.
How does the tool know which codes are valid?
It checks them against ISO 639-1 language codes and ISO 3166-1 country codes that are built into this page. The language comes first and is required. The script and the country are optional. Nothing is looked up online.
Do I still need canonical tags?
Yes. Each language version should have a canonical tag that points to itself. Hreflang links the versions together, and canonical says which address is the main one for each.