Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

head — HTML document metadata

The `head` element groups document metadata, such as the title and character encoding declaration. It is the first element child of `html`, before `body`.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<head>
  <meta charset="utf-8">
  <title>Document title</title>
</head>

head represents a collection of document metadata. Within html, it precedes body. Do not confuse it with a visible page heading: page content belongs in body, while title specifies the document title.

The contents of head must be metadata content; examples include title, meta, link, style, and script. Normally, exactly one title is required. For an iframe srcdoc document, or when a higher-level protocol supplies the title, it may be omitted. In either case, at most one base is allowed.

head supports global attributes. In text/html syntax, its tags can be omitted only under specified conditions; the example writes both explicitly to keep the structure clear.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Head demo</title>
</head>
<body>
  <p>Page content</p>
  <script>
    const head = document.head;
    const charset = head.querySelector('meta[charset]');
    console.log('Head is the first element in html: ' + (document.documentElement.firstElementChild === head));
    console.log('Title in document metadata: ' + document.title);
    console.log('Charset declared in head: ' + charset.getAttribute('charset'));
  </script>
</body>
</html>

Result

Head is the first element in html: true
Title in document metadata: Head demo
Charset declared in head: utf-8

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources