Skip to content
Nazmul Nikhil
Menu

HTML Lang Attribute Invalid (Ahrefs): Use a Proper Language Code

Ahrefs flags pages whose html lang attribute isn't a valid language code. Here's the correct format and where to set it on each platform.

Nazmul Nikhil

By

Head of SEO & Assistant Manager, Digital Marketing at Notionhive

Published 1 min read
HTML Lang Attribute Invalid (Ahrefs): Use a Proper Language Code
Photo: Jason Leung on Unsplash

In short

Ahrefs flags "HTML lang attribute invalid" when the lang value on the <html> tag isn't a valid BCP 47 language tag. Typical mistakes are english, en_US with an underscore, or en-UK. Google doesn't use the lang attribute to detect language, but screen readers use it for pronunciation, and browsers use it for translation prompts and hyphenation. Use a short code like en or en-US.

The lang attribute tells browsers and assistive tools what language a page is in. It has to be a real language code.

Correct format

Invalid Valid
lang="english" lang="en"
lang="en_US" lang="en-US"
lang="en-UK" lang="en-GB"
lang="bd" (country) lang="bn" (Bengali)
lang="" lang="en"

Why it matters: WCAG 2.2 success criterion 3.1.1, Language of Page, is a level A requirement, the most basic level of accessibility.

Where to set it

WordPress: Settings > General > Site Language. The theme outputs it through language_attributes().

Shopify: the store's default language, output in theme.liquid via request.locale.iso_code.

Webflow: Site settings > Localization, for the primary locale.

Wix: the site language in Settings > Language & Region.

Custom builds: set it in the root HTML template, for example <html lang="en"> in index.html for a Vite app.

This guide isn't affiliated with or endorsed by Ahrefs.

Sources and references

TAGSAhrefs Site AuditHtml lang attribute invalidHtml lang codesLang attribute format
Nazmul Nikhil

About the author

Nazmul Nikhil

Head of SEO & Assistant Manager, Digital Marketing at Notionhive

SEO and AI search consultant in Dhaka, Bangladesh, helping small and mid-size businesses in the USA, UK, Australia and Canada.

Need help with this?

Get it fixed with International SEO

I find the issues that cost you traffic and fix them, starting with the pages that matter most.

Keep reading

Related articles

All Site Audit Issues posts →

Get the next guide in your inbox

One email when a new SEO or AI search guide goes live.

Ready to grow?

Get a free audit of your website, or book a 30-minute call to talk through your goals.

Nazmul Hasan

Talk to Nazmul directly

Reply within 24h

WhatsApp +880 1682835118
nazmulnikhil@gmail.com