HTMLAnchorElement: hreflang property

The hreflang property of the HTMLAnchorElement interface is a string that is the language of the linked resource.

It reflects the hreflang attribute of the <a> element and is the empty string ("") if there is no hreflang element.

Web browsers and search engines may use this information to understand the language of the linked content better, but they are not required to follow it. The value provided for the hreflang attribute adheres to the format defined in RFC 5646: Tags for Identifying Languages (also known as BCP 47). If not, it is ignored.

Web browsers do not rely solely on the hreflang attribute after fetching the linked resource. Instead, they use language information directly associated with the resource (e.g., through HTTP headers) to determine its language.


A string that contains a language tag, or the empty string ("") if there is no hreflang element.


<a id="exampleLink" href="" hreflang="en-IN">Example Link</a>
<p class="hreflang"></p>
#exampleLink {
  font-size: 1.5rem;
const anchorElement = document.getElementById("exampleLink");
const pTag = document.querySelector(".hreflang");
console.log(anchorElement.hreflang); // Outputs: "en-IN"
pTag.textContent = anchorElement.hreflang;



HTML Standard
# dom-a-hreflang

Browser compatibility

BCD tables only load in the browser

See also