Web development
Declare the page’s language
Set lang on the root HTML element to identify the page’s primary language. Mark a passage with its own language when it differs meaningfully from the surrounding text.
Worked example
HTML example · save as example.html and open in a browser
<!doctype html>
<html lang="en"><head><title>Language example</title></head>
<body><main><h1>Welcome</h1><p>A French greeting: <span lang="fr">Bonjour tout le monde.</span></p></main></body></html>How it works
Language metadata helps speech synthesis choose pronunciation rules and supports other language-aware browser behavior. The page-wide value supplies a default, while a nested lang attribute applies only to that element and its descendants.
Limits and mistakes
The language tag describes content rather than the reader’s location. It does not translate text or configure a server locale. Use valid language tags and update the attribute when serving a genuinely different language version.
Check the result
Inspect the HTML root and the foreign-language span. If using a screen reader with the relevant voices installed, confirm the language change is communicated at the intended passage.
Sources
Reference documentation for the behavior used in this guide: