Check 10.19 · On-page SEO and metadata

Check the lang attribute

Check that the lang attribute of the html tag declares the right language on every page, and fix it on WordPress, Shopify, Laravel, Next.js or Nuxt.

Priority
Important
Difficulty
Easy
Estimated time
15 to 45 min
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

The lang attribute of the <html> tag declares the main language of the page: <html lang="fr"> for a page in French. The check consists of making sure it is present, valid and correct on every template, then fixing it where it is set: the CMS language setting, the theme template or the application configuration. The multilingual case, where the value changes from one page to another, is covered in set html lang on each page (opens in a new tab).

Why it matters

Accessibility first. Screen readers choose their voice and pronunciation rules based on the declared language. A French page marked lang="en" is read with an English accent, often unintelligibly. WCAG (Web Content Accessibility Guidelines) success criterion 3.1.1, level A, requires that the default language of each page can be programmatically determined, which is what the lang attribute does.

Text rendering. The browser uses it for automatic hyphenation (hyphens: auto in CSS), glyph selection in some fonts, quotation marks generated by CSS, and to decide whether to offer to translate the page.

Google does not use it to detect the language. Its documentation is explicit: it determines the language of a page from its visible content and does not use language information in the code, such as the lang attribute. So do not count on this attribute to target a language in Google: that is the job of the content, of hreflang (opens in a new tab) and of separate URLs for each language. Bing documents the language signals it uses less precisely; a correct attribute costs nothing and removes any ambiguity.

What breaks when it is wrong. The most common case is not a missing attribute but a wrong one: a French site installed with the software’s default language (en-US), or a Laravel application left on APP_LOCALE=en. Accessibility audits flag it, screen readers mispronounce, and tools that rely on the code (translation, content extraction) start from wrong information.

What it improves

  • Accessibility Correct pronunciation by screen readers and speech synthesis; compliance with WCAG criterion 3.1.1.
  • Rendering Consistent hyphenation, typography and translation prompts.
  • Lighthouse audit The accessibility checks on the presence and validity of lang pass.
  • Generative engines and third-party tools Language metadata consistent with the content. How they use the attribute is not documented.
  • Google rankings No effect; Google ignores the attribute when determining the language.

How to check

Read the <html> tag served:

curl -s https://example.com/ | grep -o -i -m 1 '<html[^>]*>'

Expected result: <html lang="fr"> or <html lang="fr-FR">. Repeat on one example of each template (home, article, category, product, 404 page): a template written separately may have its own tag.

Values to recognize:

Value Verdict
fr, fr-FR, fr-CA, fr-BE Correct (BCP 47 language tag)
en, en-US on a page in French Wrong: installation language never changed
fr_FR Invalid: BCP 47 uses a hyphen, not an underscore (the underscore is the og:locale format)
french, reversed FR-fr, fra-FR Invalid or non-standard
lang="" Declared language unknown
Attribute missing Language unknown to assistive technologies

For a site-wide check:

  • Lighthouse, Accessibility category: it checks that <html> has a lang attribute and that its value is valid.
  • The W3C Internationalization Checker: it shows the language declared by the attribute, by the Content-Language HTTP header and by any meta tag, and flags inconsistencies.
  • Screaming Frog: custom extraction with the XPath /html/@lang across the whole crawl, then sort the column to spot isolated values.

How to implement

Before you start

Choose the value. For a French-language site meant for all French speakers, fr is enough. Add the region (fr-CA, fr-BE, fr-CH) only if the content is genuinely adapted to that country. The region in lang describes the language variant, not the targeted country. See distinguish language from geotargeting (opens in a new tab).

Where to put it. On the <html> tag only, once. For a passage in another language (a quotation, a book title), add lang to the element concerned: <blockquote lang="en">. This is WCAG criterion 3.1.2, level AA. See mark passages in another language (opens in a new tab).

What not to use instead. The W3C advises against <meta http-equiv="Content-Language"> for declaring the language of a page. The Content-Language HTTP header can indicate the intended audience, but lang in the HTML is what counts for the language of the text.

WordPress

Versions WordPress 6.4 to 7.1.

WordPress writes the attribute from the site language, through the language_attributes() function called in the theme header.

  1. Settings > General, “Site Language” field: choose “Français”. Save. The tag becomes <html lang="fr-FR">.
  2. If the value is still wrong, open the theme’s (or child theme’s) header.php and check the tag:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>

A hard-coded value (<html lang="en-US">) in a purchased theme is a theme bug: fix it in a child theme. Block themes handle the tag automatically.

  1. A user can display the admin in another language (Profile > Language): this does not change the language of the public site.

With Polylang or WPML, the attribute follows the language of each page; check one page per language.

Shopify

Versions Shopify admin, all plans, Horizon and Dawn themes, November 2026.

Recent themes write the active language, as Horizon and Dawn do in layout/theme.liquid:

<html class="js" lang="{{ request.locale.iso_code }}">

The store’s default language is set in Settings > Languages. If your theme writes a fixed value, replace it with {{ request.locale.iso_code }} in layout/theme.liquid (Online Store > Themes > … > Edit code), and do the same in layout/password.liquid and any other layout file.

PrestaShop

Versions PrestaShop 8 and 9, Classic and Hummingbird themes.

The Classic theme writes the attribute from the language of the store being displayed. Check the default language in International > Localization (Configuration), then the code of each language in the Languages tab of the same section (ISO code and language code fields). A third-party theme that writes a fixed value is fixed in templates/layouts/layout-both-columns.tpl or its equivalent, using the language variable provided by the Classic theme.

Magento

Versions Magento Open Source and Adobe Commerce 2.4.x.

The language comes from the store view locale: Stores > Settings > Configuration > General > General > Locale Options, “Locale” field, at store view level (French (France)). The Luma theme then writes <html lang="fr">. Flush the cache (System > Cache Management) and check.

Drupal

Versions Drupal 10 and 11.

Drupal writes the language of the current page in the theme’s <html> tag (html.html.twig). The default language is set in Configuration > Regional and language > Languages (/admin/config/regional/language), with the Language module enabled. If the site was installed in English, add French and set it as the default.

Wix, Squarespace and Webflow

Versions Wix Editor and Wix Studio, Squarespace 7.1, Webflow, all plans, November 2026.

The declared language comes from the site language setting in the settings (main language, or language and region). If the published source code shows lang="en" on a French site, change this setting, republish, then check again with the command from the “How to check” section.

Laravel

Versions Laravel 10 to 13.

The default template writes the application locale:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

The str_replace converts fr_FR to fr-FR. The locale comes from config/app.php, locale key; only the place where you set it changes with the version. After setting it, check every layout template (resources/views/layouts/, error pages in resources/views/errors/), and emails if you publish their web version.

Laravel 11 to 13

The locale key is fed by an environment variable. In .env:

APP_LOCALE=fr
APP_FALLBACK_LOCALE=fr

Then php artisan config:clear, or php artisan config:cache in production.

Laravel 10

The value is hard-coded in config/app.php:

'locale' => 'fr',

'fallback_locale' => 'fr',

Then php artisan config:clear, or php artisan config:cache in production.

Symfony

Versions Symfony 6.4, 7.4 and 8.x.

In templates/base.html.twig:

<!DOCTYPE html>
<html lang="{{ app.request.locale|replace({'_': '-'}) }}">

The default locale is set in config/packages/translation.yaml, key framework.default_locale: fr.

Next.js

Versions Next.js 15 and 16 (App Router and Pages Router).

App Router

The attribute goes in the root layout:

// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="fr">
      <body>{children}</body>
    </html>
  )
}

For a multilingual site with a [lang] segment, put the root layout in app/[lang]/layout.tsx and write <html lang={lang}> from the route parameters, which Next.js 15 and 16 pass as a promise (const { lang } = await params).

Pages Router

With i18n routing (i18n.locales and i18n.defaultLocale in next.config.js), Next.js itself writes the route’s language on <html>. Without i18n routing, set the attribute in pages/_document.tsx:

