Dofactory.com
Dofactory.com

HTML <a> hreflang Attribute

The hreflang attribute on an <a> (anchor) tag specifies the language.

Optionally the country region of the link may also be included in the value.

This attribute requires that href has a value.

This value is purely advisory.

Example

#

An hreflang attribute on an <a> tag.
This attribute specifies the link is a page in English.

Go to Microsoft.
Go to <a hreflang="en" target="_blank"
         href="https://microsoft.com/en-us/">Microsoft</a>.

Using hreflang

The hreflang attribute specifies the language and country region of the linked page.

Its value is for advisory purposes only.

The first two characters in the hreflang value represents the language code, such as 'en'.

And the last two characters in the hreflang value represents the country code, such as 'US'.

For example, the hreflang value of 'en-GB' specifies the English language in Great Britain.

Note: The hreflang attribute requires that href has a value.


Syntax

<a href="URL" hreflang="language-code-country-code" />

Values

#

Value Description
language-code-country-code The first 2 characters represent the language code of the linked page.
The last two characters represent the country code (optional).

More Examples

An <a> tag with an hreflang attribute set to English (en) in the United States (US).

Go to Microsoft.
Go to <a hreflang="en-US" target="_blank" 
         href="https://microsoft.com/en-us/">Microsoft</a>.

Browser support

Here is when hreflang support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <a>

Last updated on Sep 30, 2023




Guides