How to Implement Hreflang Tags: A Step-by-Step Guide
Learn how to implement hreflang tags using HTML, XML sitemaps, or HTTP headers to properly map your localized content for search engines.
Learning how to implement hreflang tags comes down to mapping every localized version of a URL, including the current page, and deploying those reciprocal references across your site. Search engines use these annotations to serve the correct language or regional URL to searchers based on their location and browser settings. You can deploy them in your HTML <head>, your XML sitemap, or your HTTP response headers.
Which Implementation Method Should You Choose?
Google supports three ways to declare hreflang annotations. Each method accomplishes the same goal, but the best fit depends on your site size, tech stack, and file types.
| Method | Best For | Trade-offs |
|---|---|---|
HTML <link> tags |
Small to medium sites (under 500 pages) managed directly or through templates | Adds weight to page HTML; easy to edit by hand; risky on sites with dozens of languages |
| XML sitemaps | Large websites, enterprise e-commerce, sites with many locales | Zero added page weight; keeps code clean; harder to inspect without specialized tools |
| HTTP headers | Non-HTML documents like PDFs, downloadable assets, or headless APIs | Requires server configuration (Apache, Nginx, or CDN edge workers); less visible to casual auditing |
If you run a standard website with three or four language variations, generating a clean HTML block using the Links to Wild Hreflang Generator is usually the fastest route. If your catalog spans twenty countries and thousands of products, placing annotations into your XML sitemaps prevents page bloat and avoids page speed penalties.
Method 1: Generate Tags with the Links to Wild Tool
Generating tags manually leaves room for syntax mistakes, mismatched ISO language codes, and forgotten return tags. A generator solves this by producing the complete cluster at once.
- Gather the full, absolute URLs for every alternate version of the target page (for instance,
https://example.com/page,https://example.com/es/page, andhttps://example.com/fr/page). - Open the free Links to Wild Hreflang Generator in your browser. The tool runs entirely in your browser with no backend, meaning your URLs are never uploaded, logged, or saved.
- Paste each URL alongside its corresponding ISO 639-1 language code and optional ISO 3166-1 alpha-2 country code.
- Assign an
x-defaultURL to direct users whose language or region does not match any specified alternate. - Select your desired output format: HTML link tags, XML sitemap markup, or HTTP headers.
- Copy the generated reciprocal cluster and paste it into your page templates or sitemap files.
Method 2: Implement Hreflang in HTML Head with a Text Editor
For custom websites, static site generators, or simple template files, you can code the link elements directly into your global header template.
- Open the HTML template that controls the
<head>section of your pages in a code editor. - Create a
<link rel="alternate" hreflang="..." href="..." />tag for every regional and language variation of the page. - Include a self-referencing tag pointing to the current page URL itself. A Spanish page at
https://example.com/es/aboutmust contain anestag pointing directly tohttps://example.com/es/about. - Add the
x-defaulttag pointing to your fallback page or language selector screen. - Verify that the exact same group of tags is placed into the
<head>of every single page in the cluster. If page A links to page B, page B must link back to page A with identical tags. - Save and deploy your template, ensuring the tags render before the closing
</head>tag and not inside the<body>.
A typical three-language cluster looks like this:
<link rel="alternate" hreflang="en" href="https://example.com/about" />
<link rel="alternate" hreflang="es" href="https://example.com/es/about" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/about" />
<link rel="alternate" hreflang="x-default" href="https://example.com/about" />
Keep these tags alongside your canonical reference. Make sure the canonical tag on each localized page points to itself, not to the English original. You can review our guide on how to use canonical tags to see how canonicals and alternates interact.
Method 3: Configure Hreflang in Your CMS
Most content management systems automate tag injection through localization plugins or native settings. Here is how to handle the setup in common platforms.
- WordPress: Install an internationalization plugin such as WPML or Polylang. Navigate to the plugin settings, define your active languages, and map your translated posts to each other. The plugin automatically generates reciprocal tags in the
<head>of each post. - Shopify: If using Shopify Markets, language subfolders manage tags automatically. Check your theme layout file (usually
theme.liquid) to confirm that{{ content_for_header }}is present in the<head>, as Shopify injects alternate link tags through this variable. - Webflow: If using Webflow Localization, configure locales in Project Settings under the Localization tab. Webflow outputs the required hreflang tags automatically on published domains. If localizing manually with distinct projects, paste custom code blocks into the page-level Head Code settings.
- Publish your changes and inspect the live page source code using your browser to confirm the tags render with absolute HTTPS URLs.
Method 4: Implement Hreflang via XML Sitemaps
If your website serves dozens of countries, putting twenty or thirty tags inside the HTML of every page inflates document sizes. Sitemaps keep this overhead off the page entirely.
- Create or open your XML sitemap. If you are starting fresh, check our walkthrough on what an XML sitemap is and how sitemap protocols work.
- Add the XHTML namespace to your root
<urlset>tag:xmlns:xhtml="http://www.w3.org/1999/xhtml". - For every individual URL entry enclosed in
<url>tags, add a child<xhtml:link>element for every language version, including the URL itself and thex-defaultversion. - Repeat the full block for each alternate URL. If you have three localized versions, each of those three URLs will have its own
<url>entry containing three child<xhtml:link>elements. - Save the file and check its formatting with an XML Sitemap Validator to ensure there are no syntax or namespace errors before uploading.
- Upload the sitemap to your root directory and submit it directly through Google Search Console.
Here is how a single page entry appears inside the sitemap:
<url>
<loc>https://example.com/en/page</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/page"/>
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/page"/>
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/en/page"/>
</url>
Method 5: Add Hreflang via HTTP Response Headers
When you serve non-HTML files such as translated PDF user manuals, you cannot add <head> markup. You must send hreflang directives through the HTTP response headers.
- Access your server configuration file (such as
.htaccesson Apache ornginx.confon Nginx) or your CDN edge rules (such as Cloudflare Workers). - Define a
Linkheader rule matching the target file extension or directory path. - Format the header value with each URL wrapped in angle brackets, separated by commas, declaring
rel="alternate"and the correspondinghreflangcode. - Example Apache syntax:
<Files "guide-es.pdf">
Header add Link '<https://example.com/guide-en.pdf>; rel="alternate"; hreflang="en", <https://example.com/guide-es.pdf>; rel="alternate"; hreflang="es"'
</Files> - Restart or reload your web server software to apply the new headers.
- Check the response headers using a command-line
curl -Icheck to confirm theLinkheader returns on request.
Common Hreflang Mistakes and How to Check Your Work
Hreflang implementation errors prevent search engines from processing your international targeting instructions. Watch out for these four frequent issues.
1. Missing Return Tags
Hreflang tags are reciprocal contracts. If URL A points to URL B as its German counterpart, URL B must point back to URL A as its English counterpart. If URL B omits this return link, search engines ignore the annotation completely to prevent third parties from claiming arbitrary associations.
2. Invalid Language and Region Codes
The language code must follow ISO 639-1 (two letters, such as de for German, en for English). The optional country code follows ISO 3166-1 alpha-2 (such as GB for the United Kingdom, CA for Canada). A common mistake is using uk instead of gb for the United Kingdom, or using a country code alone without a preceding language code.
3. Canonical and Hreflang Conflicts
Every localized page must specify itself as its own canonical URL. If an alternate page has a canonical tag pointing back to the default language version, you send conflicting signals: the canonical tag claims the page is a duplicate, while the hreflang tag claims it is an alternate version. Check your pages using our Canonical Tag Checker to catch these conflicts before deploying.
4. Relative URLs Instead of Absolute URLs
Hreflang values must always be full, absolute URLs including protocol and subdomain (for example, https://example.com/fr/ rather than /fr/). Protocol mismatches (mixing HTTP and HTTPS) or trailing-slash inconsistencies will invalidate the tag cluster.
To inspect your setup, open your browser Developer Tools, visit the page, and review the rendered <head> elements. In Google Search Console, review the Page Indexing reports to see if search engines encounter issues crawling your localized pages. Official search guidelines maintained on Google for Developers clarify that hreflang annotations act as signals rather than strict directives, so crawl cleanliness is essential for reliable indexation.
Frequently Asked Questions
What is hreflang tags?
An hreflang tag is an HTML attribute specified inside a link element that informs search engines about the language and geographical targeting of a webpage. It enables search engines like Google to present the most suitable language version of your content to searchers according to their browser settings and location.
How to use hreflang tags for international SEO?
To use hreflang for international SEO, identify which language or regional markets need dedicated content. Create localized URLs for each audience, ensure each version provides distinct value (such as local currencies or localized spelling), and implement reciprocal link tags connecting every version in the set. Always include an x-default tag to capture searchers whose preferred language is not explicitly listed.
Do I need hreflang if my site is only in one language?
No. Hreflang exists to disambiguate between multiple versions of the same page. With only one version, there is nothing to disambiguate. Adding self-referencing hreflang tags to a monolingual site does nothing at all, neither good nor bad.
Is the region code required in hreflang?
No, and most sites should not use one. A tag using hreflang="es" serves every Spanish speaker worldwide. A tag using hreflang="es-MX" serves Spanish speakers located specifically in Mexico. You should only use a region code when you have distinct regional content, such as different pricing, shipping terms, or legal requirements, rather than simply because the content author was based in that country.
Why does Search Console report "no return tags"?
This happens when the page you pointed to fails to point back to the source URL. To diagnose it, load the destination URL and inspect its rendered HTML head. Common causes include publishing the hreflang block only on the primary language domain, having a trailing-slash mismatch between the two URLs, or relying on client-side JavaScript to render the tags after Googlebot has already parsed the initial response.