Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

hreflang — language of the linked resource

The hreflang attribute identifies the language of a linked resource. Its value is a valid BCP 47 language tag and is only a hint: it neither sets the current document’s language nor overrides language information associated with the fetched resource.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<a href="URL" hreflang="language-tag">...</a>
<link rel="alternate" href="URL" hreflang="language-tag">

The hreflang attribute describes the language of the linked resource, not the language of the link text. Its value must be a valid BCP 47 language tag, such as en or en-GB. It is not a boolean attribute: supply a language tag rather than an empty value.

On an a element, it describes the hyperlink destination. On a link element, it has the same meaning; combining rel="alternate" with hreflang can identify an alternative language version. By itself, hreflang does not establish that the resource is a translation of the current page.

The information is purely advisory. After fetching the resource, the browser must determine its language using information associated with that resource, not the link metadata. Do not confuse hreflang with lang, which specifies the language of an element’s content; the attribute does not translate text either.

In the example, lang="pl" describes the document, while both occurrences of hreflang="en" describe guide-en.html. The visible text is English guide; the link metadata does not add a second visible link.

Examples

<!doctype html>
<html lang="pl">
<head>
  <meta charset="utf-8">
  <title>hreflang</title>
  <link rel="alternate" href="guide-en.html" hreflang="en">
</head>
<body>
  <a href="guide-en.html" hreflang="en">English guide</a>
</body>
</html>

Result

English guide

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources