Course contentsShow
← Web Development
Lesson 2542 of 2,98245. InternationalizationFree lesson

Hreflang Tags for SEO

Add hreflang link tags to help search engines understand locale variants of the same content.

Hreflang Tags for SEO

What you'll learn: How to use hreflang link tags to tell search engines which language and regional versions of your content exist, preventing duplicate content penalties and improving international SEO.

What Are Hreflang Tags?

When you've built locale variants of the same page—say, English for the US, English for the UK, and Spanish for Mexico—search engines need guidance. Without it, they might show the wrong version to users or flag your pages as duplicate content.

Hreflang tags are <link> elements placed in your HTML <head> that explicitly declare these relationships. Think of them as a translation map for search engines: "This page exists in these languages/regions, and here's where to find each version."

The Basic Syntax

<link rel="alternate" hreflang="en-US" href="https://example.com/en-us/page" />
<link rel="alternate" hreflang="en-GB" href="https://example.com/en-gb/page" />
<link rel="alternate" hreflang="es-MX" href="https://example.com/es-mx/page" />
<link rel="alternate" hreflang="x-default" href="https://example.com/en-us/page" />

Each page should reference itself and all its alternate versions, including an x-default fallback for unmatched locales.

Why It Matters

Hreflang prevents your US English page from cannibalizing your UK English page in search results. It ensures users in Madrid see the Spanish version, not the English one. It's the final piece connecting your URL structure, locale detection, and translation efforts into a cohesive international strategy.

Key Takeaway: Hreflang tags tell search engines "these pages are the same content in different languages/regions," ensuring the right version appears for the right audience while avoiding SEO penalties.