How to Add hreflang Tags to a Multilingual Website (HTML, WordPress, and Sitemap Methods)
In short: hreflang tags tell Google which language or regional version of a page to show each searcher. You add them in one of three places: <link> elements in the page <head>, an HTTP Link header, or your sitemap. That sitemap is the XML (Extensible Markup Language) file listing your URLs for search engines. Every version must list itself and all its alternates, with absolute URLs, valid codes from the International Organization for Standardization (ISO) and an x-default fallback. Most broken setups fail on the same three points: missing return links, wrong codes, and canonical tags that contradict the cluster. For any multilingual website, that’s the core of international SEO. This guide shows all three methods with copy-ready code for an English page, a French page and an x-default fallback. It also covers WordPress and a Node.js Express app, then walks through the mistakes that make Google quietly ignore your markup. An in-depth look at it is worth the time. What hreflang tags actually do (and what they don’t) The hreflang attribute is a piece of HTML code that declares the language, and optionally the country, a page is written for. It sits on a <link rel=”alternate”> element, so it connects one web page to each alternate version in a different language or for a different country. Search engines read it; visitors never see it. That answers the common question “what is hreflang in HTML?”: it’s a machine-readable map of your page’s language versions and their geographical targeting. The mechanism is easier to grasp in three steps. First, Google decides that one of your URLs deserves a spot in the results, using its usual ranking signals. Next, it checks whether that URL belongs to a hreflang cluster, meaning a group of pages that all point to each other. Finally, just before showing the result, it swaps in the version that best matches the searcher’s language settings and location. Hreflang works on that last step, the swap, and nothing else: the hreflang annotation is how you tell Google which version belongs to which language preference. Three consequences follow, and they clear up most of the confusion around the topic: It’s a hint, not a directive. Google can ignore a cluster, especially when the tags contradict each other or the pages are near-identical. It isn’t a ranking factor. Your French page won’t rank higher because it has hreflang. It will simply be the page French users see, instead of the English one. It doesn’t detect language. Google’s documentation states that it uses its own algorithms to work out a page’s language, not hreflang or the HTML lang attribute. A badly translated page stays a badly translated page. Hreflang also helps with a classic duplicate content issue between regional versions. Two English pages for the United States (US) and the United Kingdom (UK), differing only by spelling and currency, look like copies. The annotation tells Google they’re deliberate alternates for different audiences, so it can show each one in the right country rather than picking one and filtering the other. Search engine support varies. Google and Yandex read hreflang. Bing has historically leaned on other signals, such as the content-language meta tag and country-code domains. A site that cares about Bing traffic should therefore set its language declarations correctly too. Do you need hreflang tags? A quick decision table Hreflang only makes sense when you have equivalent content in multiple languages or for more than one region. Creating that content is the real work; the markup comes after. The table below matches common situations to a recommendation. Your situation Do this Avoid One language, one market No hreflang. Set <html lang=”en”> and move on. Adding a lone self-referencing tag “just in case” Full translations (English + French) Language-only codes: en, fr, plus x-default Adding country codes you don’t actually target Same language, several countries (US, UK, Australia) Language-region codes: en-US, en-GB, en-AU, plus a generic en Identical pages with no local difference (prices, spelling, shipping) Same country, several languages (Canada, Belgium, Switzerland) en-CA and fr-CA, or nl-BE and fr-BE One URL that switches language with a cookie Only the menus are translated Translate the main content first Pointing hreflang at pages that aren’t really equivalent PDFs or other files in several languages HTTP Link header Leaving downloads out of the cluster Machine translation deserves a word of caution. The markup itself works on any page, but sending French searchers to a raw automatic translation hurts the user experience hreflang is supposed to improve. In our view, a short human review of each translated page matters more than the tags. Anatomy of a tag: language codes, region codes and x-default Every hreflang tag has three parts, and the syntax never changes. Here’s the English version of a page declaring itself: <link rel=”alternate” hreflang=”en” href=”https://example.com/en/pricing/” /> rel=”alternate” says the linked URL is another version of the same content. hreflang=”en” gives the audience: a language code, optionally followed by a region code. href gives the full, absolute URL of that version, including https://. Language and region codes The language part uses two-letter codes in ISO 639-1 format: en, fr, de, ja. The optional region part uses ISO 3166-1 Alpha 2 country codes, separated by a hyphen: fr-CA means French for Canada. Google’s documentation names both standards explicitly. Together they form a tag in the BCP 47 format (Best Current Practice 47), the standard for language tags published by the Internet Engineering Task Force (IETF). BCP 47 tags are case-insensitive, so en-gb and en-GB are equivalent. Lowercase language and uppercase region is simply the usual convention. These codes are the whole of your regional targeting, so a typo sends the wrong signal. Four rules catch most code errors: A region never stands alone. hreflang=”US” is invalid; use en-US. Country and language codes differ. The United Kingdom is GB, so en-UK is wrong. Greek is el, while Greece is GR. Use a hyphen, not an underscore. en_US comes from software locales and isn’t valid here. No made-up









