The html tag

Quick look

Required?sort of?
Common attributeslang, dir

Summary

html is the root element, so all your HTML should live inside this tag. While it's not strictly required, it's good practice to include it. If you omit the tag, browsers will usually insert it for you. Because browsers can have different behavior, you may get unexpected side effects relying on this implementation. Explicitly defining the html tag also allows you to define the language of the document.

Immediate children can only be one head and one body (in that order).

The CSS psuedo-class :root will select the html tag.

Attributes

lang

The lang attribute accepts any valid language code and defaults to unknown. This attribute tells screen readers what language to use to announce the page. Depending on the language code you set in the lang attribute, you may also want to set dir="rtl" on the html tag to denote whether text is read right-to-left or left-to-right.

Global attributes

Usage

<!DOCTYPE html>
<html lang="en">
  <head>
    …
  </head>
  <body>
    …
  </body>
</html>

Note: denotes miscellaneous HTML, removed for brevity.

Links

MDN: The HTML Document

MDN: The lang attribute

BCP47 Language Code Lookup

:root CSS psuedo-class