How to use hreflang tags for your SEO strategy in Spanish

Hreflang tags can help you to optimize the SEO of yout multilingual website in order to show your content to the right audience.
People conected around the world
May 23, 2023

Optimizing SEO on your website can make all the difference in reaching your target audience. There are many tools and techniques that can help you to carry out a good strategy, and hreflang tags are one of them. We tell you exactly what they are and how to use them on your website for your SEO strategy in Spanish.

What are hreflang tags

Hreflang is an important international SEO concept that will ensure that web visitors see the right page.

Hreflang is an HTML attribute that communicates the language and target region of a web page. These tags are used to provide information to search engines about the different language or regional versions of a page, allowing them to display the most relevant version for each user based on their language and location. In this way, instead of having the same web page for your users in other parts of the world, they allow you to have alternative pages optimized for the main language of that country.

These tags are added to the <link> element in the <head> section of an HTML page and are used to establish relationships between different versions of a page in different languages or targeting different regions. This is what an hreflang tag looks like:

<link rel=”alternate” href=”url_of_page” hreflang=”lang_code” />

  • link rel=”alternate” means that the tagged link is an alternate version of the page.
  • href=”url_of_page” is the link where you can find the alternate page.
  • hreflang=”lang_code” is the alternative language code.

How to implement a hreflang tag for your SEO strategy in Spanish

To generate your hreflang tag, you first need to know the codes of both the country and the language to which you are going to address your website, in order to fill in the gaps. These codes are composed of two letters. The ISO 639 nomenclature refers to languages and the ISO 3166-1 alpha-2 nomenclature for country codes and different regions that make up the world.

The International Organization for Standardization (ISO) has a search engine where you can find the codes of the regions quickly and easily. Therefore, if your web page is translated into Spanish and French, your hreflang tags would look like this:

<link rel=”alternate” href=”https://yourwebsite.com” hreflang=”en” />
<link rel=”alternate” href=”https://yourwebsite.com/es/” hreflang=”es” />
<link rel=”alternate” href=”https://yourwebsite.com/pt/” hreflang=”pt” />

The hreflang attribute on each web page must include a reference to all pages that serve as alternatives, otherwise search engines may ignore or misinterpret your hreflang tags and they will be of no use to you.

The reference links in the code snippet for the English article above should appear on your French and Spanish pages. If you are targeting an additional country that also speaks Spanish, you would also need to add the country code. For example, if that country were Mexico:

<link rel=”alternate” href=”https://yourwebsite.com/mx/” hreflang=”es-mx” />

Finally, it is also recommended to implement an x-default tag at the end of your hreflang attribute set. As Google explains, “the x-default hreflang attribute tells our algorithms that this page is not targeted to any language or regional settings and that it is the default page used when there is no other more suitable page.”

<link rel=”alternate” href=”https://yourwebsite.com” hreflang=”x-default” />

The hreflang tags can be placed in the XML Sitemap, in the HTML head section of the page or in the HTTP header, the latter for non-HTML files such as PDF files.

On the Internet, there are numerous tools that allow you to generate hreflang tags. For example, Aleyda Solis has a tool where you only have to indicate the url of your article, the language and the country for each version of the article you want to publish, to get your tag. This tool also allows you to upload the information from a .csv file and select if the tags are for the HTML header or the XML Sitemap.

Now that you know what hreflang tags are and how to implement them, you just need to put all this into practice to boost the SEO of your multilingual website to the maximum.

Other articles related to

Published by

Content Creator in Marketing4eCommerce
Creator, writer and proofreader of content for both the Spanish and English Marketing4eCommerce editions.

Stay up to date!

Únete a nuestro canal de Telegram

All you need to know!

Sign up for our newsletter and receive our best articles on eCommerce and digital marketing in your email for free.