What Is the Hreflang Attribute?
Hreflang is an HTML attribute that communicates the language and focused area of a webpage. It permits serps to serve essentially the most acceptable model of that web page based mostly on the searcher’s nation and language preferences.
Hreflang is a vital worldwide search engine optimization idea. It helps be certain that the precise viewers sees the precise webpage.
For instance, as a substitute of getting the identical web page compete for customers in Spain and Mexico, you’ll be able to have alternate pages optimized for that nation’s language, forex, and extra.
Right here’s what it seems to be like in apply.
Say you Google “semrush weblog” within the US. That is the primary end result:

Whereas in the event you’re in Spain, that is what you’ll see:

What Does an Hreflang Tag Look Like?
Hreflang follows a constant and simple construction. Normally, it seems to be like this:
<hyperlink rel="alternate" href="url_of_page" hreflang="lang_code" />
And right here’s what the syntax (laptop language) means:
- hyperlink rel=“alternate” means the hyperlink on this tag is an alternate model of this web page
- href=“url_of_page” is the place yow will discover the alternate web page
- hreflang=“lang_code” is what the alternate language is
Notice: The hreflang tag is a sign, not a directive.Google and Yandex use hreflang attributes. Baidu and Bing don’t. They depend on the content-language HTML attribute.
The way to Construct an Hreflang Tag
To create an hreflang tag, you must first discover the language and nation codes you want. After which fill within the blanks.
Hreflang helps two-letter ISO 639-1 language codes and ISO 3166-1 alpha-2 nation and area codes.
(You gained’t at all times want the nation or area code. However it might turn out to be useful.)
Let’s say your English weblog has been translated into Spanish and Portuguese. The hreflang attribute for an article ought to appear to be this:
<hyperlink rel="alternate" href="https://instance.com" hreflang="en" />
<hyperlink rel="alternate" href="https://instance.com/es/" hreflang="es" />
<hyperlink rel="alternate" href="https://instance.com/pt/" hreflang="pt" />
The hreflang attribute on every webpage ought to embrace a reference to all of the pages that function alternates.
Together with a reference to itself. Google recommends self-referencing hreflang in its tips.
In case your hreflang attributes don’t reference all of the related alternate pages, serps could ignore or misread your hreflang tags.
Which suggests:
The reference hyperlinks within the code snippet for the English article above ought to seem in your Spanish and Portuguese pages.
However what in the event you focused a further nation that additionally speaks Portuguese? Like Brazil.
(You would possibly wish to try this in the event you’re promoting a product in numerous currencies, for instance.)
In that case, you’d additionally want so as to add the nation code.
So, that will appear to be this, with “pt” being the two-letter nation code for Portugal and “br” for Brazil:
Portuguese in Portugal:
<hyperlink rel="alternate" href="https://instance.com/pt/" hreflang="pt-pt" />
Portuguese in Brazil:
<hyperlink rel="alternate" href="https://instance.com/br/" hreflang="pt-br" />
The syntax here’s a bit completely different. It’s hreflang=“language-country” as a substitute of simply hreflang=“language.”
And that’s all you must do.
Professional tip: It’s additionally necessary to setx-default tags. They point out the fallback web page for customers when no different localized model is suitable.
X-default tags aren’t necessary, however they’re really helpful.
To implement an x-default tag, add an annotation and set the “href” attribute to the URL the place you’d need customers to land in case your website doesn’t assist their language.
Like this (proven final):
<hyperlink rel="alternate" href="https://instance.com" hreflang="en-us" />
<hyperlink rel="alternate" href="https://instance.com/es/" hreflang="es-es" />
<hyperlink rel="alternate" href="https://instance.com/pt/" hreflang="pt-pt" />
<hyperlink rel="alternate" href="https://instance.com/pt/" hreflang="pt-br" />
<hyperlink rel="alternate" href="https://instance.com" hreflang="x-default" />
The place Does an Hreflang Tag Go?
There are 3 ways to implement hreflang attributes:
- Within the HTML head of the web page
- Within the HTTP header (for non-HTML recordsdata like PDFs)
- Within the XML sitemap
1. Within the HTML
Probably the most primary option to point out your alternate pages is within the web page’s HTML code.
Merely add all of the related hreflang attributes within the <head> portion of the web page.
Keep in mind—every language model of an article should reference itself. In addition to all different language variations.
Right here’s what the syntax seems to be like once more for every aspect:
<hyperlink rel="alternate" href="url_of_page" hreflang="lang_code" />
The one actual subject with this technique is it may be messy and time-consuming.
For instance, each time you translate an article into one other language, it’s important to return and add one other hreflang tag to all variations of it.
Notice: For numerous hreflang entries, you in all probability wish to point out your alternate pages by way of your sitemap. We’ll get to how you are able to do that in a bit.
To create or modify hreflang tags in HTML, strive utilizing an hreflang instrument.
For this instance, we’ll use Aleyda Solis’ hreflang generator instrument.
Simply enter the URL, language, and nation for each model of the article you’re engaged on.
Choose “Tags to incorporate within the head space of the pages HTML” and click on on “GENERATE THE HREFLANG TAGS FOR THESE URLS.”

