How to generate hreflang tags
- Add one row per language or country version of the page: the hreflang code (such as
en,en-GB,deorpt-BR) and the full URL of that version. - Keep x-default on and point it at your language selector or the version for everyone else.
- Choose the output:
<link>tags for the page head, entries for an XML sitemap, or an HTTPLinkheader for PDFs and other non-HTML files. - Fix any warnings, then add the same complete set to every language version.
How hreflang works
hreflang tells Google and Yandex which language or regional version of a page to show to each user, so a searcher in Germany sees your German page and one in Mexico sees the Latin American Spanish page. It also stops near-identical versions (for example US and UK English) from competing with each other as duplicates.
The rules are strict, and mistakes are common:
- Codes are an ISO 639-1 language, optionally followed by an ISO 3166-1 region:
en-GB, noten-UK. A region alone, such asGB, is invalid. - Every version must link to every other version and to itself (return links). If page A lists B but B does not list A, Google ignores the pair.
- Use absolute URLs of canonical, indexable pages.
- Use one method per page: HTML tags, sitemap or HTTP headers.
The validator catches invalid codes and suggests fixes, such as en_us to en-US. Everything runs in your browser.
What is x-default?
The fallback for users whose language or region you do not target, often a language selection page or your international English version.
Do I need hreflang for a single-language site?
No. hreflang is only needed when the same content exists in several languages or regional variants.
Does Bing support hreflang?
Bing mainly uses the content-language meta tag and HTML lang attribute instead. Set lang on each page's <html> element as well.