Firefox Tomorrow

web api instance property

HTMLAnchorElement: hreflang property

View on MDN ↗

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 BCP 47 language tag format. 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.

Value

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

Example

<a id="exampleLink" href="https://example.com" 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;

Result

Interactive exampleOpen the canonical MDN source to run this embedded demo.

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also