Free audit with a recorded video walkthrough in 3 business days Plans and prices published for every service You own every account, dashboard and line of code Senior-led, with hours that overlap the full US business day

Free tool

Hreflang Generator: Head Tags, XML Sitemap Entries and Headers

Enter the language, optional region and URL of each version of a page, and get hreflang tags, sitemap entries and an HTTP header with error checks.

This hreflang generator turns a list of language and region versions of one page into ready-to-paste hreflang tags, XML sitemap entries and an HTTP Link header, and flags errors such as UK instead of GB or a missing x-default. Each value is an ISO 639-1 language code, optionally joined to an ISO 3166-1 country code (en-GB), and every version must carry the full set, including a line that points to itself.

US-registered LLC Free audit with video walkthrough No long lock-ins Flexible ways to pay
On this page
  1. How to Use the Hreflang Generator
  2. Hreflang Tag Generator Output: A Worked Example
  3. What Hreflang Does, and What It Does Not Do
  4. Hreflang Language and Country Codes
  5. Head Tags, XML Sitemap or HTTP Header: Choosing a Method
  6. Does Every Page Need Hreflang?
  7. Do You Need a Country Code in Hreflang?
  8. Choosing an x-default Page
  9. Hreflang and Canonical Tags Together
  10. Hreflang Mistakes the Generator Cannot See
  11. How to Check Hreflang After Launch
  12. Get Hreflang Right Across a Whole Site

A hreflang generator saves you from hand-typing the tags that tell Google which language or country version of a page to show each searcher. List every version of one page, for example your US, UK and Spanish URLs, and this tool writes the hreflang tags for the <head>, the matching XML sitemap entries and an HTTP Link header. It also checks your input for the mistakes that make search engines ignore hreflang, and it runs entirely in your browser, so the URLs you enter are not sent anywhere.