Then, copy the code and paste it into every web page’s <head> tag.

HTTP headers are nice for implementing hreflang attributes for non-HTML content material in your web site.
Like PDFs, for instance.
HTTP header codes switch knowledge between a server and a shopper. This code accommodates details about the date of the request, the referrer, most popular language, and so forth.
Notice: You should use this technique for HTML content material, too. However it might add a variety of burden when it comes to server requests. So, you’re higher off solely utilizing it solely when strictly obligatory.
The format of the header in HTTP seems to be like this:
Hyperlink: <url 1>; rel="alternate"; hreflang="language code 1",
<url 2>; rel="alternate"; hreflang="language code 2", …
Right here’s what the syntax means:
- <url x> is the URL of the alternate web page associated to the locale assigned to the hreflang attribute. It should embrace surrounding < and > marks.
- Language code x is the language (or area) code focused by this web page
You need to point out a set of <url>, rel=”alternate,” and hreflang values for each model of the web page, together with itself, separated by a comma.
Say you create a PDF doc in three variations—one in English, one in Spanish, and one in Portuguese.
Your HTTP header ought to appear to be this (for every file):
Hyperlink: <https://instance.com/doc.pdf>; rel="alternate"; hreflang="en",
<https://instance.com/es/doc.pdf>; rel="alternate"; hreflang="es",
<https://instance.com/pt/doc.pdf>; rel="alternate"; hreflang="pt"
3. On the XML Sitemap
The third hreflang implementation technique is thru your XML sitemap.
An XML sitemap is a file that gives serps with details about the pages in your website.
So it’s a good way to let Google know of all of the language and area variants of every URL.
It additionally has one main profit:
The XML sitemap lets you make any modifications to your hreflang attributes multi function place.
With the HTML and HTTP header hreflang strategies, it’s important to go in and replace a number of recordsdata each time you get a weblog or doc translated to a different language. It will get messy.
To get began, you must add a <loc> aspect for every URL. With <xhtml:hyperlink> entries for each language and area model of the web page.
Together with itself.
Which suggests:
You probably have three variations of a web page, your sitemap could have three entries. One for every URL. And every of these entries could have three equivalent listings.
If we run with our unique instance of the English, Spanish, and Portuguese weblog, that is what the portion of the sitemap for this weblog publish will appear to be:
<url>
<loc>https://https://instance.com</loc>
<xhtml:hyperlink rel="alternate" hreflang="en-us"
href="https://https://instance.com" />
<xhtml:hyperlink rel="alternate" hreflang="es-es"
href="https://instance.com/es/" />
<xhtml:hyperlink rel="alternate" hreflang="pt-br"
href="https://instance.com/pt/" />
</url>
<url>
<loc>https://instance.com/es/</loc>
<xhtml:hyperlink rel="alternate" hreflang="en-us"
href="https://https://instance.com" />
<xhtml:hyperlink rel="alternate" hreflang="es-es"
href="https://instance.com/es/" />
<xhtml:hyperlink rel="alternate" hreflang="pt-br"
href="https://instance.com/pt/" />
</url>
<url>
<loc>https://instance.com/pt/</loc>
<xhtml:hyperlink rel="alternate" hreflang="en-us"
href="https://https://instance.com" />
<xhtml:hyperlink rel="alternate" hreflang="es-es"
href="https://instance.com/es/" />
<xhtml:hyperlink rel="alternate" hreflang="pt-br"
href="https://instance.com/pt/" />
</url>
</urlset>
You should use the identical hreflang generator instrument to create or modify hreflang tags in an XML sitemap.
Begin by coming into the URL, language, and nation for each model.
Then choose “Attributes in an XML Sitemap” and click on “GENERATE THE HREFLANG TAGS FOR THESE URLS.”

