About this tool
The hreflang attribute (introduced by Google in 2011, governed by RFC 5646) is the technical SEO standard for multilingual and multi-regional international websites. When delivering localized content across languages (e.g., English, Spanish, Chinese) or regional dialects (en-US vs en-GB), missing hreflang mappings causes Google to misinterpret regional mirrors as duplicate content and serve wrong languages to foreign users. This tool generates reciprocal hreflang tags with canonical x-default fallbacks compliant with Google Search Central guidelines.
How to Use This Tool (Step-by-Step)
Enter Localized URLs
Add your supported languages and input the corresponding absolute URLs for each localized version.
Assign ISO Language & Country Codes
Assign valid ISO 639-1 language codes (`en`, `zh`) and optional ISO 3166-1 alpha-2 region suffixes (`en-US`, `zh-TW`).
Configure x-default and Copy
Designate the default fallback URL (`x-default`), then copy the complete reciprocal `<link rel="alternate">` block directly.
Strict Google Reciprocal Compliance
Generates fully reciprocal bidirectional link sets including self-referencing links, preventing Google Search Console indexing rejections.
Automated x-default Fallback
Injects Google-recommended `x-default` attributes to route unmatched global traffic gracefully to your default international homepage.
100% Client-Side Privacy
Tag assembly computes entirely within local browser memory. Unpublished multi-region localization topologies remain 100% private.
Google hreflang Fatal Errors & Implementation Tips
- •Reciprocal linking is mandatory: If page A points to page B, page B MUST point back to page A. Missing return links causes Google to discard both tags.
- •Never use country codes alone: Writing `hreflang="uk"` or `cn` is invalid syntax. It must be `language` (`en`) or `language-country` (`en-GB`).
- •Always include self-referencing links: The Chinese page must list its own `zh` URL; the English page must include its own `en` URL.
Code & Transformation Examples
Standard Multilingual hreflang Head Block Benchmark
• 中文主站 : https://example.com/zh/tools/
• 英文全球站 : https://example.com/en/tools/
• 默认兜底页 : https://example.com/zh/tools/<link rel="alternate" hreflang="zh" href="https://example.com/zh/tools/" />
<link rel="alternate" hreflang="en" href="https://example.com/en/tools/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/zh/tools/" />* These exact lines must appear symmetrically inside the `<head>` of BOTH the Chinese and English pages.
Next.js Metadata alternates Language Configuration
export async function generateMetadata(): Promise<Metadata> {
return {
alternates: {
canonical: 'https://example.com/en/page',
languages: {
'zh': 'https://example.com/zh/page',
'en': 'https://example.com/en/page',
'x-default': 'https://example.com/en/page'
}
}
};
}Next.js 会在编译打包时自动把 languages 字典序列化为完全合规的 HTML link 标签。* Using the official `alternates.languages` object guarantees standard compliance without manual string concat errors.
Frequently Asked Questions
Q: What is `x-default` and why is it necessary?
A: `x-default` represents the fallback landing page for international users whose browser languages match none of your specific localized tags.
Q: Should hreflang go into HTML `<head>` or XML Sitemaps?
A: Google considers both equivalent. Placing tags in `<head>` is simple to audit for small/medium sites; embedding within XML sitemaps suits massive enterprise portals.
Q: Does hreflang protect against duplicate content penalties?
A: No. That is hreflang's primary purpose: It officially informs crawlers that localized copies are intended mirrors, completely eliminating duplicate content penalties.