Hreflang mastery
Hreflang Syntax Writing Tags Without Errors
Hreflang syntax is unforgiving: wrong ISO codes, missing return tags or malformed attributes silently break the whole cluster. Learn the exact format before deploying at scale.
Reading time · unlocks the next lesson
0:00 / 5:00 · pausedCorrect syntax, three implementation methods
Hreflang can be implemented in the HTML head as link tags, in the HTTP header (useful for non-HTML files like PDFs), or in an XML sitemap. The link tag format is: link rel="alternate" hreflang="fr-fr" href="https://example.com/fr/". The hreflang value uses ISO 639-1 language code, optionally followed by a hyphen and ISO 3166-1 Alpha-2 country code — language is mandatory, country is optional and must come second, never first.
A frequent error is using region-only codes like hreflang="eu" or reversing the order to "fr-fr" written as country-first "fr-FR" (this specific case is actually fine since fr is language and FR is country, but writing "FR-fr" reversed is invalid). Case doesn't technically matter to Google but convention is lowercase language, uppercase country: fr-FR.
- link rel="alternate" hreflang="en-gb" href="https://example.com/uk/"
- Language code is mandatory; region code is optional and comes second
- Use ISO 639-1 for language, ISO 3166-1 Alpha-2 for region
- Never use continent codes (eu, asia) — they are not valid values
- x-default is written as hreflang="x-default"
The return-tag requirement
Every hreflang relationship must be reciprocal: if page A declares an alternate for page B, page B must declare an alternate back to page A, and both must also self-reference. Google treats one-directional hreflang as invalid and will ignore the entire annotation set for that cluster rather than partially applying it — this is the single biggest cause of hreflang 'not working' complaints.
For large sites, generate all hreflang tags programmatically from a single source of truth (a market/URL mapping table) rather than hand-editing templates per page, since manual editing is where reciprocal tags drift out of sync as pages get added or removed over time.
Key takeaways
- ✓Language code is mandatory, region code is optional and always second
- ✓Every URL in a cluster must self-reference and reciprocate every other URL
- ✓Never use continent codes; only ISO 639-1 and ISO 3166-1 Alpha-2
- ✓Generate hreflang programmatically from a single mapping table at scale
Why this lesson matters
This lesson belongs to Hreflang mastery, the part of International SEO where the goal is: write, validate and maintain hreflang so google serves the correct url to the correct market every time.
Read it once, then do it straight away on a real site inside RankTracker. Nothing here is theory for its own sake — every step produces something you can show a client.
Do it now
- 1Open RankTracker with sample data already loaded, so you are not stuck on setup.
- 2Track the keywords from this lesson.
- 3Use RankTracker's hreflang crawl view to list every hreflang cluster on your site and flag any without matching return tags.
