Link hreflang Attribute

Definition and Usage

hreflang The attribute sets or returns the language code of the linked document.

The hreflang attribute will not be displayed as any special content in any mainstream browser. However, it can be used by search engines or scripts.

Tip:To view all available language codes, please visit ourLanguage Code Reference Manual.

See also:

HTML Reference Manual:HTML <link> hreflang Attribute

HTML Reference Manual:HTML <link> Tag

Example

Example 1

Return the language code of the linked document:

var x = document.getElementById("myLink").hreflang;

Try it yourself

Example 2

Change the language code of the linked document:

document.getElementById("myLink").hreflang = "en-us";

Try it yourself

Syntax

Return the hreflang attribute:

linkObject.hreflang

Set the hreflang attribute:

linkObject.hreflang = languagecode

Attribute Value

Value Description
languagecode Specifies the language code of the linked document.

Technical Details

Return Value: A string value representing the language code of the linked document.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support