Help Google serve the correct language to your visitors

Submit rel-alternate-hreflang annotations in a Sitemap

If your site targets users in many languages and, optionally, countries, you can use Sitemaps to provide Google with rel="alternate" hreflang="x". These annotations help Google serve the correct language or regional URL to searchers. More information.

Imagine you have an English language page, targeted at English speakers worldwide. You also have equivalent versions of this page targeted at German speakers worldwide, and German speakers located in Switzerland. Your full set of URLs is:

  • www.example.com/english/
  • www.example.com/deutsch/
  • www.example.com/schweiz-deutsch/

The following Sitemap tells Google that the www.example.com/english/ page has equivalent pages targeting worldwide German-speaking users  (http://www.example.com/deutsch/) and Switzerland (http://www.example.com/schweiz-deutsch/).

<?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>http://www.example.com/english/</loc>
    <xhtml:link 
                 rel="alternate"
                 hreflang="de"
                 href="http://www.example.com/deutsch/"
                 />
    <xhtml:link 
                 rel="alternate"
                 hreflang="de-ch"
                 href="http://www.example.com/schweiz-deutsch/"
                 />
    <xhtml:link 
                 rel="alternate"
                 hreflang="en"
                 href="http://www.example.com/english/"
                 />
  </url>
  
  <url>
    <loc>http://www.example.com/deutsch/</loc>
    <xhtml:link 
                 rel="alternate"
                 hreflang="en"
                 href="http://www.example.com/english/"
                 />
     <xhtml:link 
                 rel="alternate"
                 hreflang="de-ch"
                 href="http://www.example.com/schweiz-deutsch/"
                 />
     <xhtml:link 
                 rel="alternate"
                 hreflang="de"
                 href="http://www.example.com/deutsch/"
                 />
  </url>
  
  <url>
    <loc>http://www.example.com/schweiz-deutsch/</loc>
     <xhtml:link 
                 rel="alternate"
                 hreflang="de"
                 href="http://www.example.com/deutsch/"
                 />
     <xhtml:link 
                 rel="alternate"
                 hreflang="en"
                 href="http://www.example.com/english/"
                 />
<xhtml:link 
                 rel="alternate"
                 hreflang="de-ch"
                 href="http://www.example.com/schweiz-deutsch/"
                 />
  </url>
  
</urlset>

Notes

  • Be sure to specify the xhtml namespace as follows:
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
  • You must create a separate url element for each URL. Each url element must include a loc tag indicating the page URLs, and an xhtml:link rel="alternate" hreflang="XX" subelement for every alternate version of the page, including itself
  • This example uses the language code de for the URL targeted at German speakers anywhere, and the language-locale code de-ch for German speakers in Switzerland. If you have several alternate URLs targeted at users with the same language but in different locales, it's a good idea to provide a URL for geographically unspecified users. For example, you may have specific URLs for English speakers in Ireland (en-ie), Canada (en-ca), and Australia (en-au), but want all other English speakers to see your generic English (en) page. In this case you should specify the generic English-language (en) page for searchers in, say, the UK.