Lesson 6 of 1514 minAdvanced

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.

Want to earn a Rankar Academy certificate?

This lesson is free to read in full, with nothing to sign up for. Join the Academy to track your learning, complete courses and sit the certification assessment.

Join the Academy →

Search journey

International SEO · Hreflang mastery

Stage 1

Correct syntax, three implementation methods

Stage 2

return-tag requirement

Stage 3

this lesson matters

Hreflang Syntax Writing Tags Without Errors: Correct syntax, three implementation methods to return-tag requirement to this lesson matters.

Correct 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.

Why this lesson matters

Incorrect hreflang implementation, specifically due to syntax errors, can lead to a complete breakdown of your international SEO efforts, directly impacting revenue. Imagine a scenario where a UK-based e-commerce brand launches a new product line, localising content for France, Germany, and Spain. If the hreflang tags for the French version mistakenly use "en-FR" instead of "fr-FR", or if the return tags from the German page back to the UK page are missing, Google will simply ignore these signals. This means French users might see the English (UK) version, German users could be served the Spanish page, and Spanish users potentially receive no localised content at all, resulting in high bounce rates and lost conversions.

The financial implications are substantial. Each market represents a potential revenue stream, and misdirected traffic or non-localised experiences translate directly into missed sales opportunities. Furthermore, the lack of clear hreflang signals can cause internal duplication issues, where Google struggles to identify the canonical version for each locale, potentially splitting link equity and diluting ranking power across what should be distinct, targeted pages. This lesson ensures you can deploy hreflang with confidence, safeguarding your international rankings and revenue streams by avoiding these critical, yet often silent, syntax-based failures.

Common Hreflang Syntax Pitfalls and Diagnostics

Despite understanding the basic format, practitioners frequently encounter specific syntax pitfalls that invalidate their hreflang clusters. A common error involves using incorrect ISO 639-1 language codes or ISO 3166-1 alpha-2 region codes. For instance, using "en-UK" instead of the correct "en-GB" for Great Britain will render the tag useless. Similarly, including only a language code without a region when a region is implied or desired (e.g., "en" for a page specifically targeting the US market where "en-US" would be more appropriate) can lead to ambiguity that search engines may resolve unfavourably.

Another prevalent issue is malformed XML for sitemap implementations or incorrect HTML attribute syntax within the <head> section. Overlooking the exact quotation marks, forward slashes, or closing angle brackets can break the parsing of the entire tag cluster. Misuse of the `x-default` attribute, applying it incorrectly to a region-specific URL instead of the true fallback, also represents a syntax misstep that can confuse search engines about your primary or default target audience. These nuances demand meticulous attention to detail during implementation and thorough validation post-deployment.

To diagnose these:

Inspect the raw source code of the affected page, not just browser-rendered output.

Validate ISO codes against official lists; do not guess.

Check sitemap XML for correct `xhtml:link` structure and namespace declarations.

Utilise a live hreflang validator tool for immediate feedback on individual URLs.

Do it now

Immediately verify the hreflang implementation for your most critical international page. Select a localised page that targets a specific language and region, for instance, your French-Canadian product page, and systematically check its hreflang tags against the precise syntax rules discussed. This hands-on exercise will solidify your understanding and expose any live errors that could be impacting your site's international visibility. Leverage RankTracker's audit features to confirm correct parsing and identify discrepancies.

  • Choose one international URL with hreflang (e.g., a German product page).
  • Inspect its HTML source code for all hreflang tags, including the `x-default`.
  • Verify each `rel="alternate" hreflang="code" href="URL"` tag for exact syntax.
  • Use RankTracker's site audit to check for any reported hreflang issues on this page.
Video lecture · 15 min

Create a project, add keywords page by page, read positions, SERP features, share of voice and competitor gaps.

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

  1. 1Open RankTracker with sample data already loaded, so you are not stuck on setup.
  2. 2Track the keywords from this lesson.
  3. 3Use RankTracker's hreflang crawl view to list every hreflang cluster on your site and flag any without matching return tags.