The hreflang attribute specifies the language and geographical targeting of a page. It is an essential element for websites with content in multiple languages or catering to different geographies. Search engines like Google use hreflang attributes to serve the most relevant version of a page to users based on their language and location.

What Is Hreflang?

Hreflang is an HTML attribute that defines the language and targeted region of a webpage. It enables search engines to understand the alternate versions of a page available in different languages and regions. By implementing hreflang correctly, you can ensure that users see the appropriate version of your content based on their location and language preferences.

For example, if you search for “semrush blog” in the US, you will see the US version of the blog. However, if you perform the same search in Spain, you will see the Spanish version of the blog. This localization is possible because of the proper use of hreflang attributes.

What Does an Hreflang Tag Look Like?

An hreflang tag follows a consistent and straightforward structure. It typically looks like this:

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

Here’s what each part of the syntax means:

  • link rel="alternate": Indicates that the link in this tag is an alternate version of the page.
  • href="url_of_page": Specifies the URL where the alternate page can be found.
  • hreflang="lang_code": Specifies the language code of the alternate version.

It’s important to note that the hreflang tag is a signal, not a directive. While Google and Yandex rely on hreflang attributes, search engines like Baidu and Bing use the content-language HTML attribute instead.

How to Build an Hreflang Tag

To create an hreflang tag, you first need to determine the language and country codes relevant to your content. Then, fill in the blanks with the appropriate URLs and language codes. Hreflang supports two-letter ISO 639-1 language codes and ISO 3166-1 alpha-2 country and region codes.

Suppose you have an English blog that has been translated into Spanish and Portuguese. The hreflang attributes for an article should look like this:

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

Each webpage’s hreflang attribute should reference all the pages that serve as alternates, including a self-reference. Google recommends self-referencing hreflang in its guidelines. Failure to reference all relevant alternate pages may result in search engines ignoring or misinterpreting your hreflang tags.

However, if you target an additional country that speaks the same language, you need to include the country code. For example, if you want to target Portuguese speakers in both Portugal and Brazil, you would add the following hreflang tags:

Portuguese in Portugal:

<link rel="alternate" href="https://example.com/pt/" hreflang="pt-pt" />

Portuguese in Brazil:

<link rel="alternate" href="https://example.com/br/" hreflang="pt-br" />

In this case, the hreflang syntax is slightly different, using “language-country” instead of just “language.”

It’s also important to set x-default tags, which indicate the fallback page for users when no other localized version is appropriate. While x-default tags are not mandatory, they are recommended. To implement an x-default tag, add an annotation and set the “href” attribute to the URL where you want users to land if your site doesn’t support their language. Here’s an example:

<link rel="alternate" href="https://example.com" hreflang="en-us" />
<link rel="alternate" href="https://example.com/es/" hreflang="es-es" />
<link rel="alternate" href="https://example.com/pt/" hreflang="pt-pt" />
<link rel="alternate" href="https://example.com/pt/" hreflang="pt-br" />
<link rel="alternate" href="https://example.com" hreflang="x-default" />

Where Does an Hreflang Tag Go?

There are three ways to implement hreflang attributes: in the HTML head of the page, in the HTTP header (for non-HTML files like PDFs), or in the XML sitemap.

1. In the HTML

The simplest way to indicate your alternate pages is by adding the hreflang attributes in the HTML code of the page. Place them within the “ section of each page. Remember to include references to all versions of the article, including self-references.

However, manually adding hreflang tags to HTML can become messy and time-consuming, particularly when managing a large number of alternate pages. In such cases, it’s advisable to use an hreflang tool or generator to create or modify hreflang tags.

2. In the HTTP Header

Hreflang attributes can also be implemented through the HTTP header, primarily for non-HTML content like PDFs. HTTP headers contain information exchanged between servers and clients. The format of the header code for hreflang looks like this:

Link: ; rel="alternate"; hreflang="language_code_1", ; rel="alternate"; hreflang="language_code_2", ...

Each represents the URL of an alternate page associated with a specific language or region code. You must include a set of, rel="alternate", and hreflang values for every version of the page, including self-references.

While this method can be used for HTML content as well, it may result in increased server requests and should only be used when necessary.

3. On the XML Sitemap

The third method involves adding hreflang attributes to your XML sitemap. An XML sitemap is a file that provides search engines with information about the pages on your site. By including hreflang annotations in the XML sitemap, you can manage all hreflang attributes in one place, reducing the need for manual updates in multiple files.

To implement hreflang in an XML sitemap, add a element for each URL and entries for every language and region version of the page, including self-references. For example:

  https://example.com

Using an hreflang generator tool can simplify the process of creating or modifying hreflang tags in an XML sitemap.

How to Find and Fix Hreflang Issues

Regularly auditing your website and using SEO tools can help you identify and fix hreflang issues effectively. Tools like Semrush’s Site Audit can serve as an hreflang checker and provide insights into potential issues that need attention.

When conducting a hreflang audit, you can use Semrush’s Site Audit tool by entering your domain and creating a project. After the tool crawls your site, navigate to the “Issues” tab and search for “hreflang.” This will display a list of hreflang-related issues and recommendations for fixing them.

Here are some common hreflang issues and their solutions:

1. Issues With Hreflang Values

This warning indicates that the country or language codes in the hreflang tags are not in the correct format. It is important to fix this issue because search engines may ignore hreflang tags with incorrect codes, leading to incorrect page serving. To resolve this issue, review the hreflang tags in each affected URL and ensure their syntax adheres to the correct language and country codes. Hreflang generator tools can assist in verifying or creating accurate tags.

2. No Self-Referencing Hreflang

Each page’s hreflang attribute should reference all the relevant alternate pages, including a self-reference. If hreflang attributes don’t self-reference, search engines may ignore or misinterpret them. To fix this issue, review each affected URL and add a self-referencing hreflang tag to the set of hreflang attributes.

This warning is triggered when there are issues with the links specified in the hreflang attributes. For instance, the link might point to a broken or redirected page. Incorrect hreflang links can lead to search engines ignoring your hreflang attributes. To address this issue, review each affected URL and ensure that the annotations point to valid and working pages.

4. Conflicting Hreflang and Rel=Canonical URLs

This warning occurs when an hreflang tag references a non-canonical URL. Canonical tags indicate the main version of a page when you have duplicate or similar pages. Conflicts between hreflang and canonical tags can confuse search engines and result in them ignoring one or both of the tags. To resolve this issue, update the hreflang annotations in each affected URL to point to canonical URLs.

Automate Your Hreflang Tag Audits

To streamline the process and catch hreflang issues promptly, it’s beneficial to automate your hreflang audits. Semrush’s Site Audit tool allows you to set up recurring reports. By scheduling regular audits, you will be notified of any hreflang issues before they become significant problems.

To automate hreflang audits, follow these steps:

  1. Set up a recurring report in Semrush’s Site Audit tool.
  2. Click on the gear “settings” symbol in the top right corner of your dashboard.
  3. Scroll down to find the “Schedule” section.
  4. Choose the desired frequency for running the audit and select the “Send an email” option.
  5. Click “Save” to save the settings.

After each crawl, the Site Audit tool will display any new hreflang issues in the “International SEO” section of your dashboard. Make sure to check the dashboard regularly to address any identified issues promptly.

By implementing hreflang attributes correctly and automating hreflang audits, you can ensure that your website serves the most appropriate version of your pages to users in different languages and regions. This improves your international SEO and provides a better user experience.

Remember, BulkGPT is a powerful tool that can assist you in building custom workflows to create content in bulk, saving you time and improving your SEO and productivity.