Hreflang Tag Generator

Hreflang tags for every language and country version of a page, with error checks.

  • SEO Tools
  • Free, no sign-up
  • Runs in your browser

Hreflang Tag Generator tool

Versions of the page
    
        

    About the Hreflang Tag Generator

    Sites with versions of a page in different languages or for different countries need hreflang annotations, so search engines show visitors the right version. This hreflang tag generator takes a row for each version, such as English for the United Kingdom, English for the United States and Urdu for Pakistan, with its URL, adds an x-default fallback and outputs the annotations as link tags, sitemap XML or HTTP headers. Every version must list all the others, including itself, which the tool handles automatically. Mistakes in hreflang are common and silent, so check the output carefully. For canonical tags, use the Canonical Tag Generator, and for sitemaps, the XML Sitemap Generator.

    Choose the output that fits your site: link tags for the head of each page, XML entries for your sitemap with every alternate listed under each URL, or HTTP Link headers for PDFs and other files that have no HTML head. Every version must list all the others and itself, and the generator does that for you, so the annotations are always reciprocal.

    Built-in checks catch the mistakes that most often break hreflang: invalid codes such as en-UK instead of en-GB, uk used for the United Kingdom when it means Ukrainian, duplicate language codes, relative or malformed URLs and a missing x-default. Everything runs in your browser and nothing is uploaded.

    To declare the preferred URL of each page, also use the canonical tag generator. For your sitemap file itself, try the sitemap generator, and for page titles and descriptions, the meta tag generator.

    How to use the Hreflang Tag Generator

    1. Add each versionFor every language or country version, choose the code and enter its full URL. Add rows as needed.
    2. Set the fallbackEnter the x-default URL, usually your language selector or main version.
    3. Pick the formatChoose link tags, sitemap XML or HTTP headers.
    4. Fix any warnings and copyRead the checks, correct any problems, then copy the output.

    Hreflang Tag Generator features

    • Link tags, sitemap XML or HTTP Link headers
    • Reciprocal annotations generated automatically
    • x-default fallback
    • Common language and region codes, or your own
    • Catches en-UK, uk and other common code mistakes
    • Flags duplicates and relative URLs
    • Copy or download the result
    • Nothing is uploaded

    Common uses

    • Launching a site in several languages
    • Separating US, UK and Australian English pages
    • Fixing hreflang errors reported by SEO tools
    • Adding hreflang to sitemaps of large sites
    • Annotating PDFs with HTTP headers

    Hreflang in practice: English and Urdu versions of a site, the pk mistake, regional English for Gulf audiences, canonicals and language redirects

    By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

    Hreflang tags tell search engines which language or regional version of a page to show each searcher. For Pakistani sites publishing in English and Urdu, or businesses serving customers at home and in the Gulf, they prevent the wrong version from appearing and stop language versions being treated as duplicates. This guide sets up English and Urdu versions and covers common code mistakes, regional variants, canonical tags, automatic redirects and translation quality.

    A worked example: English and Urdu pages

    A university publishes its admissions page in English at /en/admissions/ and in Urdu at /ur/admissions/. Each page lists both versions: hreflang="en" for the English address and hreflang="ur" for the Urdu address, plus hreflang="x-default" pointing to the English page for everyone else. Searchers using Urdu settings or searching in Urdu are shown the Urdu page, while others see the English one.

    The pk mistake

    A common error uses hreflang="pk" to mean Pakistan. Hreflang codes start with a language, so pk is invalid and ignored. Urdu is ur, and a Pakistan-specific version can be written as ur-PK or en-PK, language first and country second. Since Urdu is also read in India and elsewhere, plain ur suits Urdu content meant for all Urdu readers.

    Regional English for Gulf audiences

    A Pakistani business serving customers in Pakistan and the United Arab Emirates might publish en-PK pages with prices in rupees and local delivery details, and en-AE pages with prices in dirhams and UAE contact numbers. Hreflang helps search engines show each region its own version. The versions should genuinely differ; identical pages with different codes add little.

    Canonical tags and hreflang

    Each language version should have a canonical tag pointing to itself. Pointing the Urdu page's canonical at the English page tells search engines to ignore the Urdu version entirely, which defeats the purpose. Canonicals choose between duplicates; hreflang connects equivalents.

    Avoid forced redirects

    Automatically redirecting visitors by location or browser language can trap people who want another version, such as an English reader in Lahore or an Urdu reader abroad, and can stop search engines crawling all versions, since their crawlers mostly visit from abroad. A visible language switcher, with a suggestion banner if needed, works better.

    Quality of translations

    Unedited machine translations often read awkwardly and may be treated as low-quality content produced at scale. Translations reviewed by fluent speakers, with local examples and correct terminology, serve readers properly and make the language versions worth showing.

    Tags or sitemap

    Hreflang can be placed in each page's head or listed in the sitemap. Large sites often prefer sitemaps, which keep all relationships in one file. Whichever method you choose, use it consistently, and make sure the addresses listed are the canonical, indexable versions.

    Checking the setup

    Search engines no longer provide a dedicated report for international targeting, so checks rely on crawling tools and manual inspection. Confirm that every version lists every other version, that codes are valid and that no listed address redirects or returns an error.

    Common mistakes

    • Using country codes such as pk as language codes.
    • Canonicalising translations to the original language.
    • Redirecting visitors by location without a choice.
    • Publishing unreviewed machine translations.

    Related tools

    To set the preferred address of each version, use Canonical Tag Generator. To list language versions in a sitemap, try XML Sitemap Generator, and for the rest of the head tags, Meta Tag Generator.

    Only link pages that exist

    If only some pages are translated, add hreflang only to those pages and their real equivalents. Pointing an untranslated English page's Urdu alternate at the Urdu home page sends searchers to the wrong content. Partial coverage is fine, as long as every link connects genuinely equivalent pages.

    Language switchers

    A language switcher should take visitors to the equivalent page in the other language, not to the other language's home page. Visitors reading about fees in English who switch to Urdu expect the Urdu fees page. Matching switcher links with hreflang pairs keeps navigation and search signals consistent.

    Urdu page addresses

    Urdu pages can use Urdu words in their addresses, which appear as long percent-encoded strings when shared, or transliterated English slugs, which are shorter and easier to share. Either works for search engines. Choose one approach for the whole site and keep equivalent pages' addresses parallel where possible.

    The lang attribute should agree

    Each page's html lang attribute should match its hreflang code, such as ur on the Urdu page and en on the English page. A mismatch, often caused by templates copied from the English site, sends confusing signals to browsers, screen readers and search engines.

    Pages mixing languages

    Pages that mix English and Urdu substantially, such as bilingual notices, do not fit neatly into hreflang, which assumes one language per page. Choose the dominant language for the lang attribute, or split the content into separate language versions if both audiences matter equally.

    Privacy

    Tags are generated in your browser. Nothing you enter is sent anywhere or stored.

    Frequently asked questions

    What is hreflang?

    Hreflang is an annotation that tells search engines a page has versions in other languages or for other countries. Google uses it to show the right version, for example the UK page to searchers in Britain and the US page to searchers in America.

    What is the correct hreflang code for the United Kingdom?

    en-GB. The country code for the United Kingdom is GB, not UK, so en-UK is invalid and ignored. Also note that uk on its own means Ukrainian. The checks in this tool flag both mistakes.

    What does x-default mean?

    x-default marks the page to show when no other version matches the visitor's language or region. It is usually a language selector page or your main international version, and it is recommended for every set of hreflang annotations.

    Do pages need to link back to each other?

    Yes. Hreflang must be reciprocal: if page A lists page B, page B must also list page A, and each page should list itself. Otherwise search engines may ignore the annotations. The generated output includes every version on every page.

    Should I use link tags or the sitemap?

    Both work equally well; use whichever is easier to maintain. Link tags suit small sites, sitemap entries suit large sites because they keep the HTML lean, and HTTP headers are for non-HTML files like PDFs. Do not mix methods for the same pages.

    Can I target a country without a language?

    No. Hreflang always starts with a language code, optionally followed by a region, such as es-MX. A region code on its own, like MX, is invalid. Choose the language spoken by the audience in that country.

    Is my data uploaded?

    No. The tags are generated in this page on your device. Your URLs are not sent anywhere or stored. It is safe to use for client work and unpublished projects.