# Hreflang Tag Generator

> The Hreflang Tag Generator turns a list of language or language-region codes and URLs into hreflang link tags and an equivalent XML sitemap block, adds x-default, and flags invalid codes.

URL: https://atechcraft.com/hreflang-generator/
Category: SEO Tools
Last updated: 2026-12-01
Author: Abdul Moid Khan, ATechCraft

Runs in your browser. Your data never leaves your device.

## How to use the Hreflang Tag Generator

1. Add one row per page version: a language code (en) or language-region code (en-GB) and its URL.
2. Choose which URL should be x-default, the fallback for other users.
3. Fix any invalid codes the tool highlights.
4. Copy 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:

```html
<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](https://developers.google.com/search/docs/specialty/international/localized-versions).

Three rules cause most errors:

1. **Tags must be reciprocal.** If page A lists page B, page B must list page A. Otherwise Google may ignore the pair.
2. **Region alone is invalid.** `PK` or `UK` on its own is wrong; it must be `ur-PK` or `en-GB`. Note that the region code for the United Kingdom is `GB`, not `UK`.
3. **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](https://atechcraft.com/sitemap-generator/).

## 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

1. **Use x-default** for a language picker or your main international page.
2. **Translate the content properly.** Hreflang doesn't make thin, machine-swapped pages rank.
3. **Keep URLs readable** in each language with the [Slug Generator](https://atechcraft.com/slug-generator/), and encode non-Latin characters correctly with the [URL Encoder & Decoder](https://atechcraft.com/url-encoder-decoder/).
4. **Don't redirect by language automatically** without a way to switch. If you must, plan redirects carefully with the [.htaccess Redirect Generator](https://atechcraft.com/htaccess-redirect-generator/).
5. **Bing relies more on** the `content-language` meta tag and the `lang` attribute 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](https://atechcraft.com/robots-txt-generator/) 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.