Then, copy the code and add it into your website’s XML sitemap.

The way to Discover and Repair Hreflang Points
You’ll find and repair hreflang points by often auditing your web site.
And by utilizing Semrush’s Website Audit instrument as an hreflang checker.
Begin by coming into your area and making a venture.

After the instrument crawls your website, head to the “Points” tab. Then, seek for “hreflang” within the search bar.
Like this:

You’ll see an inventory of all of your hreflang conflicts. Together with the kind of subject and the way to repair it.

For reference, listed here are the commonest hreflang points and the way to repair them:
Points With Hreflang Values
The sort of warning is triggered when the nation or language codes aren’t within the appropriate format.

It’s necessary to repair this subject as a result of serps could ignore hreflang tags with incorrect codes.
And in the event that they ignore the tag, they might present customers the improper model of your web page. That’s not good to your search engine optimization.
Repair this subject by reviewing the hreflang tags in every affected URL.
Be sure that the syntax in every attribute follows the right codes. Two-letter ISO 639-1 for languages and ISO 3166-1 alpha-2 for nations and areas.
You possibly can at all times use an hreflang generator instrument to confirm or create your tags.
No Self-Referencing Hreflang
The hreflang attribute on every web page ought to embrace a reference to all of the pages that function alternates. Together with a reference to itself.

If hreflang attributes don’t self-reference, serps can ignore or misread them.
Repair this subject by reviewing every affected URL and including a self-referencing hreflang tag to the set of hreflang attributes.
Points With Incorrect Hreflang Hyperlinks
The sort of warning triggers when there is a matter with the hyperlink within the hreflang attribute.
For instance, the hyperlink would possibly level to a web page that’s damaged or has been redirected.

If this occurs, serps could ignore your hreflang attributes.
Repair this subject by reviewing every affected URL and altering the annotation to ensure it factors to a working web page.
Conflicting Hreflang and Rel=Canonical URLs
The sort of warning occurs when an hreflang tag references a non-canonical URL.

A canonical tag is an HTML attribute that signifies the principle model of a web page when you’ve got duplicate (or near-duplicate) pages. It tells serps which model of a web page is most authoritative and will seem in search outcomes.
So, what in case your hreflang attributes reference a non-canonical model of a specific web page?
The 2 tags contradict one another:
- The hreflang attribute says the non-canonical web page ought to seem in search outcomes for customers who converse specific languages
- The canonical tag says a special model of that web page ought to seem in search outcomes
To place it merely: It’s going to confuse serps. And so they’ll in all probability ignore the hreflang, canonical, or each.
Repair this subject by going to every affected URL and altering the hreflang annotations to level to canonical URLs.
Automate Your Hreflang Tag Audits
After you learn to implement hreflang tags and repair associated points, take issues a step additional by automating your hreflang audits.
That means, you’ll be notified of any points earlier than they turn into greater issues.
To automate your hreflang audits, arrange a recurring report in Website Audit.
Within the prime proper nook of your dashboard, click on on the gear “settings” image.
Then, scroll down and discover “Schedule.”

You’ll then see a pop-up the place you’ll be able to select how usually you wish to run your audit.
Set it to your most popular day. Then, tick the “Ship an e mail” choice.
And click on “Save.”

New points will present in your dashboard’s “Worldwide search engine optimization” field after every crawl. So, be certain to verify it often.

Now you’re set to repair any hreflang implementation points that pop up and preserve your search engine optimization efforts operating easily.