import { Html, Head, Main, NextScript } from 'next/document'

export default function Document() {
  return (
    <Html lang="fr">
      <Head />
      <body>
        <Main />
        <NextScript />
      </body>
    </Html>
  )
}

Nuxt

Versions Nuxt 3 and 4; @nuxtjs/i18n module 9 and 10.

In nuxt.config.ts:

export default defineNuxtConfig({
  app: {
    head: {
      htmlAttrs: {
        lang: 'fr',
      },
    },
  },
})

With the @nuxtjs/i18n module, call useHead(useLocaleHead()) in app/app.vue (Nuxt 4) or app.vue (Nuxt 3): the lang option, enabled by default, makes the attribute follow the route’s language.

Astro

Versions Astro 5 to 7.

In the layout template, for example src/layouts/Base.astro: <html lang="fr">. With Astro’s i18n routing, use Astro.currentLocale: <html lang={Astro.currentLocale}>.

Common mistakes

  • Installation language kept: lang="en-US" on a French site, because WordPress, Drupal or Laravel was installed in English.
  • Underscore: lang="fr_FR", copied from a system locale or og:locale. BCP 47 uses a hyphen.
  • Forgotten templates: the 404 page, the maintenance page, AMP pages or separately built landing pages keep the old value.
  • A fixed language on a multilingual site: every version declares fr. See set html lang on each page (opens in a new tab).
  • Believing that lang targets a language in Google: Google detects the language from the visible content. Targeting relies on content, separate URLs and hreflang.
  • Region added out of habit: fr-FR is not wrong, but fr-CA on content written for France is.
  • A Content-Language meta tag instead of the attribute: discouraged by the W3C.

Frequently asked questions

Does Google use the lang attribute for SEO?

No. Google states that it determines the language of a page from its visible content and does not use language information in the code, such as the lang attribute or the URL. Filling in lang therefore targets no language in Google. The attribute is still needed for accessibility, text rendering by the browser and consistent metadata; language targeting relies on content, separate URLs and hreflang.

Should I write lang="fr" or lang="fr-FR"?

Both are valid. Use fr for content in standard French meant for all French speakers, and a regional variant such as fr-CA or fr-BE only if the text is genuinely adapted to that country, through its vocabulary, prices or practical information. WordPress writes fr-FR by default when the site language is French: this is not an error to fix.

Does the lang attribute replace hreflang?

No, they do not play the same role. The lang attribute describes the language of the page text for the browser and assistive technologies. Hreflang, placed in the HTML, the HTTP headers or the sitemap, tells search engines which other URLs offer the same content in other languages or for other countries. A multilingual site needs both, with values that are consistent with each other.

How do I declare an English quotation in a French page?

Add the lang attribute to the element that contains the passage: for example lang="en" on the blockquote tag, or on a span for a short phrase. Screen readers then switch pronunciation for that passage alone, then return to French. This is the requirement of WCAG criterion 3.1.2, level AA. There is no need to do it for borrowed words that have passed into common usage, such as “week-end”.

Updated on

Topic checklist (PDF)

And now?

In the “On-page SEO and metadata” topic

  1. Write a unique title for each important page
  2. Include the main topic naturally
  3. Place important terms early if relevant
  4. Aim for 50–60 characters as an optional benchmark
  5. Avoid generic and repetitive titles
  6. Write a specific meta description
  7. Aim for 140–160 characters as a benchmark
  8. Convey a value proposition and encourage clicks
  9. Use one clear main H1
  10. Align the H1 with search intent
  11. Structure H2/H3 headings
  12. Avoid purely decorative headings
  13. Introduce the topic naturally
  14. Use semantic variants
  15. Break up paragraphs
  16. Use lists and tables where helpful
  17. Add a table of contents and anchors to long content
  18. Optimize URLs and slugs
  19. Check the lang attribute
  20. Set up a favicon
  21. Configure Open Graph and X Cards
  22. Test social sharing
  23. Analyze CTR and optimize snippets