Add html lang attribute

The lang attribute on the html element tells browsers and assistive technology which language the page uses. Set it per locale, keep it accurate when content mixes languages, and make it match your hreflang values. A missing or wrong value breaks pronunciation, translation prompts and locale signals.

mediumIn codeimpact effort

Why this matters

Declare the page language once, in the html element.

Get the full breakdown

The extended brief explains when this works, when it does not, and the trade-offs. Join the waitlist and it unlocks for every tip when sign-in opens; MCP access is the paid part.

Join the waitlist

Before you start

  • Access to the root layout or template

How to apply it

  1. Set lang in the root layout

    Add lang to the html element with the locale of the page, not of the browser. Use the same tag format as your hreflang values.

    Check: curl -s your production domain/ | grep -o '<html[^>]*lang="[^"]*"' returns a valid BCP 47 tag.

  2. Handle mixed-language passages General best practice

    Wrap quotes or excerpts in another language with their own lang attribute. Do not change the document language for a single paragraph.

    Check: A page with a foreign quote contains a nested element with a different lang value.

  3. Align with hreflang and visible language

    Check that the lang value, the hreflang entry for the page and the visible content language agree on every locale template.

    Check: For each locale, the html lang, hreflang value and page copy all use the same language code.

Get the prompt for your agent

A ready-to-paste prompt for your agent that implements this tip and verifies the result in your repo.

Join the waitlist

Source: seo-mcp playbook · curated entry · report an error

Framework notes

nextjs-app

Set `<html lang={locale}>` in `app/[lang]/layout.tsx`; the App Router requires the tag in the root layout, so pass the param through.

nuxt

Set `app.head.htmlAttrs.lang` in `nuxt.config.ts` or per locale with `useHead({ htmlAttrs: { lang } })`.

wordpress

Use `language_attributes()` in `header.php`, and configure the site language under Settings, General so the function outputs the right tag.

Official references

Let your agent apply this + 161 more tips.

Pre-order — $19