LLMSdocs
English

Language alternates in sitemaps

A sitemap can tell search engines that pages are translations or regional versions of each other, using xhtml:link elements with hreflang values inside each url entry. Every version lists every version, itself included.

Type: Intermediate
On this page
  1. The complete example
  2. Rules for the sitemap form
  3. Language and region codes
  4. x-default
  5. Sitemap, HTML or HTTP header
  6. Checking the annotations
  7. See also
  8. References

Suppose a documentation page exists in English at https://example.com/docs/sitemaps and in Korean at https://example.com/ko/docs/sitemaps. Without help, a search engine sees two pages with different text and no stated connection. An hreflang annotation says that they are the same page in two languages, so that a searcher whose browser is set to Korean can be shown the Korean URL and an English reader the English one.

Google documents three equivalent places to put these annotations: link elements in the HTML head, Link headers in the HTTP response, and the sitemap. It treats them as the same signal and recommends choosing one. The sitemap form is the easiest to generate for a large site, because all the relationships are written in one file by one program rather than in the head of every page.

The complete example

XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://example.com/docs/sitemaps</loc>
    <lastmod>2026-12-03</lastmod>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/docs/sitemaps"/>
    <xhtml:link rel="alternate" hreflang="ko" href="https://example.com/ko/docs/sitemaps"/>
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/docs/sitemaps"/>
  </url>
  <url>
    <loc>https://example.com/ko/docs/sitemaps</loc>
    <lastmod>2026-12-04</lastmod>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/docs/sitemaps"/>
    <xhtml:link rel="alternate" hreflang="ko" href="https://example.com/ko/docs/sitemaps"/>
    <xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/docs/sitemaps"/>
  </url>
</urlset>
https://example.com/sitemap.xml with one page in two languages

Each language version has its own url entry, and each entry repeats the same block of xhtml:link elements. With two languages and an x-default there are three links per entry; with ten languages there would be eleven. The lastmod values differ because each version is revised on its own schedule.

Rules for the sitemap form

  1. Declare the XHTML namespace on the root element: xmlns:xhtml="http://www.w3.org/1999/xhtml". The prefix xhtml is a convention; the namespace URI is what matters.
  2. Give every language version its own url element with its own loc, as for any page.
  3. Inside each url element, add one xhtml:link with rel="alternate" for every version of the page, including the one named in loc.
  4. Use fully qualified URLs, with the scheme, in every href. Relative and protocol-relative URLs are not accepted.
  5. Make the annotations reciprocal. If the English page names the Korean page, the Korean page must name the English page; Google ignores annotations that are not returned.
  6. Keep the order of the xhtml:link elements consistent. Order has no meaning, but identical blocks are easier to check.

The xhtml:link elements are not part of the Sitemaps 0.9 schema. They rely on the protocol's provision for extensions in other namespaces, and they are documented by Google. Google's documentation also notes that they do not count toward the 50,000 URL limit of a sitemap; they do count toward its 50 MB size, which is the limit a site with many languages usually meets first. The sitemap's location rules still apply, so a sitemap can only list URLs in its own directory and below.

Language and region codes

An hreflang value starts with a language code in ISO 639-1 form. A region code in ISO 3166-1 alpha-2 form may follow after a hyphen, to target speakers of a language in one country. A script can be named with an ISO 15924 code where it matters, as in zh-Hant. A region on its own is not a valid value.

ValueValidMeaning or problem
koYesKorean, any region
en-GBYesEnglish, for users in the United Kingdom
zh-HantYesChinese in traditional script
x-defaultYesThe fallback version for languages and regions that match no other value
krValid, but not KoreanA valid code, but for the Kanuri language; Korean is ko
en-UKNoUK is not the ISO 3166-1 code for the United Kingdom (GB); Google ignores the region part
GBNoA region without a language

x-default

The reserved value x-default names the URL to show when no other value matches the searcher's language or region. On a documentation site it usually points to the English page, as in the example. On a site whose home page asks visitors to pick a language, it can point to that selector page instead. x-default is optional, and like every other value it must appear in the block of every version.

Sitemap, HTML or HTTP header

MethodWhere the annotations goSuits
Sitemapxhtml:link elements in each url entryLarge sites, and sites where templates are hard to change
HTMLlink rel="alternate" hreflang elements in the head of every versionSites where each page is generated with knowledge of its translations
HTTP headerLink headers with rel="alternate" and hreflang on every responseFiles with no head, such as PDFs

For comparison, the head of the English page would carry the same three links as HTML elements:

HTML
<link rel="alternate" hreflang="en" href="https://example.com/docs/sitemaps">
<link rel="alternate" hreflang="ko" href="https://example.com/ko/docs/sitemaps">
<link rel="alternate" hreflang="x-default" href="https://example.com/docs/sitemaps">

Using more than one method adds nothing in Google Search and doubles the places where the annotations can disagree. If a site already has hreflang links in its pages, there is no need to add them to the sitemap as well. How alternates combine with a canonical link on each page is covered in canonical and alternate links.

Checking the annotations

  • Every url entry for a page group should carry an identical set of xhtml:link elements. A script that groups entries by that set and flags any group with a missing member catches most errors.
  • Every href should return 200 and should not redirect.
  • Each version's own canonical link should point to itself, not to another language version. Google recommends naming a canonical page in the same language.
  • Codes should be checked against the ISO lists, not against country names: GB for the United Kingdom, KR for South Korea, and ko, not kr, for Korean.

See also

  • Sitemap XML formatEvery element of the Sitemaps 0.9 XML format, with the size limits, encoding and escaping rules, which fields Google uses, and the RSS, Atom and text alternatives.
  • Sitemap index filesA sitemap index is an XML file that lists other sitemaps instead of pages. It is required once a site passes 50,000 URLs or 50 MB in one sitemap, and it is useful well before that for splitting a site by section.
  • How crawlers find a sitemapA sitemap only helps once a crawler knows where it is. The Sitemap line in robots.txt, submission in Google Search Console and Bing Webmaster Tools, the retired ping endpoint, and IndexNow for announcing changed URLs.
  • Canonical and alternate linksA canonical link names the preferred URL when the same content is reachable at several addresses; alternate links point to translations and to the same page in other formats, such as JSON or Markdown. Both can be written in the HTML head or sent as HTTP Link headers.

References

  1. Google Search Central. Tell Google about localized versions of your page. developers.google.com (accessed 5 December 2026)
  2. sitemaps.org. Sitemaps XML format: Extending the Sitemaps protocol. sitemaps.org
  3. Library of Congress (ISO 639-2 Registration Authority). Codes for the Representation of Names of Languages, including ISO 639-1 codes. loc.gov (accessed 5 December 2026)
  4. ISO. ISO 3166 country codes. iso.org
  5. Nottingham, M. RFC 8288: Web Linking, section 3.4.1 (the hreflang parameter). IETF, October 2017. rfc-editor.org