Skip to main content

"<html> element must have a lang attribute": how to tell browsers what language your site is in

Published

“<html> element must have a lang attribute” is the error you’ll see in axe. Lighthouse calls it “<html> element does not have a [lang] attribute”, WAVE calls it “Language missing or invalid”, and the Tabwise scan calls it “Page language is not set”. They all mean the same thing: your page doesn’t tell browsers what language it’s written in.

It’s a small setting, usually a single line, and one of the quickest fixes there is.

Across all the Irish business websites in our studies, 7% (869 of 12,397) didn’t set a page language. It was highest among hotels and B&Bs: 8.1% (49 of 608) in our study of Irish hotel and accommodation websites.

Who this affects

Mainly people who use a screen reader. That’s software that reads the page aloud, used by blind people and many people with low vision. Screen readers use the page language to pick the right voice and pronunciation.

If the language isn’t set, the screen reader assumes the page is in its own default language, the one the person chose when setting it up. So someone whose screen reader is set to French may hear your English page read with French pronunciation. That’s very hard to follow.

The page language helps others too. Browsers can use it to offer a translation of your page.

What to set it to

For a website in English, either of these is fine:

  • en, which just means English
  • en-IE, which means English as used in Ireland

Either passes the check. Other English codes, like en-GB, pass too. What matters is that there’s a valid language.

Pages in Irish

If a page is in Irish, its language should be ga, the code for Irish. A page in Irish marked as English will be read with English pronunciation, which won’t make sense to anyone.

On a bilingual site, think about each page:

  • A page that’s all in Irish should have ga as its page language.
  • A page in English with a paragraph in Irish, like a welcome or a quote, needs that paragraph marked as Irish too. Your web person can do that with a small tag on the paragraph.
  • Place names, and Irish words that are part of everyday English, don’t need marking.

One honest limit: our scan only checks the setting for the whole page. It can’t tell whether a paragraph is in Irish, so it won’t notice an Irish passage on an English page that isn’t marked. Check those by eye, or ask your web person.

How to fix it

On most platforms, the page language comes from a site language setting, or from your theme. Set it to English (or Irish, if that’s your main language), then run our free scan again to check.

WordPress and WooCommerce

WordPress has a Site Language setting under Settings, then General. WordPress explains it on its page about the General Settings screen.

Your theme is what puts the language on your pages. If the language is set but our scan still flags it, the theme may be leaving it out. Contact your theme’s developer.

Shopify

Your store’s default language is under Settings, then Languages. Shopify says the default language is used in your store’s theme and checkout. Its guide to managing languages shows how to change it. If it’s set and our scan still flags it, contact your theme’s developer.

Wix

Your site language is under Language & Region in your site’s dashboard. Wix’s guide to changing your site’s language says screen readers use it to adjust accent and pronunciation. If you use Wix Multilingual, languages are managed there instead.

Squarespace

On version 7.1 sites, the site language is in the Site Languages panel. Squarespace’s guide to changing your account and site language explains it. Set it, then run our free scan again to check.

If someone else built your site

Copy this and send it to your web person:

Our website’s pages don’t declare a language, which fails WCAG 2.1 AA (success criterion 3.1.1). Please add a lang attribute to the html element on every page, set to “en-IE” (or “ga” for pages in Irish). Please also mark any passages in Irish on English pages with lang=“ga” (success criterion 3.1.2).

How to check it’s fixed

Run our free scan again. If the page language is set, this check will pass. Most sites set it in one place for every page, but it’s worth scanning a page in Irish separately if you have one.

For other pages, try the free WAVE checker from WebAIM. Type in the address of any page and look for “Language missing or invalid” in the results.

For your web developer

axe reports this as html-has-lang, against WCAG 2.1 success criterion 3.1.1, Language of Page. It checks only the <html> element for a non-empty lang (or xml:lang). A separate check, html-lang-valid, fails values that aren’t valid language codes.

<!-- Before -->
<html>

<!-- After -->
<html lang="en-IE">
  • In WordPress themes, the opening tag should be <html <?php language_attributes(); ?>>. That prints the language from the Site Language setting.
  • For pages in Irish, use <html lang="ga">.
  • For Irish passages on an English page, set lang on the element itself, as success criterion 3.1.2, Language of Parts, requires. Proper names, and words that have become part of the surrounding language, are exempt.
<p lang="ga">Fáilte romhat chuig ár siopa.</p>
  • axe’s valid-lang checks that these codes are valid, but no automated check can tell whether text is actually in Irish.
  • Check any pages served by a separate system, such as a booking engine or blog, which may have their own <html> tag.

Check your own website for free

We'll scan your homepage and a few key pages and email you a plain-English report in minutes.

Free Report by email in minutes Privacy