Skip to main content

HTML Guide

Using the “meta” element to specify the document-wide default language is obsolete. Consider specifying the language on the root element instead.

Specify the language of your HTML document using the lang attribute on the <html> element instead of using a <meta> tag for the language.

The HTML5 standard encourages specifying the primary language of a document using the lang attribute on the <html> element. The lang attribute should be set to a valid language code, such as en for English or fr for French. Using a <meta> tag to declare the document language is considered obsolete because the <meta> tag cannot convey element-specific language information. The lang attribute is more versatile and directly associates the language with the HTML document structure itself. This approach aligns better with accessibility requirements and helps user agents understand and render the content appropriately.

Here is how you should specify the language using the lang attribute:

Correct usage with lang attribute:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Document with Language Specification</title>
  </head>
  <body>
    <p>This document is written in English.</p>
  </body>
</html>

Incorrect usage with <meta> tag:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Language" content="en">
    <title>This usage is considered outdated</title>
  </head>
  <body>
    <p>This should not be done in HTML5.</p>
  </body>
</html>

By defining the language with the lang attribute directly in the <html> tag, you improve the document’s compliance with modern standards and enhance the accessibility and internationalization aspects of your web content.

Learn more:

Related W3C validator issues