To understand what an hreflang attribute is, one must know the definition of attribute first. All HTML elements can have attributes. They provide additional information about an element and are always specified at the start tag and usually come in name/value pairs like name=’value.’
An hreflang attribute is an HTML tag that tells search engines what your target language is. This way, users who are searching in that language can find more accurate results. Other names for it are rel=’alternate’ or hreflang=’x.’
Where do I write this tag?
The attribute can be applied in one of three ways: on the sitemap, in the HTML <header> of the page, or the HTTP header.
Here’s an example. In order to write the attribute on the HTML header section of the page, you must use the rel=’alternate’ or hreflang=’x’ commands. It would look something like this:
rel=”alternate”, href=”(URL here)”, hreflang=”x”
rel=“alternate” lets search engines know there is an alternative version of a page.
href=”(url here)” tells them where that page is located.
hreflang=”x” specifies the language of the page and country. “x” would be where the language and the ISO country code goes.
You can obtain the different endings of the attribute by consulting the ISO Language and Region Codes, ‘de’ for Germany, ‘es’ for Spain, and so on.
This attribute is handy when you want to change your website’s language or want to publish content for a local audience. For example, if your site is in English, but you have created content for a Spanish speaking audience, then adding the hreflang=es to the HTML code should do the trick. This ensures people from Spanish speaking countries can see your content in their desired language.