Screen readers can use a page's declared language to choose pronunciation rules. In HTML, the lang attribute on the root <html> element sets the default language for the document.
The language on the root element applies to the page title and to body text that inherits it. A passage written in another language can carry its own lang attribute on the element that contains it.
A language tag can be as broad as en for English or as specific as en-GB for British English. A regional tag is useful when the wording or spelling follows that variety.
Steps to set the HTML language attribute:
- Create
index.htmlin an empty test folder using your text editor. - Enter the HTML below with lang="en" on the opening <html> tag for the page's English text.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Library</title> </head> <body> <h1>Library hours</h1> <p>Open at nine.</p> </body> </html>
On an existing HTML page, the change belongs on the opening <html> tag. If it already has
lang, replace its value in place. The W3C guidance on language tags explains which BCP 47 tag to use for your text. - Save
index.html. - Open the saved
index.htmlfrom your test folder in desktop Chrome.Chrome's file picker opens with
Ctrl+Oon Windows or Linux andCommand+Oon macOS.
- Open the Elements panel in Chrome DevTools with
Ctrl+Shift+Con Windows or Linux.On macOS the shortcut is
Command+Option+C.
- Confirm that the top-level <html> element in Elements shows the language tag you saved.
The Library hours page shows <html lang="en">. If the attribute is missing or has the wrong value, correct the opening tag in the file and reopen the saved page.