|

Tiempo de lectura

11 min

What hreflang is and when a site needs it

Hreflang is how you tell Google which URL belongs to each language or country, so they do not compete with each other in search. You need it when the same site exists in more than one language. You do not need it on a site that is only in one language, and putting it in wrong is worse than leaving it out. It does not translate the page or add rankings just by existing in the code.

What problem it solves

You have the same page in two languages, or the same offer for two countries. Without a notice, Google sees two similar URLs and picks one, sometimes the one that is wrong for that person. Hreflang is that notice: this URL is Spanish, this other one is English, and this is the one you show if you do not know the language.

It does not translate. It does not change the content. It does not replace a good page in each language. If the English version is the Spanish one with four sentences run through an automatic translator and the rest identical, hreflang does not turn that into an English site. It only declares the relationship.

When you need it, and when it gets in the way

  • You need it if there are distinct URLs by language, for example one at the root in Spanish and another under /en/ in English, and the content is the equivalent.

  • You need it if you serve the same language to two countries with distinct URLs, and there is a real difference that justifies the split. The code then carries a region, not only a language.

  • You do not need it on a single-language site. The HTML lang attribute is enough to declare that language.

  • It gets in the way if it points at a URL that redirects, returns 404, or is not the translation of that page. Relating an article on one topic to the homepage of the other language is a false map.

The useful answer is the list above. Long guides get lost in the code before they say whether you need it.

How to read a notice that is done properly

Each page includes a link to itself and another to each version. The codes are language codes, such as es or en, and they add a country only when the URL is specific to that country. x-default points at the version for whoever does not fit: on many sites, the Spanish one, or a language-choice page. It is not left empty.

The relationship goes both ways. If the Spanish page points at the English one, the English one has to point at the Spanish one. One direction only is the most common failure, and Google can discard the whole group.

One structure, without copying anyone's as if it were the only one: the Spanish page lives at the root and the English page lives under an /en/ prefix, with the slug translated. The notice relates those two URLs, not every URL on the domain with every other. Each pair is its own. An article that exists only in Spanish must not invent an English sibling.

The three implementations

  1. In the HTML. Several link elements in the head. It is the easiest to check: you view the page source and you see the map. It fits when each language's template can write those links.

  2. In the XML sitemap. The same relationships, inside the file. It fits when there are many URLs and the generator does not forget a pair. You have to regenerate it when you publish a translation, not only when you publish a new article in one language.

  3. In the HTTP header. For a resource that has no head, such as a PDF. On a services site it almost never appears.

You do not need to use all three at once. You need the one you use to be complete. Mixing a half-done HTML with a sitemap that says something else is another way for Google to ignore the signal.

What to look at to know it is wrong

Open a Spanish URL and search for hreflang. It has to list itself, the equivalent English URL, and the x-default. Open the English one and check the way back. Try an article that is not translated: it should not promise an English URL that returns 404.

Search Console can show hreflang errors when it detects them: odd codes, destinations that do not return the link, pages that cannot be indexed. A redirect on the destination cancels the notice. That is why hreflang is reviewed after a migration, together with the 301 redirects, not before you know which URLs are final.

The language the browser sees, the lang attribute, is separate. You can have lang set to Spanish on an English template if the template was copied and nobody changed that line. Hreflang does not correct that slip. You have to change the language of the page.

What it will not do for rankings

It does not add positions in a language you have not translated. It does not stop a weak page from competing: it only stops it from competing with its translation. And it is not the first job of a new site in a single market. First the page in the language of your customers, indexable, with a title that names the service. The map of that work is in what SEO is. Hreflang comes in the day the second version exists, not the day someone reads that the attribute is a best practice.

If you already have both versions, check a real pair: a service page and a translated article. Do not treat the homepage as proof that the rest is the same. New articles are the ones left without a sibling, or with a sibling that points at an old URL.

Three ways to implement hreflang

Google accepts the same notice in three places. The table says where each one lives. The notice has to be reciprocal: if A points at B, B points at A.

Method

Where it goes

When it fits

In the HTML

A link in the head of each page

Sites where you can edit the template of each language

In the sitemap

Annotations inside the XML

Many URLs, and a generator that does not forget pairs

In the HTTP header

The server response

Files that are not HTML, such as a PDF

Conclusion

Hreflang does not translate the page. It only says which URL is the version for each language. If you do not have that version, do not add it. If you do, each URL must point at the other and at itself, with an x-default for whoever does not fit a language.

Frequently asked questions about hreflang

What is hreflang?

It is a notice to search engines that relates the URLs of the same content in different languages or countries. That way Google can show the Spanish version to someone searching in Spanish and the English version to someone searching in English, instead of treating them as duplicates that compete.

Are hreflang and the lang attribute the same?

No. The HTML lang attribute tells the browser and screen readers which language that page is in. Hreflang tells Google which other URLs are the translations. You can have the language marked correctly and still have no hreflang. If there is more than one language, you need both.

Does a site in only one language need hreflang?

No. If there is no other version, there is nothing to relate. Pointing hreflang at the same URL, or at a translation that does not exist, does not improve rankings. It only creates a notice that does not match the site, and Google can ignore it entirely.

What happens if hreflang is wrong?

Google can ignore it. The typical case is that the Spanish page points at the English one and the English one does not point back, or that the language code is invented. It is not a penalty with that name. It is a signal that stops counting, and the two URLs compete again without a map.

Need a marketing team?

Let’s talk and grow your business

BG Image

Let's build something remarkable

Ready for your next project

+

You

15-minute call

Pick the best time for you

Vector
Vector
Element Image
Otros blogs