4. The elements of HTML
4.1. The root element
4.1.1. The html element
- Categories:
- None.
- Contexts in which this element can be used:
- As the root element of a document.
- Wherever a subdocument fragment is allowed in a compound document.
- Content model:
- A
headelement followed by abodyelement. - Tag omission in text/html:
- An
htmlelement’s start tag can be omitted if the first thing inside thehtmlelement is not a comment. - An
htmlelement’s end tag can be omitted if thehtmlelement is not immediately followed by a comment. - Content attributes:
- Global attributes
- Allowed ARIA role attribute values:
- None
- Allowed ARIA state and property attributes:
- Global aria-* attributes
- DOM interface:
-
interface HTMLHtmlElement : HTMLElement {};
The html element represents the root of an HTML document.
Authors are encouraged to specify a lang attribute on the root html element, giving
the document’s language. This aids speech synthesis tools to determine what pronunciations to use,
translation tools to determine what rules to use, and so forth.
It is recommended to keep the usage of attributes and their values defined on the html element to a minimum to allow for proper detection of the character encoding declaration within the first 1024 bytes.
The
html element in the following example declares that the document’s language is
English.
<!DOCTYPE html> <html lang="en"> <head> <title>Swapping Songs</title> </head> <body> <h1>Swapping Songs</h1> <p>Tonight I swapped some of the songs I wrote with some friends, who gave me some of the songs they wrote. I love sharing my music.</p> </body> </html>