Indicating language
The content of HTML documents can be authored in a wide range of written and spoken languages, and one document may include multiple languages. Correctly indicating language in the HTML markup supports assistive technology, search engines, and the user experience.
Recommendations
Specify the main language of the page content.
Indicate any changes to language within the page content.
When needed, specify the language direction along with the language.
Why it matters
Assistive technologies such as screen readers can support different languages. Indicating language programmatically supports appropriate pronunciation.
Search engines use the indicated language of a page to return relevant search results.
Browsers use the indicated language and language direction to choose a default font, punctuation, spell check dictionary, and to offer translation when appropriate.
Examples
Recommended:
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>Language techniques</title>
</head>
<body>
<h1>Techniques for language in HTML</h1>
<p><span lang="es">Cinco de Mayo</span> is Spanish for "fifth of May".</p>
<p><span dir="rtl" lang="ar">丕賱禺丕賲爻 賲賳 賲丕賷賵</span> is Arabic for "fifth of May".</p>
</body>
</html>
<!DOCTYPE html>
<html dir="rtl" lang="ar">
<head>
<title>鬲賯賳賷丕鬲 丕賱賱睾丞</title>
</head>
<body>
<h1>鬲賯賳賷丕鬲 丕賱賱睾丞 賮賷 HTML</h1>
<p><span dir="ltr" lang="es">Cinco de Mayo</span> 賮賷 丕賱兀爻亘丕賳賷丞 "丕賱禺丕賲爻 賲賳 賲丕賷賵".</p>
</body>
</html>
Not recommended:
<!DOCTYPE html>
<html>
<head>
<title>Language techniques</title>
</head>
<body>
<h1>Techniques for language in HTML</h1>
<p>Cinco de Mayo is Spanish for "fifth of May"</p>
<p>丕賱禺丕賲爻 賲賳 賲丕賷賵 is Arabic for "fifth of May".</p>
</body>
</html>
Testing
After HTML validation, use the .
Aim for the 鈥淗TML tag鈥 row to show a valid lang
attribute that is consistent with the main language of the page content (not the message 鈥楾he html tag has no language attribute鈥).
Aim for the 鈥淎ll language tags鈥 row to show a valid lang
attribute for each instance in the page content that uses a different language to the main language of the page.