TL;DR: Hreflang can be implemented 3 ways: HTML tags, XML sitemap, HTTP headers. Choose based on site size and CMS. Consistency critical.
3 Methods
1. HTML Tags (most common)
In head of each page:
<link rel="alternate" hreflang="en" href="https://example.com/" />
<link rel="alternate" hreflang="he" href="https://example.com/he/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />Pros: Simple, controllable per page.
Cons: Increases page size. Hard on very large sites.
2. XML Sitemap
In sitemap:
<url>
<loc>https://example.com/</loc>
<xhtml:link rel="alternate" hreflang="he" href="https://example.com/he/" />
</url>Pros: No HTML overhead. Easy for large sites.
Cons: Requires sitemap regeneration.
3. HTTP Headers
For non-HTML files (PDF, images):
Link: <https://example.com/file.pdf>; rel="alternate"; hreflang="en"Pros: Works for non-HTML.
Cons: Server configuration needed.
Language Codes
- ISO 639-1 for language: en, he, de, fr.
- ISO 3166-1 for country: US, GB, IL, DE.
- Format: language-COUNTRY (optional): en-US, he-IL.
- x-default for fallback.
Common Pitfalls
- Missing return links (A links to B, B doesn't link back).
- Wrong codes ("en-UK" invalid, use en-GB).
- Hreflang to non-existent URL.
- Hreflang on page with noindex.