hreflang
hreflang is an attribute on a link annotation that tells a search engine which language, and optionally which region, a page is written for, and where the equivalent pages in other languages live. It exists so a searcher in one language is shown that language’s version rather than a translation of it.
Three places to declare it
Google accepts the annotation in any of three forms, and treats them as equivalent: a <link rel="alternate" hreflang="..."> element in the page head, a Link HTTP response header, or an xhtml:link entry against each URL in the XML sitemap. The value is an ISO 639-1 language code, alone or followed by an ISO 3166-1 alpha-2 region code, so en, en-GB and de-CH are all valid. A script code from ISO 15924 can be added where the same language is written two ways. The reserved value x-default names the page to show when no version matches the searcher’s language.
The rule that breaks it
Every page in a set has to point at every other page in the set, and each of them back. If page X names Y as an alternate and Y does not name X, Google may ignore the annotations for both. This is the usual failure: a new language version is added with links to the old ones, and the old ones are never updated. Two other points from the same documentation matter. Google works out a page’s actual language by reading it, not from hreflang or the HTML lang attribute, so the annotation tells it which version to serve to whom, never what the page is. And when several URLs are duplicates, Google favors a URL that sits inside an hreflang cluster when choosing the canonical, which is one reason to keep the set complete.
One question that comes up
Does hreflang affect AI assistants?
This site has not measured whether any assistant reads hreflang, and no assistant’s crawler documentation says it does. What is documented is search behavior: Google uses the annotation to serve the right version to the right searcher, and an assistant that retrieves through a search index inherits whichever version that index chose. The text on the page it receives is what it works from.
Related terms
Sources
Google Search Central, tell Google about localized versions of your page and how to specify a canonical.