<head> contains information about the document, such as its title, character encoding, stylesheet links, and other metadata. It is the first child of html, before the body.
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
For an ordinary standalone document, include one title. Place <meta charset="utf-8"> early in the document; the encoding declaration must be within the first 1024 bytes. A viewport declaration lets mobile browsers use the device width without disabling zoom.
Head content does not become the article’s visible text. Use body for that. Scripts and styles can have observable effects, but they are still document resources and instructions.
Inspect the result
Copy the document into an HTML file. Look at the browser tab: “Gardening notes” comes from title, while the visible heading comes from h1. Inspect head in developer tools and compare it with the visible body.
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: head describes the syntax and links to the specification and compatibility data. Check individual values in that table when supporting older browsers.