Skip to the content
Start free

HTML lang attribute

The HTML lang attribute is a short code in a page’s HTML, such as lang=”en-GB”, that tells browsers, screen readers and other software which human language the text is written in. It usually sits on the opening <html> tag and covers the whole page. You can also put it on a single element when one phrase is in another language.

What is the lang attribute? #

It is a global attribute, so any HTML element can carry it. MDN says it holds a single BCP 47 language tag. That is the same family of codes you see in many places on the web: en for English, fr for French, en-GB for British English, zh-Hans for Chinese in simplified script.

A typical page starts like this:

<!DOCTYPE html>
<html lang="en-GB">
<head>...

Elements with no lang of their own inherit it from their parent. If nothing on the page or in the server’s Content-Language header gives a language, MDN says the language is unknown. MDN recommends always setting a value.

Why does it matter for people? #

The main job is accessibility. The W3C’s guide to WCAG success criterion 3.1.1, Language of Page, a Level A rule, says the default language of each page must be programmatically determined. When it is, screen readers can load the right pronunciation rules, browsers can show characters and scripts correctly, and media players can show captions correctly. A screen reader set to English that meets a Welsh page with no lang tag will read the Welsh with English sounds, which is hard to follow.

It also changes how the page looks. MDN’s page on the CSS hyphens property says automatic hyphenation depends on the language being properly tagged, and browsers only hyphenate when the tag is present and they have a dictionary for it. That matters for responsive pages, where long words on a phone screen can break the layout.

No, not to decide the language. Google’s guide to multi-regional and multilingual sites says it uses the visible content of a page to work out its language, and does not use code-level information such as lang attributes or the URL. Its localised versions guide repeats the point: Google does not use hreflang or the HTML lang attribute to detect page language.

So a correct lang tag will not lift your rankings in Google. A wrong one will not make Google think your English page is German either. The words on the page decide that. Other search engines and tools may read the tag, so it is still worth getting right, and it is one of the cheap basics of technical SEO.

What about AI answers? #

AI crawlers and live fetchers turn your page into text before a model reads it. The lang tag is one of the few plain, machine-readable statements about who the page is for. We have seen no AI company document that it uses the tag, so we do not claim it helps you get cited. What it does is remove a doubt: a page that says en-GB, writes “colour” and quotes prices in pounds sends one clear signal. For more on how machines read pages, see AI crawlability and technical SEO for AI search.

How is lang different from hreflang? #

lang attribute hreflang
What it says “This text is in this language” “Here are the other language or country versions of this page”
Where it lives On the html tag or any element In link tags, HTTP headers or the XML sitemap
Main reader Browsers and assistive technology Search engines choosing which version to show
Code rules BCP 47 Google supports ISO 639-1 language codes plus optional ISO 3166-1 Alpha 2 regions

A site with several language versions needs both. The lang tag describes each page; hreflang links the set together. Our international SEO and multilingual SEO pages explain the wider plan, and localisation covers the words themselves.

How do I choose the right code? #

The W3C article on choosing language tags gives a golden rule: keep the tag as short as possible. Add a region only when it tells readers something they need. Its example: en-GB can help spell-checking, while ja-JP is usually not needed. By convention the language part is lower case and the region upper case.

For a UK business writing in British English, en-GB is a sensible choice. Note it is GB, not UK. Google’s localised versions guide warns that UK is not a valid region code in hreflang, and the same ISO list sits behind the region part of a lang tag.

How do I mark a phrase in another language? #

Wrap it in an element with its own lang. The W3C guide to declaring language in HTML suggests a span where no other element fits:

<p>Our café sign reads <span lang="cy">Croeso</span>.</p>

WCAG calls this Language of Parts (3.1.2, Level AA). The same W3C guide says to put the language on the html element rather than the body, because the body does not cover the head. It also says not to use a meta tag with http-equiv Content-Language, and that the in-page declaration overrides the HTTP header. For right-to-left languages such as Arabic or Hebrew, add the dir attribute as well.

Common mistakes #

  • No lang at all. Many themes and page builders leave it out, or a headless front end drops it.
  • The wrong language. A template copied from a US site that says en-US on British pages, or a translated page that still says en.
  • Invalid codes. en-UK, english or en_GB with an underscore. MDN says an invalid tag sets the language to invalid.
  • An empty value. lang="" means unknown.
  • Machine-translated pages with one tag. A French copy served with the English tag misleads screen readers on every line.
  • Expecting a ranking lift. Google does not use it to set language, so fix it for people first.

A worked example #

A UK shop sells in English and adds a Welsh version under /cy/.

Page Before After
Home page <html> <html lang="en-GB">
Welsh home page <html lang="en-GB"> (copied template) <html lang="cy">
Delivery page with a Welsh phrase Phrase read with English sounds Phrase wrapped in <span lang="cy">
Both versions No link between them hreflang en-GB and cy on each page

The Welsh page now reads correctly in a screen reader, and Google has a clear map of which version to show.

How to check it #

  1. View the page source and look at the first html tag. Or paste the page into our Meta Tag Checker and SEO Checker, which read the head of the page.
  2. For a site with language versions, run our Hreflang Checker to see that each version points to the others with valid codes.
  3. Check the Content-Language header with our HTTP Header Checker. If it disagrees with the page, fix the page first.
  4. Test with a screen reader on a short page in each language.
  5. Run a wider SEO audit to find templates that leave the tag out across many pages, and check how readable the text is with our Readability Checker.
  6. In URSY Pro, the Hreflang audit (Pro) and Site audit (Pro) will track this across the whole site.

Questions #

Is lang required? #

HTML pages work without it, but WCAG Level A needs the page language to be programmatically set, and the lang attribute is the usual way to do it.

en or en-GB? #

Both are valid. Use en-GB if British spelling matters to your readers, which it often does for UK firms.

Does it affect which country I rank in? #

Not in Google. Country targeting comes from things like hreflang, a country code domain and the content itself.

Should every element carry it? #

No. Set it once on the html tag and only add it again where the language changes.

Sources #

Updated 25 November 2026 by URSY.

Cite this page: HTML lang attribute. URSY. Updated 25 November 2026. https://ursy.com/wiki/html-lang-attribute/ · Section links

Tools for this

All 871 wiki entries, A to Z →