HTML hreflang Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The hreflang attribute hints at the human language of the resource linked by href. Allowed values match the global lang attribute: valid BCP 47 language tags such as en, en-US, or fr-CA.

Use it on <a>, <area>, and <link> when href is present. With rel="alternate", it marks a translation of the current document.

Baseline · Widely available.

Not deprecated and not experimental. The attribute is supported; it is advisory only (no built-in visual change).

Advisory — not authoritative.

After fetching a resource, user agents must use the resource’s own language information, not hreflang alone, to decide its language.

HTML Syntax

syntax.html
<a href=" url" hreflang="language-tag">

The same hreflang="language-tag" pattern works on <link> and <area>. For alternates in <head>, combine with rel="alternate".

Attribute Values

Language tags and common patterns:

ValueDescriptionTry it
en, fr, …Primary language (BCP 47)Try it
en-US, fr-CALanguage plus regionTry it
With rel="alternate"Marks a translation of the current pageTry it
x-defaultCommon SEO fallback when no other language matchesTry it
On <a>Hints language for a visible language switcher linkTry it

Live Preview

Change hreflang on a real link. The page look stays the same — inspect the attribute to confirm the hint.

Advisory metadata only. Browsers do not restyle the link based on hreflang.

Link

Language version

hreflang="en"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — rel="alternate" Language Links

Declare English and Spanish translations in the document head.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Product page</title>
  <link rel="alternate" href="https://example.com/page" hreflang="en">
  <link rel="alternate" href="https://example.com/page-es" hreflang="es">
</head>
<body>
  <p>English product page.</p>
</body>
</html>
Try It Yourself

How It Works

  1. Pair with alternate. rel="alternate" plus a different hreflang means a translation.
  2. Point href at each version. One URL per language tag.
  3. Keep pages consistent. Each language page should list the same set of alternates (including itself).
  4. Set document lang. Use lang on <html> for the current page’s language.

Example 2 — Visible Links with Regional Tags

Language switcher links can carry hreflang for the destination page.

HTML
<nav aria-label="Languages">
  <a href="https://example.com/en-us/" hreflang="en-US">English (US)</a>
  <a href="https://example.com/fr-ca/" hreflang="fr-CA">Français (Canada)</a>
</nav>
Try It Yourself

How It Works

  1. Region codes. en-US and fr-CA combine language and region.
  2. Clear link text. Users see the language; hreflang adds machine-readable metadata.
  3. Still advisory. The attribute does not auto-redirect or restyle the page.
  4. Prefer head alternates for SEO. Visible switchers help people; <link rel="alternate"> helps crawlers.

Example 3 — Fallback with x-default

Add a default alternate for users when no other language matches.

HTML
<head>
  <link rel="alternate" hreflang="x-default" href="https://example.com/">
  <link rel="alternate" hreflang="en" href="https://example.com/en/">
  <link rel="alternate" hreflang="de" href="https://example.com/de/">
</head>
Try It Yourself

How It Works

  1. x-default. Points to a global or language-picker URL used when nothing else matches.
  2. List real languages too. Include each concrete tag such as en and de.
  3. SEO convention. Widely used by search engines with alternate annotations; keep tags consistent across pages.
  4. Still need valid pages. Every href must resolve to a real alternate, not a soft 404.

Edge Cases & Pitfalls

Most mistakes mix up lang and hreflang, or publish incomplete alternate sets.

advisory

No built-in browser UI

MDN: no built-in functionality. Do not expect redirects or auto language switching from hreflang alone.

lang

Not a substitute for lang

lang labels the current content. hreflang labels the linked URL. You usually need both on multilingual sites.

tags

Use valid BCP 47 tags

Prefer en-US over invented codes. Invalid tags may be ignored by agents.

seo

Return links both ways

Each language version should reference all alternates in the set. One-way annotations are a common crawl issue.

href

Requires href

On <link>, use hreflang only when href is present. Without a destination, the hint has nothing to describe.

Browser Support

hreflang is an HTML attribute for hyperlinks in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

hreflang

Widely available as an advisory attribute on a, area, and link. Visual behavior does not change; search engines and tools may use the hint.

97% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
hreflang Widely supported

Bottom line: Safe to use as language metadata. Pair with correct lang on the page and consistent alternate sets for multilingual SEO.

Key Takeaways

  • Role: hint the language of the linked URL (advisory).
  • Format: BCP 47 tags like en, en-US, fr-CA.
  • Alternates: use with rel="alternate" for translations.
  • vs lang: lang = this page; hreflang = linked page.

One line: hreflang tells agents what language the link points to — it does not change the page look.

Frequently Asked Questions

It hints at the human language of the linked resource. Values follow BCP 47 (same idea as the lang attribute). It is advisory — browsers do not treat it as the final authority after fetching the resource.
It applies to hyperlink-creating elements with href: a, area, and link. The common SEO pattern is <link rel="alternate" hreflang="..." href="..."> in the document head.
lang describes the language of the current element or page. hreflang describes the language of the URL you link to with href.
x-default is a common search-engine convention for a fallback alternate URL when no other language or region matches. It is widely used with rel=alternate language annotations.
No. MDN notes there is no built-in visual behavior. It is metadata for agents such as browsers and search engines.
Use a valid BCP 47 language tag, such as en, en-US, fr, or fr-CA. Invalid tags may be ignored.

Next: hspace

Legacy horizontal spacing on images (deprecated).

hspace tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful