What is hreflang?
If you have multiple versions of a page targeting different languages or targeting different regions with the same language, tell the search engines about the target audience of the page versions using a hreflang-tag. In this way, you help search engines to show users the page that best suits their language and/or region. Correct use of hreflang is important for your search engine optimisation (SEO) work.
Example of language versioning
For example, suppose you have two virtually identical subpages in German, one of which is aimed at users in Germany, while the other is aimed at users in Austria. In the section of the pages, you need to specify both page versions and the language and region each page version is for. For example, it might look like this:
The former (hreflang="de-de") indicates that the site is aimed at German speakers in Germany, while the latter (hreflang="de-at") indicates German speakers in Austria. However, this solution has the problem that Google does not know which page is most relevant for German speakers in Belgium and Switzerland. You can solve this by having a language entry without region - hreflang="de" - on one of the pages instead:
This way, German speakers in Austria will be shown the latter page, while all other German speakers will be shown the former page. In other words, for language versioning you should always have one page with a general language indication without region. The order of the tags in the source code is irrelevant.
The same principle applies to other languages, for example English, where you can use hreflang="en-us" (English speakers in the US), hreflang="en-gb" (English speakers in the UK) and hreflang="en" (all other English speakers). The language is indicated by a two-digit ISO 639-1 code (list itself). The region is optional and is indicated by a two-digit ISO 3166-1 alpha-2 code (list itself).
Specify hreflang tags for all pages
It is important that all language versions of a page appear on each language version. In other words, if you have 20 language versions, you need to include 20 hreflang tags on each page. Note that you must also link between pages in different languages if one page is a translation of another, and that the same applies to domains if one domain is a translation of another.
If you have many language versions, it is not appropriate to have hreflang tags in the source code itself. They make the source code larger and increase the number of database calls, which makes the load time (loading speed) of the page a little bit worse than otherwise. Instead, you can specify the language versions in a so-called XML sitemap. Read more about this at SearchEngineLand.com.