Add one row for every language or country version of the same page. Use full URLs including https.

    HTML tags for every version's <head>

    XML sitemap entries

    HTTP header (for PDFs and other files)

    
    

    How to Use the Hreflang Generator

    Work on one page at a time, with one row for each version of that page. The tool opens with three example rows (US English, UK English and Spanish) that you can edit or remove.

    • Language: the two-letter ISO 639-1 code for the language the page is written in, such as en, es, fr, de or ar. The dropdown covers 36 widely used languages.
    • Region (optional): a two-letter ISO 3166-1 country code, added only when that version is meant for one country, such as US, GB, CA, AU or AE. The tool converts it to uppercase and joins it to the language, so en plus GB becomes en-GB.
    • URL: the full address of that version, starting with https://. Use the canonical URL: the one that returns a 200 status, is indexable and is not redirected.
    • Add a version and Remove: add a row for each extra language or market, and remove the rows you do not need.
    • x-default URL (optional): the page for searchers whose language or country matches none of your versions, often a language selector or your main international page.

    The output updates as you type, in three blocks:

    • HTML tags for every version's <head>: one link element per version, plus x-default if you set one. The whole block goes on every version, including the line that points to the page itself. Copy HTML copies it in one click.
    • XML sitemap entries: one <url> entry per version, each listing all the alternates as xhtml:link elements. The output ends with a reminder to add the xhtml namespace to your <urlset> tag, and Copy XML copies the block.
    • HTTP header: a single Link header that lists every version, for PDFs and other files that have no <head>.

    Above the code, the warnings list flags six problems: a region that is not two letters, UK used instead of GB, a URL that does not start with http:// or https://, the same language and region pair listed twice, no x-default, and fewer than two versions. When the set is clean, the tool says so and reminds you that every version needs the full set of tags.

    Hreflang Tag Generator Output: A Worked Example

    Here is a made-up store with three versions of its returns policy. The URLs are examples, not a real site.

    VersionLanguageRegionURL
    US EnglishenUShttps://example.com/returns/
    UK EnglishenGBhttps://example.com/uk/returns/
    Spanish, all countrieses(none)https://example.com/es/devoluciones/
    Fallbackx-default(none)https://example.com/returns/

    The hreflang tag generator writes four lines:

    <link rel="alternate" hreflang="en-US" href="https://example.com/returns/" />
    <link rel="alternate" hreflang="en-GB" href="https://example.com/uk/returns/" />
    <link rel="alternate" hreflang="es" href="https://example.com/es/devoluciones/" />
    <link rel="alternate" hreflang="x-default" href="https://example.com/returns/" />

    All four lines go into the <head> of all three pages. The US page lists itself as en-US, the UK page lists itself as en-GB, and each one points to the others. Google calls these return links: if the UK page points to the US page but the US page does not point back, Google may ignore the pair. Using the US page as x-default is common when it is the main version, and it is fine for one URL to appear twice in the set like this.

    The Spanish version has no region because it serves Spanish speakers everywhere. If you later launch a Mexico-specific page, add es-MX and keep the plain es version as the catch-all for Spanish speakers in other countries.

    What Hreflang Does, and What It Does Not Do

    Hreflang tells search engines that several URLs are the same content for different languages or regions, so the engine can show the version that fits each searcher. Without it, Google has to guess whether /uk/returns/ and /returns/ are duplicates, and it may show the US page, with US prices and shipping terms, to a shopper in London.

    Hreflang is a signal, not a command. Google uses it when the annotations are consistent and confirmed from both sides, and it can still pick another version if other signals conflict. It does not raise rankings by itself: it decides which of your versions appears, not whether your site ranks. It also does not make thin, machine-translated pages useful, and it does not replace a canonical tag.

    Hreflang Language and Country Codes

    Every hreflang value starts with a language code, and the country is optional. Getting the format wrong is one of the most common reasons tags are ignored.

    ValueFormatUse it when
    enLanguage only (ISO 639-1)One version serves speakers of that language in every country
    en-GBLanguage plus country (ISO 3166-1 alpha-2)The version is built for one country: currency, shipping, spelling, legal terms or stock differ
    x-defaultReserved valueA fallback page for anyone your other versions do not match

    A few rules catch people out. A country on its own, such as hreflang="GB", is invalid, because the language must come first. The United Kingdom is GB, not UK, which is why the tool warns about UK. Codes are not case-sensitive, but a lowercase language and an uppercase country keep them readable. For Chinese, this tool can produce zh-CN, zh-TW or zh-HK. Script codes such as zh-Hans and zh-Hant are also valid, but the region field accepts two letters only, so add those by hand.

    Head Tags, XML Sitemap or HTTP Header: Choosing a Method

    Google documents all three methods as ways to send the same information, so pick the one your site can keep accurate. That is why the tool gives you all three.

    MethodBest forWatch out for
    HTML link tags in the <head>Small and medium sites, and platforms that output the tags from a templateEvery language you add lengthens the head of every page, and one template bug breaks the whole set
    XML sitemap entriesLarge sites, many languages, or teams that cannot edit page templatesEach sitemap file is limited to 50,000 URLs and 50 MB uncompressed, and it must be regenerated when URLs change
    HTTP Link headerPDFs, spreadsheets and other non-HTML filesNeeds server or CDN configuration, and is harder to audit by eye

    Use one method per set of pages where you can. Two methods that disagree, for example head tags from a plugin and an older sitemap with different URLs, send mixed signals. If you use the generator as a hreflang sitemap generator, submit the sitemap in Google Search Console so you can see whether it is read without errors.

    Does Every Page Need Hreflang?

    No, only pages that have an equivalent in another language or region need hreflang, but every page in that group needs the complete set. A US-only blog post with no UK or Spanish version needs no hreflang at all. A product page sold in three markets needs the same block of tags on all three versions.

    In practice, templates do this work. On most sites hreflang is generated from a translation table or a market setting rather than written page by page. Use this generator to work out the correct pattern for one page, then check that your platform produces the same pattern everywhere.

    Do You Need a Country Code in Hreflang?

    A country code is optional: add one only when the content really changes by country. If your English pages are the same for every English speaker, a single en version is cleaner than en-US, en-GB, en-CA and en-AU all pointing at near-identical pages.

    Add regions when prices, currency, delivery terms, product range, spelling or regulations differ. A store selling in USD to the US and in GBP to the UK has a real reason for en-US and en-GB. If you add regional English versions, consider a plain en version as well, so English speakers in countries you have not listed still land on an English page.

    Choosing an x-default Page

    x-default tells search engines which page to show when no other version matches the searcher's language or location. It is optional, which is why the tool shows a missing x-default as a warning rather than an error, but most international sites benefit from one.

    Good x-default choices are a language or country selector page, or your main version if most traffic comes from one market. Do not point x-default at a page that redirects visitors based on their IP address, because crawlers may never see the versions behind the redirect.

    Hreflang and Canonical Tags Together

    Each version should have a canonical tag that points to itself, and the URLs in your hreflang tags must match those canonical URLs exactly. If the UK page has a canonical pointing to the US page, you are telling Google the UK page is a duplicate to drop, which contradicts the hreflang that says it is an alternate to show.

    Exact means exact: the same protocol, the same www or non-www host, the same trailing slash and no tracking parameters. A hreflang link to http://example.com/uk/returns when the canonical is https://example.com/uk/returns/ points at a URL that redirects, and the pair can be ignored.

    Hreflang Mistakes the Generator Cannot See

    The generator checks the codes and URLs you type. It does not crawl your site, so these problems need a separate check:

    • Missing return links on live pages. The tags were right in the tool, but only one version was updated, so the other versions do not point back.
    • Alternate URLs that redirect, return 404 or carry noindex. Hreflang should only point at live, indexable pages.
    • Automatic redirects by IP or browser language. Google documents that Googlebot crawls mostly from US IP addresses, so forced redirects can hide your other versions from it. Suggest the right version with a banner instead.
    • Pages that are not really translated. A UK page that only swaps the currency symbol, or a Spanish page with an English body and a translated menu, gives hreflang little to work with.
    • Wrong codes set in a CMS. Values such as en-uk, en_GB or eng usually come from plugin or market settings rather than from the people writing the tags.
    • Hreflang on filtered and parameter URLs. Keep hreflang to canonical pages, not every sort or filter combination.

    How to Check Hreflang After Launch

    Check a sample of pages by viewing the source and confirming the full set appears on each version, including the self-referencing line. A crawler such as Screaming Frog SEO Spider can extract hreflang across a whole site and report missing return links, non-canonical targets and invalid codes. In Google Search Console, the URL Inspection tool shows which canonical Google selected for a page, which tells you whether Google treats your versions as alternates or folds them together.

    On Shopify, hreflang tags are added automatically when you publish extra languages or set up market-specific domains or subfolders with Shopify Markets, so check the existing output before adding a second set by hand. On WordPress, multilingual plugins such as WPML and Polylang output hreflang, and the usual problems are mismatched canonical URLs and partly translated pages. On a custom build, generate the tags from one table of page equivalents so they cannot drift apart.

    Get Hreflang Right Across a Whole Site

    Tags for one page are easy. Keeping hundreds or thousands of pages consistent across markets, through redesigns, new products and platform changes, is where international SEO usually breaks. Our technical SEO services cover hreflang audits, template and sitemap fixes, canonical conflicts and redirect rules, and our SEO migration work covers moving to new domains or subfolders without losing regional rankings. If you want us to check what you have now, request a free audit.

    Planning content for each market? Group your target terms with the keyword clustering tool, check what each one needs with the search intent tool, or browse all our free marketing tools.

    Hreflang Generator questions

    How do you use a hreflang tag generator?
    Add one row for each version of the same page, choose its language, add a country only if that version targets one country, and enter the full URL. Add an x-default fallback if you have one. The generator then writes head tags, sitemap entries and an HTTP header. Paste the same full block on every version, including the line that points to the page itself, and keep each URL identical to that page's canonical URL.
    Is it necessary to include an x-default hreflang?
    No, x-default is optional, but it helps on most international sites. It tells search engines which page to show people whose language or country matches none of your versions. A language selector page or your main version both work. Avoid pointing it at a page that automatically redirects by location, because crawlers may never reach the versions behind it.
    Where should hreflang tags go?
    Put them in the head section of each page as link elements, in your XML sitemap as xhtml:link entries, or in an HTTP Link header for files such as PDFs. Any one of the three works. Choose the method your platform can keep accurate, and avoid running two methods that list different URLs for the same pages.
    Does hreflang improve SEO rankings?
    Not directly. Hreflang decides which of your versions Google shows each searcher; it does not make a page rank higher. The benefit is indirect: visitors land on the page with their language, currency and shipping terms, which tends to keep them on the site, and your regional pages stop looking like duplicates that compete with each other.
    Can hreflang point to pages on a different domain?
    Yes. Hreflang works across domains, so example.com can list example.co.uk and example.de as alternates. The rules are the same as on one domain: each version must list all the others and itself, and every URL must be the canonical, indexable version. Cross-domain sets are common for brands that run a separate domain for each country.
    What happens if hreflang return links are missing?
    Google may ignore the hreflang annotations for that pair of pages. Return links confirm that both pages agree they are alternates, which stops one site from claiming another site's pages as its own versions. If page A lists page B but page B does not list page A, fix the template or sitemap so every version carries the full set.

    Next step

    Tell us what you want to grow

    Send a few details and a senior strategist replies within one business day with honest next steps, even if we are not the right fit.

    • Free audit with a recorded video walkthrough
    • Fixed scope and published pricing
    • No long lock-ins: 3-month minimum on most retainers
    • You own every account, file and line of code

    We only use your details to reply. See our privacy policy.