Skip to content
AnswerWell geo Documentation

Research · 9 min read · Answerwell

HTML Head Metadata, Sectioning, and Grouping Content

How WHATWG HTML defines head metadata, global attributes, main landmarks, and lists—plus limits authors often miss.

This page summarises the WHATWG HTML rules for the document shell (html, head, body), metadata in the head, selected global attributes, and the sectioning and grouping elements most authors use when structuring pages. Normative detail also appears in the multipage and developer editions of the same specification; where algorithms differ, the multipage text is authoritative.

html, head, and body: what belongs in the document shell

Section titled “html, head, and body: what belongs in the document shell”

The html element is the root of an HTML document. Its content model is head followed by body.

The html element represents the root of an HTML document.

— WHATWG, Semantics — The html element

Authors are encouraged to set lang on the root html element so user agents know the document’s primary language for pronunciation, translation, and related processing.

The head element holds metadata for the document—not the primary readable content.

The head element represents a collection of metadata for the Document.

— WHATWG, Semantics — The head element

In the usual case (not an iframe srcdoc document and no title supplied by a higher-level protocol), head must contain one or more metadata elements, exactly one title, and at most one base. The title may be omitted only when a protocol such as email provides the document title (for example the message subject).

The body element contains the document’s contents. Conforming documents have a single body, exposed in the DOM as document.body.

title, meta charset, and other meta elements in head

Section titled “title, meta charset, and other meta elements in head”

The title element is the document’s name. It should make sense out of context—in history lists, bookmarks, and similar UI— and is often not the same text as the first h1.

The title element represents the document’s title or name. Authors should use titles that identify their documents even when they are used out of context

There must be no more than one title element per document.

— WHATWG, Semantics — The title element

User agents use document.title and the title element’s text for tab and window titles; directionality can follow the title element.

The meta element carries metadata that cannot be expressed with title, base, link, style, or script. Exactly one of name, http-equiv, charset, or itemprop may be set. When name, http-equiv, or itemprop is used, a content attribute is required.

For encoding, a meta element with charset declares that the document uses UTF-8 when serialized:

The charset attribute specifies the character encoding used by the document. This is a character encoding declaration. If the attribute is present, its value must be an ASCII case-insensitive match for the string “utf-8”.

— WHATWG, Semantics — The meta element

At most one meta element with charset may appear per document. In XML documents the charset attribute has no effect but is allowed to ease migration.

Section titled “base href: how relative links and form targets resolve”

The base element sets the document base URL for parsing relative URLs and the default navigable target for links and forms. At most one base per document may contribute each of href and target; additional base elements with the same kind of attribute are ignored after the first.

If href is present, it must be a valid URL and the base element must appear before any other element in the tree that has attributes taking URLs (so early placement in head matters). Certain schemes and documents block setting a base URL; in those cases the frozen base URL falls back per the spec’s algorithms.

A typical pattern: with base href="https://www.example.com/news/index.html", a link to archives.html resolves to https://www.example.com/news/archives.html. Treat unsanitized base as unsafe in user-generated HTML.

Global attributes: lang, translate, title, and style

Section titled “Global attributes: lang, translate, title, and style”

Global attributes apply across HTML elements. The DOM section of the spec defines processing; the developer edition mirrors the same rules for authors.

lang and translate when localising or mixing languages

Section titled “lang and translate when localising or mixing languages”

lang (no namespace) gives the primary language of an element’s text and of its attributes that contain text. The value must be a valid BCP 47 language tag or the empty string (unknown language). If omitted, language is inherited from the parent (with exceptions such as slot in a shadow tree).

The lang attribute (in no namespace) specifies the primary language for the element’s contents and for any of the element’s attributes that contain text. Its value must be a valid BCP 47 language tag, or the empty string.

Authors must not use the lang attribute in the XML namespace on HTML elements in HTML documents.

— WHATWG, Global attributes — lang

The translate attribute marks whether an element’s text and listed translatable attributes should be translated during localisation (yes / no, with inherit and empty-string defaults as defined in the spec).

The translate attribute is used to specify whether an element’s attribute values and the values of its Text node children are to be translated when the page is localized, or whether to leave them unchanged.

— WHATWG, Global attributes — translate

title attribute: advisory tooltips, not a substitute for accessible names

Section titled “title attribute: advisory tooltips, not a substitute for accessible names”

The title attribute holds advisory information, often shown as a tooltip.

The title attribute represents advisory information for the element, such as would be appropriate for a tooltip.

— WHATWG, Global attributes — title

Relying on title alone for critical information is discouraged because many user agents do not expose it accessibly (for example keyboard-only or touch users). If the value contains line feed (U+000A) characters, it is shown as multiple lines. An empty title suppresses advisory text for that element even if an ancestor has title.

style attribute: inline CSS, CSP, and non-conforming uses

Section titled “style attribute: inline CSS, CSP, and non-conforming uses”

All elements may have a style attribute interpreted under CSS Style Attributes. If Content Security Policy blocks inline style for an element, those rules must not apply.

The document must remain usable if all style attributes were removed. Using style only to hide, show, or convey meaning—not present in the markup otherwise—is non-conforming; prefer the hidden attribute or semantic elements.

Documents that use style attributes on any of their elements must still be comprehensible and usable if those attributes were removed.

In particular, using the style attribute to hide and show content, or to convey meaning that is otherwise not included in the document, is non-conforming.

— WHATWG, Global attributes — style

main, header, and search: sectioning and page landmarks

Section titled “main, header, and search: sectioning and page landmarks”

Sectioning and grouping rules live in Sections and Grouping content (dev mirrors, grouping).

The main element marks the dominant contents of the document. A document must have at most one main that is not hidden. Hierarchically, main may appear only under html, body, div, an unnamed form, or autonomous custom elements. Multiple main elements are allowed only if all but one are hidden (for example single-page app patterns described in the spec).

header groups introductory or navigational aids. It is not sectioning content: it does not by itself create a new outline section. It may contain headings, logos, tables of contents, or search UI.

The search element labels a region for search or filter controls—not a page that only shows results.

The search element represents a part of a document or application that contains a set of form controls or other content related to performing a search or filtering operation.

It’s not appropriate to use the search element just for presenting search results

— WHATWG, Sections — The search element

Browser support for search is still limited in compatibility tables bundled with the spec; treat it as progressive enhancement with a div or form fallback if broad support is required today.

Headings h1–h6 denote section titles; nesting section with headings and a flat heading hierarchy are semantically equivalent for outline purposes—choose one authoring style and stay consistent.

Lists, paragraphs, and div: grouping flow content

Section titled “Lists, paragraphs, and div: grouping flow content”
Goal Element Order matters?
Steps, rankings, legal numbering ol Yes — reordering changes meaning
Unrelated items, toolbars (menu) ul / menu No
Term–definition pairs dl with dt / dd Names paired with values, not dialogue
One block of prose p N/A

The p element is structural: do not wrap lists inside a single p to “glue” them into one sentence—use separate p and list elements.

address is for contact information tied to the nearest article or body, not for arbitrary postal addresses or “last modified” lines; use p, footer, or time as appropriate.

hr is a thematic break at paragraph level; it does not alter the document outline.

Minimal div use: the div element has no special semantics and should be a last resort when no other element fits.

Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable.

— WHATWG, Grouping content — The div element

Named character references and XML syntax (short limits)

Section titled “Named character references and XML syntax (short limits)”

HTML supports a fixed set of named character references (also listed in the dev edition). The table maps each name to code points; glyphs shown in the spec are non-normative compared to Unicode.

This list is static and will not be expanded or changed in the future.

— WHATWG, Named character references

Legacy compatibility means many characters accept several names (with or without a semicolon, different capitalizations). Tokenization rules in earlier sections govern when a reference matches at a given boundary—do not assume every alias behaves identically in ambiguous contexts.

For documents served as XML, see The XML syntax. The HTML specification discourages XML syntax for new work:

Using the XML syntax is not recommended, for reasons which include the fact that there is no specification which defines the rules for how an XML parser must map a string of bytes or characters into a Document object, as well as the fact that the XML syntax is essentially unmaintained — in that, it’s not expected that any further features will ever be added to the XML syntax (even when such features have been added to the HTML syntax).

— WHATWG, The XML syntax

  1. Open the page in a browser and confirm the tab title matches the intended out-of-context name from the single title element in Semantics; compare it to the first visible heading if they are meant to differ.

  2. In developer tools, inspect document.title and verify at most one meta with charset="utf-8" in the serialized HTML.

  3. If you use base href, follow a relative same-directory link and confirm the resolved URL matches the base URL rules (and that base appears before other URL-bearing elements in head).

  4. Temporarily remove or disable author style attributes (and inline styles blocked by CSP) and confirm the page is still comprehensible, as required for the style attribute.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.