<html> is the document’s root element. It contains the head with metadata and the body with the document’s content. A document has one root html element.
A complete document
HTML and CSS
HTML
<main>
<h1>Gardening notes</h1>
<p>Keep seedlings watered while their roots establish.</p>
</main>
CSS
Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.
Placement and attributes
Set lang to the document’s primary language, such as en. Screen readers can use it to choose pronunciation. Mark a change of language on the relevant descendant when needed. The doctype appears before html and selects standards mode; it is not an HTML element.
Write explicit opening and closing tags while learning. HTML allows omission of some tags under specific parsing rules, but XML and XHTML have different requirements.
Inspect the result
Inspect the root in developer tools. Confirm that it has one head and one body and that the language is available in the accessibility tree. The heading in this preview belongs to its own document.
Common mistakes
Do not insert a second document root, head, or body into an existing article and expect it to create a nested document. Use an iframe when a demonstration needs its own document. Browsers repair malformed HTML; the repaired DOM can differ from the source you typed.
Sources and browser support
MDN: html describes the syntax and links to the specification and compatibility data. Check individual values in that table when supporting older browsers.