HTMLLinkElement: hreflang property
Baseline Widely available
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.
Value
A string that contains a language tag, or the empty string (""
) if there is no hreflang
attribute.
Example
html
<link
rel="alternate"
href="www.example.com/fr/html"
hreflang="fr"
type="text/html"
title="French HTML" />
<p class="tag"></p>
css
.tag {
margin-left: 20px;
font: bold;
font-size: 24px;
}
js
const myLink = document.querySelector("link");
const pTag = document.querySelector(".tag");
pTag.textContent = myLink.hreflang;
Results
Specifications
Specification |
---|
HTML # dom-link-hreflang |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
hreflang |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
HTMLAnchorElement.hreflang
property