HTML a Tag hreflang Attribute Tutorial

In this section, we will see what hreflang attribute is and how it works in HTML <a> tag.

What is hreflang Attribute in HTML <a> Tag?

The hreflang attribute declares the language of the target document that the <a> element is linked to. For example, if the language of the target document is English, then the value of the hreflang attribute is “en” which is the two-letter code for English.

The use of this attribute is mainly for SEO! Basically, search engines like Google check the value of this attribute to see the language of that document. As a result, search engines like Google can decide if the document is a fit for audiences that are looking for the same type of document written in a specific language.

Note: Search engines are way smarter and can use different methods to figure out the language of a document besides the use of the hreflang attribute. So if you didn’t set this attribute, don’t worry because they can still read your document and automatically set the language for it.

HTML hreflang Attribute in <a> Tag Syntax:

<a hreflang="two-letter-code-for-the-language">

<a> Tag hreflang Attribute Values

The value we set for the hreflang attribute comes within the ISO 639-1 codes list (AKA two-letter code).

For example, if the language of the target document is English, the two-letter code would be “en”.

You can check the full list in: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Example: using hreflang attribute in HTML <a> tag

See the Pen using hreflang attribute in HTML <a> tag by Omid Dehghan (@odchan1) on CodePen.

Leave a Reply