If you have multiple versions of your website for different countries, you must ensure each site follows international SEO best practices. The most important of these is making it clear to search engines how each page relates to the other and which countries it targets.
The best way to clarify this is through hreflang, which you can apply as HTML tags or as part of your sitemap.
What is hreflang?
Hreflang is a coding convention that indicates a web page’s target country and language. The term is a portmanteau of “href,” which essentially means “link,” and “lang,” short for “language.” An hreflang tells browsers, “This version of a web page is linked to other alternate versions in multiple languages or countries.”
The two most common ways to add hreflang to your website are with HTML tags on the human-facing side of your website, or by placing them directly into your XML sitemap, which guides search engine crawlers.
Why does hreflang matter for ecommerce businesses?
Hreflang is essential for any business with multiple international versions, because they help search engines like Google find alternate language versions of your site. Using them can improve your rankings for localized searches in each country you serve.
Hreflang is particularly important for ecommerce, because currencies, shipping policies, and product availabilities may vary between site versions. Imagine a customer looking for the perfect pair of sneakers, finding your site on Google, diligently reading your product’s reviews and details, then going to purchase and realizing that pair doesn’t ship to their country—all because Google prioritized the wrong version of your site.
What is an hreflang XML sitemap?
An hreflang XML sitemap is a version of an XML sitemap that incorporates hreflang relationships. An XML sitemap is a file that provides search engines with an easily crawlable reference for all live pages on a website.
Sitemaps help ensure crawlers don’t miss any pages on your website. For example, here is the first-page reference in Shopify.com’s sitemap:
<url>
<loc>https://www.shopify.com/</loc>
<lastmod>2023-09-23</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
Hreflang XML sitemaps list each live page on the website, along with the alternative international versions of each page.
For example, here is what the first-page reference would look like if Shopify used an XML sitemap to refer to its Canadian English, Canadian French, and Australian versions:
<url>
<loc>https://www.shopify.com/</loc>
<xhtml:link
rel="alternate"
hreflang="en-ca"
href="https://www.shopify.com/ca"/>
<xhtml:link
rel="alternate"
hreflang="fr-ca"
href="https://www.shopify.com/ca-fr"/>
<xhtml:link
rel="alternate"
hreflang="en-au"
href="https://www.shopify.com/au"/>
<lastmod>2023-09-23</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
It refers to each version of the page with a detailed <xhtml:link> tag that includes the URL and an hreflang indicating its language (the first two letters) and country (the second two letters). For example, “en-au” indicates the language English and the country Australia. Note that in hreflang, the language must always come before the country.
Benefits of using hreflang XML sitemaps
There are numerous benefits to properly implemented hreflangs:
Enhanced user experience
Hreflang helps search engines show the correct version of your page, preventing situations in which a user is confused by the wrong currency, language, or shipping policy.
Improved search engine rankings
By showing search engines that you have a version of your site tailored to a local market, you can demonstrate higher local relevance than competing sites that only have a single, global version. This increased relevance can lead to improved rankings.
Reduced risk of penalties
If search engines see two very similar pages without additional context from tags like hreflang, they have to decide which version is the “real” or original page and which one is a duplicate. The search engine will deprioritize the perceived duplicate, which can lead to low rankings for international versions of your site.
How to create an hreflang sitemap
- Check if you already have an auto-generated sitemap
- Start with a sitemap template
- Add all pages on your site
- Add all international versions of each page
- Export and upload the sitemap to your website
- Submit the sitemap to Google Search Console
A sitemap is a specially formatted text file, a .xml file, typically hosted at yourdomain.com/sitemap.xml, sometimes with sub-sitemaps within them. You can create an hreflang sitemap in less than a day. Here’s how:
1. Check if you already have an auto-generated sitemap
Sitemaps are typically auto-generated and auto-updated regularly to account for page changes. Shopify automatically creates one and updates it weekly for all stores at yourdomain.com/sitemap.xml, although it does not include hreflang.
If you have an auto-generated sitemap, you should check within your CMS, app, or plug-in’s settings for an automated way to insert hreflang tags. If it has this, this is the best option. Note that Shopify does not allow for sitemap editing at this time.
If you can’t edit your auto-generated sitemap or don’t have one, you can create a manual hreflang sitemap to go alongside your automated one.
2. Start with a sitemap template
A template can help ensure your sitemap follows formatting best practices. Digital Darts provides an accessible hreflang sitemap template to work off of.
3. Add all pages on your site
Make sure to include any page you’d like Google and other search engines to crawl. If you don’t need them to crawl a page, you can leave it off. Only include canonical versions of your URLs.
4. Add all international versions of each page
This is where your local SEO efforts come into play. If you’ve altered pages from your original website to account for regional language and cultural differences, you can add those pages at this step. If a page doesn’t have an international version, it’s OK to leave it blank.
5. Export and upload the sitemap to your website
Copy the final version of your sitemap into a text editor that can save XML files, such as Microsoft Visual Code, and save it so that you can upload it to your site. In Shopify, this can be done under the Files section of Admin.
Sitemaps are typically uploaded to the root domain and named sitemap so you can find them at website.com/sitemap.xml. However, this is just a standard convention—it is not a requirement.
6. Submit the sitemap to Google Search Console
Submitting your sitemap to Google Search Console alerts Google to the new file and speeds up the time it takes for Google to crawl it. It will also tell you if there are any errors in the file. Note that it’s OK to submit a second sitemap alongside your site’s original one.
Best practices for creating an hreflang sitemap
There are several ways to maximize your benefit from your hreflang sitemap:
Keep it updated
Ensure you regularly update your sitemap when adding new pages to your site. A complete sitemap should include all the URLs (or all the pages) on your site.
Check it for errors
Google Search Console will flag any unreadable pages in its sitemap report. These are usually the result of typos or outdated pages and should be updated right away.
Have a clear x-default
Every hreflang set must include a default version for non-regional searches, as defined with the “x-default” tag. The default page is typically the .com version of your site. Make sure to include this.
Hreflang sitemap FAQ
What's the difference between hreflang tags in HTML and XML sitemaps?
HTML and XML sitemaps are two places where a website can house its hreflang tags. It makes no difference to search engines which one you use. The only difference is how easy it is for the website owner to maintain, which depends on CMS functionality.
Can I use hreflang for similar languages in different countries?
Yes, hreflang tags have both language and region in their syntax. For example, an hreflang can distinguish between the English versions of a site in the United States, Canada, and Australia.
How often should I update hreflang annotations?
You should update hreflang annotations every time you add or remove a page on one of your sites.
What are common hreflang mistakes to avoid?
The most common hreflangs mistakes are only applying hreflangs to the homepage and forgetting to include a default (“x-default”) option.
What should I do when hreflang implementation goes wrong?
Most hreflang issues can be quickly addressed. Update hreflang in your sitemap (or HTML), immediately submit it to Google Search Console, and then check back in 24 to 48 hours to confirm it has been read properly.