In this post we will try to help you better understand the hreflang tag and to improve your website when it is published in different languages. It is important to keep in mind that translations “on the fly” by using Google Translate plugins or api are not useful. All content must be translated and, if possible, by an expert in each language.
Contents
What is the hreflang tag and what is it for?
The hreflang tag is a HTML attribute very useful in our webs when we work the content in several languages. Using this tag we are helping the crawling robots to locate the correct version of our website by language or region.
The hreflang tag tells search engines if a website is displayed in different languages, the location of the website and in which versions the content is served. The use of this tag is recommendable so much for the translation into several languages such as language variations, such as Spanish in South America. By applying this tag we help Google to better understand in which language our website is offered in order to show it to users according to their origin. If we have several versions of the same page, with this hreflang tag we are indicating to Google which of all the versions we want to show the user.
If we have a multilanguage website or ecommerce, this label is very convenient for improve positioning of our contents in different parts of the world.
Using this tag we can attract new audiences to our website.
- Users from the same country who speak different languages
- Users from different countries who speak other languages
- Users from different countries speaking the same language
How to use the hreflang tag?
Enough with include in head section of our website the following link with the proper language code. We must place each of these labels in its corresponding language, as many as the languages our website offers. Today, there are many plugins for website translation that offer this function automatically in their paid versions.
The correct format for hreflang tag implementation should be the following:
<link rel=”alternate” hreflang=”it-IT” href=”https://www.yourdomain.com/“/>
- relay link=“alternate”: The link in this tag is an alternate version of this page.
- hreflang=“x”: It is alternative because it is in another language and that language is x.
- href=“https://mydomain.com/alternative-page”: The alternative page is at this address.
Hreflang gives search engines important information about your content, as it indicates language codes and country codes for each content. This code tells search engines which language and region the content is targeting. It is important to note that the attribute value must contain both the language and the country “is-ES”.
There are tag generators like https://www.aleydasolis.com/english/international-seo-tools/hreflang-tags-generator/
Relationship between hreflang tags
The relationship between hreflang tags means that it must reference itself and all other versions. When we talk about bidirectional relationship each tag must be paired with a tag in the alternate content.
For example, if the ES page connects to the EN page, then the EN page must connect back to the ES page.
Language and region codes
The value of the hreflang attribute indicates the language (in format ISO 639-1) and sometimes the region (in format ISO 3166-1 Alpha 2) of an alternate URL. If only one code is provided, Google considers it a language code. The language does not have to be related to the region. By example:
de: content in German, regardless of region
en-GB: English content aimed at British users
of is: content in German for users who are in Spain
SEE ALL THE CODES AT THE END OF THE POST
Label x-default
to show a specific version to users of languages not indicated
La X-default variant creates a default version of a page that is not targeted to a specific language where users are prompted to select language. This is very useful for users who don't have a default language in your browser settings
For example, if we serve our website in ES and EN languages and a user accesses from China, by default we can indicate that the website is served in English.
An optional value, but it's recommended to include it to control which version is shown to users of languages you haven't specified. It is not necessary to specify a language code in the x-default value.
Example.
UK
USES
AUSTRALIA
BY DEFAULT / rest of users
What function does the hreflang tag have in SEO?
The main function of this tag is to improve the usability of the website as we make it easy for users to localize our content in their language or location. This can also help us with positioning, since if a website in one language has a good positioning, it can affect other language variations.
How does the hreflang tag help us in the SEO International?
First of all, the use of this label helps us to improve positioning SEO law We have already defined the correct version for each language and this is detected by crawlers such as Googlebot. In this way we help search engines to index the keywords in the correct language.
The implementation of the hreflang tag helps avoid duplicate content since we are indicating the different versions of our website.
When to use the hreflang tag?
Sometimes Google can detect the different language versions of a website but it is important to indicate it. Google our recommended indicate localized versions in Google Search Console in the following cases:
- When the content is only in one language but there are regional variations with very similar content. For example, pages with content in Spanish aimed at Mexico, Spain or Colombia.
- When web content is in a language and a translation of the template is made, from the navigation menu and web footer. This situation usually occurs on pages with user-generated content, such as forums.
- The content is fully translated into several languages. For example, pages with a version in English and another in Spanish.
- When our home page is created for all users to exception of visitors with a specific language. In this case the website is partially translated and only provides content to certain specific users in certain languages or regions. All other users will be directed to the default home page.
Methods to indicate alternative pages
You can tell us that a page has versions in other languages or targeted to certain regions in three different ways:
HTML
HTTP headers
Link: ; rel=”alternate”; hreflang=”lang_code_1″, ; rel=”alternate”; hreflang=”lang_code_1″, …
Sitemap
Specify the xhtml namespace like so:
xmlns:xhtml=”http://www.w3.org/1999/xhtml”
Create an item different for each URL.
Each element must include a child element indicating the URL of the page.
Each element must have a child element with all variants of the page, including that of the element itself. The order of these children It's not important, but we recommend that you always use the same one to make it easier for you to check for errors.
Example.
<urlset xmlns=»http://www.sitemaps.org/schemas/sitemap/0.9″
xmlns:xhtml=”http://www.w3.org/1999/xhtml”>
https://www.example.com/english/page.html
<xhtml:link
rel=”alternate”
hreflang=”de”
href=”https://www.example.com/deutsch/page.html”/>
<xhtml:link
rel=”alternate”
hreflang=”de-ch”
href=”https://www.example.com/schweiz-deutsch/page.html”/>
<xhtml:link
rel=”alternate”
hreflang=”en”
href=”https://www.example.com/english/page.html”/>
Common errors with the hreflang tag
Missing reciprocal links: if page X contains a link to page Y, page Y must have a link to page X. If this condition is not met on all pages that use hreflang annotations, these annotations may be ignored or are not interpreted correctly. For example, if https://de.example.com/index.html includes this link:
An hreflang link must also be included in https://en-gb.example.com/index.html that returns to the version of the content:
Wrong language codes: Make sure the language codes you use identify the language in ISO 639-1 format and, optionally, the region in ISO 3166-1 Alpha 2 format of alternate URLs. You cannot specify only the region.
test hreflang
you can use this tool to verify correct implementation of this tag.
List of language codes
Language | Hreflang Code |
abkhazian | ab |
Afrikaans | af |
Aragonese | an |
Arabic | ar |
assamese | as |
azerbaijani | az |
belarusian | be |
bulgarian | bg |
bengali | bn |
tibetan | bo |
Breton | br |
bosnian | bs |
Catalan / Valencian | ca |
Chechen | ce |
corsican | co |
Czech | cs |
Church Slavic | cu |
welsh | cy |
Danish | da |
German | de |
greek | el |
English | en |
Esperanto | eo |
Spanish / Castilian | es |
estonian | et |
basque | eu |
persian | fa |
finnish | fi |
fijian | fj |
faroese | fo |
French | fr |
Western Friesian | fy |
Irish | ga |
Gaelic / Scottish Gaelic | gd |
galician | gl |
M | gv |
hebrew | he |
Hindi | hi |
croatian | hr |
Haitian; Haitian Creole | ht |
hungarian | hu |
armenian | hy |
Indonesian | id |
icelandic | is |
Italian | it |
Japanese | ja |
javanese | jv |
georgian | ka |
Congo | kg |
Korean | ko |
Kurdish | ku |
cornish | kw |
Kirghiz | ky |
latin | la |
Luxembourgish; Letzeburgesch | lb |
Limburgan; limburger; Limburgish | li |
lingala | ln |
lithuanian | lt |
latvian | lv |
malagasy | mg |
macedonian | mk |
mongolian | mn |
Moldovan | mo |
malay | ms |
maltese | mt |
Burmese | my |
Norwegian (Bokmål) | nb |
nepali | ne |
Dutch | nl |
Norwegian (Nynorsk) | nn |
norwegian | No. |
Occitan (post 1500); provencal | oc |
Polish | pl |
Portuguese | pt |
Raeto-novel | rm |
Romanian | ro |
russian | ru |
Sardinian | sc |
Northern Sami | se |
slovak | sk |
Slovenian | sl |
somali | so |
albanian | sq |
Serbian | sr |
Swedish | sv |
swahili | sw |
turkmen | tk |
Turkish | tr |
tahitian | ty |
Ukrainian | uk |
urdu | ur |
uzbek | uz |
Tiếng Việt | vi |
Volapuk | vo |
yiddish | yi |
Chinese (simplified) | zh-hans |
ภาษาไทย | th |
List of country codes
Country | Hreflang Code |
Afghanistan. | AF |
Aland Islands | AX |
Albania | AL |
Algeria | DZ |
American Samoa | AS |
Andorra | AD |
Angola | AO |
Anguilla | AI |
Antarctica | AQ |
Antigua and Barbuda | AG |
Argentina | AR |
Armenia | AM |
Aruba | AW |
Australia | AU |
Austria | AT |
Azerbaijan | AZ |
Bahamas | BS |
Bahrain | BH |
Bangladesh | BD |
Barbados | BB |
Belarus | BY |
Belgium | BE |
Belize | BZ |
Benin | BJ |
Bermuda | BM |
Bhutan | BT |
Bolivia, Plurinational State of | BO |
Bonaire, Sint Eustatius and Saba | BQ |
Bosnia and Herzegovina | BA |
Botswana | BW |
Bouvet Island | BV |
Brazil | BR |
British Indian Ocean Territory | IO |
Brunei Darussalam | BN |
Bulgaria | BG |
Burkina Faso | BF |
Burundi | BI |
Cambodia | KH |
cameroon | CM |
Canada | CA |
Cape Verde | CV |
Cayman Islands | KY |
Central African Republic | CF |
Chad | TD |
Chile | CL |
China | CN |
Christmas Island | CX |
Cocos (Keeling) Islands | CC |
Colombia | CO |
Comoros | KM |
Congo | CG |
Congo, the Democratic Republic of the | CD |
Cook Islands | CK |
Costa Rica | CR |
Cote d'Ivoire | CI |
Croatia | HR |
Cuba | CU |
Curaçao | CW |
Cyprus | CY |
Czech Republic | CZ |
Denmark | DK |
Djibouti | DJ |
Dominica | DM |
Dominican Republic | DO |
Ecuador | EC |
Egypt | EG |
The Savior | SV |
Equatorial Guinea | GQ |
eritrea | ER |
Estonia | EE |
Ethiopia | ET |
Falkland Islands (Malvinas) | FK |
Faroe Islands | FO |
Fiji | FJ |
Finland | FI |
France | FR |
French Guiana | GF |
French Polynesia | PF |
French Southern Territories | TF |
Gabon | GA |
Gambia | GM |
Georgia | GE |
Germany | DE |
Ghana | GH |
Gibraltar | GI |
Greece | GR |
greenland | GL |
Grenada | GD |
Guadeloupe | GP |
Guam | GU |
Guatemala | GT |
Guernsey | GG |
Guinea | GN |
Guinea-Bissau | GW |
Guyana | GY |
Haiti | HT |
Heard Island and McDonald Islands | HM |
Holy See (Vatican City State) | VA |
Honduras | HN |
Hong Kong | HK |
Hungary | HU |
Iceland | IS |
India | IN |
Indonesia | ID |
Iran, Islamic Republic of | IR |
Iraq | IQ |
ireland | IE |
Isle of Man | IM |
Israel | IL |
Italy | IT |
Jamaica | JM |
Japan | JP |
Jersey | JE |
Jordan | JO |
Kazakhstan | KZ |
Kenya | KE |
Kiribati | KI |
Korea, Democratic People's Republic of | KP |
Korea, Republic of | KR |
Kuwait | KW |
Kyrgyzstan | KG |
Lao People's Democratic Republic | LA |
latvia | LV |
lebanon | LB |
Lesotho | LS |
Liberia | LR |
libya | LY |
Liechtenstein | LI |
lithuania | LT |
Luxembourg | LU |
Macau | MO |
Macedonia, the Former Yugoslav Republic of | MK |
Madagascar | MG |
Malawi | MW |
Malaysia | MY |
Maldives | MV |
Mali | ML |
Malta | MT |
Marshall Islands | MH |
Martinique | MQ |
Mauritania | MR |
Mauritius | MU |
Mayotte | YT |
Mexico | MX |
Micronesia, Federated States of | FM |
Moldova, Republic of | MD |
Monaco | MC |
Mongolia | MN |
Montenegro | ME |
Montserrat | MS |
morocco | MA |
Mozambique | MZ |
Myanmar | MM |
Namibia | NA |
Nauru | NR |
Nepal | NP |
Netherlands | NL |
New Caledonia | NC |
new zealand | NZ |
Nicaragua | NI |
Niger | NE |
Nigeria | NG |
Niue | NU |
norfolk island | NF |
Northern Mariana Islands | MP |
norway | DO NOT |
Oman | OM |
Pakistan | PK |
palau | PW |
Palestine, State of | PS |
Panama | PA |
Papua New Guinea | PG |
Paraguay | PY |
Peru | PE |
Philippines | PH |
Pitcairn Islands | PN |
poland | PL |
Portugal | PT |
Puerto Rico | PR |
Qatar | QA |
Reunion Island | RE |
Romania | RO |
Russian Federation | RU |
Rwanda | RW |
Saint Barthelemy | BL |
Saint Helena, Ascension and Tristan da Cunha | SH |
Saint Kitts and Nevis | KN |
saint lucia | LC |
Saint Martin (French part) | MF |
Saint Pierre and Miquelon | PM |
Saint Vincent and the Grenadines | VC |
Samoa | WS |
San Marino | SM |
Sao Tome and Principe | ST |
Saudi Arabia | SA |
Senegal | SN |
Serbia | RS |
Seychelles | SC |
Sierra Leone | SL |
Singapore | SG |
Sint Maarten (Dutch part) | SX |
Slovakia | SK |
Slovenia | SI |
Solomon Islands | SB |
Somalia | SO |
south africa | ZA |
South Georgia and the South Sandwich Islands | GS |
south sudan | SS |
Spain | ES |
Sri Lanka | LK |
Sudan | SD |
Suriname | SR |
Svalbard and Jan Mayen | SJ |
Swaziland | SZ |
Sweden | SE |
Switzerland | CH |
Syrian Arab Republic | SY |
Taiwan, Province of China | TW |
Tajikistan | TJ |
Tanzania, United Republic of | TZ |
Thailand | TH |
Timor-Leste | TL |
Togo | TG |
Tokelau | TK |
Tonga | TO |
Trinidad and Tobago | TT |
tunisia | TN |
Turkey | TR |
Turkmenistan | TM |
Turks and Caicos Islands | TC |
Tuvalu | TV |
Uganda | UG |
Ukraine | UA |
united arab emirates | AE |
United Kingdom | GB |
United States | US |
United States Minor Outlying Islands | UM |
Uruguay | UY |
Uzbekistan | UZ |
Vanuatu | VU |
Venezuela, Bolivarian Republic of | VE |
vietnam | VN |
Virgin Islands, British | VG |
Virgin Islands, US | VI |
Wallis and Futuna | WF |
Western Sahara | EH |
Yemen | YE |
Zambia | ZM |
Zimbabwe | ZW |
Fonts
https://developers.google.com/search/docs/advanced/crawling/localized-versions?hl=es