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 “HTML tag” row to show a valid lang
attribute that is consistent with the main language of the page content (not the message ‘The html tag has no language attribute’).
Aim for the “All 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.