HTML Guide
Instead of using the isolang
attribute to define the language of the document, you can use lang
with an ISO 639-1 two character code.
For example, for Portuguese:
<html lang="pt">
Learn more:
Related W3C validator issues
The specified language code in the lang attribute of the <html> tag is not a valid ISO code.
Always use a language attribute on the <html> tag to declare the default language of the text in the page, using the lang property.
Example:
<html lang="fr">
A stray start tag <html> has been found in the document. As this tag defines the start of the whole HTML document, it should appear only once.
In HTML5, there’s no need to specify the version attribute - it is now obsolete. Here’s an example minimal HTML document to start with:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<p></p>
</body>
</html>
Based on the content of the document, the W3C Validator has determined that it’s written in Arabic, and it suggests you specify the direction of text from right to left like this:
<html dir="rtl" lang="ar">
Based on the content of the document, the W3C validator thinks that it’s written in English. Consider explicitly specifying the language using the lang property.
Example:
<html lang="en">
Based on the content of the document, the W3C validator thinks that it’s written in English, but the lang property in the <html> element specifies a different language. Check the language of the document, if it matches the lang property you can safely ignore and mute this warning.
Example:
<html lang="fr">
Based on the content of the document, the W3C validator has determined that the main language doesn’t match the one specified in the lang property of the <html> tag. Check the language of the document, if it matches the lang property you can safely ignore and mute this warning.
This validation issue indicates that your HTML document does not specify a language for its content. Specifying the document’s language is important for accessibility, search engines, and browser behavior.
To fix this, you need to add the lang attribute to the <html> element, indicating the primary language of the document. For example, if your document is written in Spanish, you should set the lang attribute to "es".
Here’s how to do it:
Original HTML (without lang attribute)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mi Sitio Web</title>
</head>
<body>
<h1>Bienvenido a mi sitio web</h1>
<p>Este es un párrafo en español.</p>
</body>
</html>
Updated HTML (with lang attribute)
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Mi Sitio Web</title>
</head>
<body>
<h1>Bienvenido a mi sitio web</h1>
<p>Este es un párrafo en español.</p>
</body>
</html>
Explanation
- The lang="es" attribute specifies that the primary language of the document is Spanish.
- Setting the lang attribute helps screen readers and other assistive technologies to better interpret the content.
- It also provides crucial information for search engines and browsers, improving the accessibility and search engine optimization (SEO) of your website.
If you need to specify a regional variation of Spanish, you can use values like lang="es-ES" for Spanish as used in Spain, or lang="es-MX" for Spanish as used in Mexico.
Example with Regional Variation
<!DOCTYPE html>
<html lang="es-MX">
<head>
<meta charset="UTF-8">
<title>Mi Sitio Web</title>
</head>
<body>
<h1>Bienvenido a mi sitio web</h1>
<p>Este es un párrafo en español de México.</p>
</body>
</html>
By adding the lang attribute with the appropriate value, you’ll resolve the W3C HTML Validator issue.
Elements that have the xml:lang attribute also need a matching lang attribute. In HTML5 documents, using just the lang attribute is enough.