body – page body
<body>…</body>
The body of the document – everything the visitor sees: headings, text, images, forms. A page has only one, right after the head (head).
- Default display:
display: block - End tag: can be omitted – just like the start tag
- Content: the content of the page (flow content: blocks, text, inline elements)
- Where it can be used: the second child of
html, afterhead - DOM interface:
HTMLBodyElement
Attributes
- Only global attributes and page-wide events (
onload,onbeforeunload,onhashchange,onpopstate…). Events are clearer to attach in JavaScript withwindow.addEventListener(), though. - Obsolete:
bgcolor,text,link,vlink,alink,background,marginwidth– presentation belongs in CSS.
Examples
The body of a page with the usual division into a header, main content and footer:
<body>
<header>
<a href="/">Mill Lane Bakery</a>
</header>
<main>
<h1>Sourdough bread</h1>
<p>Baked every morning from our own starter.</p>
</main>
<footer>
<p>12 Mill Lane, Springfield</p>
</footer>
</body>
The browser gives the body a default margin of 8 px. Most stylesheets therefore reset it at the start:
<body>…</body>
body {
margin: 0;
}
Things to watch out for
- The default
margin: 8pxis why the page does not “touch” the edge of the window. - A second
<body>tag in the page (from an included file, for example) does not create a new element – the browser only adds its attributes to the first body if they are not there yet. - A background set on
bodyextends to the whole window even when the body is shorter than the window – as long as the roothtmlhas no background of its own.
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 1. As of October 2026 (MDN browser-compat-data).
Related:
html – document root
head – document head
main – main content
header – header
footer – footer