What does a hreflang tag look like?
What does a hreflang tag look like?
Hreflang tags use simple and consistent syntax:
Here’s what each part of that code means in plain English:
How to construct a hreflang tag
Constructing a hreflang tag is as simple as looking up the code for your chosen language and filling in the tag. Hreflang supports any two-letter ISO 639–1 language code.
Example:
Say that we wanted to add a hreflang tag from the English version of our blog post about free keyword tools to the German version. This is the hreflang tag we’d end up with:
All we did was fill in the language code (de for Germany) and URL.
While it’s fine to specify a language and leave it there, hreflang tags also support the addition of a region or country.
This is also a two-letter code, but this time it’s in the ISO 3166–1 alpha‑2 format (full list).
You only need to add this when you wish to target speakers of a particular language in a particular locale.
For example:
English speakers in the UK:
English speakers in the US:
The basics of hreflang implementation
Hreflang tags are reasonably simple to implement, and we’ll discuss three methods for doing that in a moment.
But no matter which method you opt for, there are three golden rules that you must remember at all times.
Rule #1: Hreflang tags are bidirectional
It’s critical to understand that hreflang tags work in pairs.
In other words, if you add a hreflang tag to an English page pointing to the Italian variant, then the Italian variant must return the favor with a hreflang tag pointing to the English page.
This proves to search engines that you have control over both pages, and that they’re each in agreement about their relationship to one another.
It’s similar to setting a relationship status on Facebook.
You could easily declare yourself as in a relationship with Jennifer Aniston or Brad Pitt, but unless they do the same, nobody is going to believe you.
As such, when the tags are broken, or the relationship hasn’t been fully established yet, you may see the wrong page, multiple pages, or the wrong title for the right URL shown in the search results.
Rule #2 self-referential hreflang attributes are good practice:
Google states that “each language version must list itself as well as all other language versions.”
In plain English, that means that every page should have a self-referential hreflang tag—i.e., one that points back to itself.
So, if we want to add a hreflang tags between an English page:
(https://example.com/hello) and an Italian page (https://example.com/ciao), each should have the following hreflang tags:
The first specifies the URL of the alternate Italian version of the page, and the second is a self-referencing tag that points back to the page itself.
The Italian page would also need both of these hreflang tags.
SIDENOTE. Google’s John Mueller did recently say that “self referential hreflang is optional— but good practice.”
This is at odds with Google’s official recommendation on the matter.
So our advice is to use them.
Rule #3: X‑default tags are recommended, but not mandatory
The hreflang x‑default tag specifies the default or fallback page that gets shown to users when no other language variant is appropriate.
You don’t have to use them, but Google recommends that you do.
This is what one looks like:
How to implement hreflang tags
There are three ways to implement the hreflang attribute:
- HTML tags
- HTTP headers
- Sitemaps
1. Implementing hreflang tags using HTML
If you’re new to hreflang, then using basic HTML tags is probably the easiest and quickest way to implement.
All you need to do is add any appropriate hreflang tags (as discussed above) in the <head> tag of your web page.
Example:
recently launched the Ahrefs blog in several different languages, including German, Russian, Chinese, and Spanish. We’re now slowly translating English versions of the posts on our main blog into these languages.
One of the posts we’ve already translated into both Chinese and German is our list of the best free keyword research tools.
Here are the URLs for all three variants:
To implement hreflang tags correctly for this setup, we’d add this code to the <head> section of each of our pages: