Every HTML5 page begins with a doctype declaration, written as `` on the very first line. This single line tells the browser to render the document in standards mode, following the HTML5 specification. Without it, browsers fall back to quirks mode, emulating legacy behaviors that break modern CSS layouts and box-model handling. A minimal valid document then declares a language with the `lang` attribute on the `` element, sets the character encoding via a `` tag (typically UTF-8, which supports virtually every written language and emoji), and provides a `
` inside the ``. The charset declaration must appear within the first 1024 bytes so the browser can correctly decode the page without re-parsing.
The `
` element is often confused with the visible `` element, but they serve very different purposes. The `` holds metadata about the document, including title, character set, viewport settings, linked stylesheets, scripts, and Open Graph tags, and is never rendered as visible content. The ``, by contrast, is a semantic landmark that represents introductory content for its nearest sectioning ancestor, such as a page banner with a logo and main navigation. A page may contain many `` elements (for example, one inside each ``), but only one ``. Other useful head-only elements include `` for setting a default base URL for relative links, `` for declaring the master URL when the same content is reachable via multiple addresses, which helps consolidate SEO ranking signals, and `` for setting the color of the browser chrome on supporting devices.
HTML5 semantic elements describe the role of their content rather than just its appearance, providing meaningful structure that improves accessibility, SEO, and code readability. Common landmarks include `` for introductory content, `