Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Document and Metadata

The <head> element

Reference for the HTML <head> element: which metadata elements go inside, the recommended order, what browsers do with it, examples and technical details.

The <head> element holds information about the document rather than content for the page itself: its title, character encoding, viewport settings, style sheets, scripts, icons and search or social metadata. It is the first child of <html>, and nothing inside it is displayed in the page.

HTML
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Ferry timetable โ€“ Harbor Lines</title>
  <link rel="stylesheet" href="/css/site.css">
</head>

Try it

Reading head metadata from a script

Attributes

This element has only the global attributes. The old profile attribute is obsolete.

Usage notes

  • What goes inside. Only metadata content: <title>, <meta>, <link>, <style>, <script>, <base>, <noscript> and <template>.
  • Exactly one title. A normal document needs one <title> and may have at most one <base>.
  • A good order. Put <meta charset="utf-8"> first (it must appear within the first 1024 bytes), then the viewport <meta>, then <title>, then style sheets and scripts. Browsers can start work sooner when the important hints come early; see Loading Resources Efficiently.
  • Visible elements end the head. If the parser meets an element that doesn't belong in the head, such as a <p> or <img>, it closes the head and starts the body automatically. Any metadata written after that point ends up in the body, where some of it is ignored.
  • document.head gives scripts direct access to this element.

Technical summary

Content categories None
Permitted content One or more metadata content elements, including exactly one <title> and at most one <base>. (In an iframe srcdoc document, or when a title comes from a higher-level protocol, zero or more elements and an optional <title>.)
Tag omission The start tag may be omitted if the head is empty or its first content is an element. The end tag may be omitted if it is not immediately followed by a space or a comment.
Permitted parents An <html> element, as its first child
Implicit ARIA role No corresponding role
DOM interface HTMLHeadElement
Default display none

Browser support

Supported in every browser.