How to use the Hreflang Tag Generator
- 1Add one row per page version: a language code (en) or language-region code (en-GB) and its URL.
- 2Choose which URL should be x-default, the fallback for other users.
- 3Fix any invalid codes the tool highlights.
- 4Copy the link tags into every version of the page, or use the sitemap output instead.
What is a hreflang tag generator?
A hreflang tag generator writes the code that tells search engines which language or regional version of a page to show each user. This tool takes your list of language codes and URLs, adds an optional x-default fallback, checks every code, and outputs either HTML <link> tags for each page's <head> or an XML sitemap with the same information.
If your site has an English page and an Urdu page, or separate pages for the UK and Pakistan, hreflang helps Google send people to the right one.
How do hreflang tags work?
Each version of a page lists every version in the set, including itself:
<link rel="alternate" hreflang="en" href="https://example.com/" />
<link rel="alternate" hreflang="ur-PK" href="https://example.com/ur/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />
The hreflang value is a language code from ISO 639-1 (such as en, ur, ar), optionally followed by a region code from ISO 3166-1 alpha-2 (such as GB, PK, AE). Google explains the rules in its guide to localized versions of your pages.
Three rules cause most errors:
- Tags must be reciprocal. If page A lists page B, page B must list page A. Otherwise Google may ignore the pair.
- Region alone is invalid.
PKorUKon its own is wrong; it must beur-PKoren-GB. Note that the region code for the United Kingdom isGB, notUK. - URLs must be absolute and canonical. Each URL should return 200 and point to itself as canonical.
Which codes are valid?
| Code | Meaning | Valid? |
|---|---|---|
en | English, any region | Yes |
en-GB | English for the United Kingdom | Yes |
ur-PK | Urdu for Pakistan | Yes |
ar-AE | Arabic for the UAE | Yes |
zh-Hant | Chinese in Traditional script | Yes |
en-UK | Wrong region code | No |
PK | Region without language | No |
x-default | Fallback for everyone else | Yes |
The generator normalises what you type (for example EN_gb becomes en-GB) and flags codes that don't match the pattern.
Worked example
An e-commerce site sells in Pakistan in English and Urdu, and to the UAE in English. You enter:
| Code | URL |
|---|---|
| en-PK | https://shop.pk/ |
| ur-PK | https://shop.pk/ur/ |
| en-AE | https://shop.pk/ae/ |
and set x-default to https://shop.pk/. The HTML output has four link tags. Paste the same four tags into all three pages. In sitemap mode, the tool writes one <url> entry per page, each with all four xhtml:link alternates, which is the format Google accepts in sitemaps.
HTML tags or sitemap?
Both are equally valid for Google. Use HTML tags for a small site where you edit templates directly. Use the sitemap method for large sites or when you cannot edit the <head>. Don't mix methods for the same pages, as conflicting signals make errors harder to find. A third method, HTTP headers, is useful for PDFs.
Tips
- Use x-default for a language picker or your main international page.
- Translate the content properly. Hreflang doesn't make thin, machine-swapped pages rank.
- Keep URLs readable in each language with the Slug Generator, and encode non-Latin characters correctly with the URL Encoder & Decoder.
- Don't redirect by language automatically without a way to switch. If you must, plan redirects carefully with the .htaccess Redirect Generator.
- Bing relies more on the
content-languagemeta tag and thelangattribute on<html>, so set those too.
Limitations
The tool checks code format, not whether a language or region pair is meaningful, and it cannot visit your URLs to confirm they return 200, are canonical or link back to each other. Make sure your robots.txt doesn't block any of the versions, or search engines won't see the tags.
Frequently asked questions
What format do hreflang codes use?
An ISO 639-1 language code, optionally followed by an ISO 3166-1 alpha-2 region code, such as en, ur, en-GB or ur-PK. A region on its own is not valid.
Do hreflang tags need to be reciprocal?
Yes. Every page in the set must list all versions, including itself. If page A points to B but B does not point back, Google may ignore the tags.
What is x-default?
x-default marks the page to show users whose language does not match any listed version, often a language selector or the main English page.
Tags in HTML or in the sitemap?
Either works. Use one method consistently. Sitemaps are easier to manage on large sites.
Last updated: . Written and tested by Abdul Moid Khan, ATechCraft. Read how we build and test tools.