This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The hreflang property of the HTMLLinkElement interface is used to indicate the language and the geographical targeting of a page. This hint can be used by browsers to select the more appropriate page or to improve SEO.
It reflects the hreflang attribute of the <link> element and is the empty string ("") if there is no hreflang attribute.
A string that contains a language tag, or the empty string ("") if there is no hreflang attribute.
<link rel="alternate" href="www.example.com/fr/html" hreflang="fr" type="text/html" title="French HTML" /> <p class="tag"></p>
.tag {
margin-left: 20px;
font-weight: bold;
font-size: 24px;
}
const myLink = document.querySelector("link");
const pTag = document.querySelector(".tag");
pTag.textContent = myLink.hreflang;
| Specification |
|---|
| HTML> # dom-link-hreflang> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
hreflang |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
HTMLAnchorElement.hreflang property
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement/hreflang