Favorites

DOM Document.body Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Document.body
DOM Document PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The body property returns the page's body element.

Description

The body property returns the document's <body> element, where the visible content lives. It's often used as a place to append overlays and toasts, or to add classes that change the whole page's state, such as document.body.classList.add('menu-open'). It can be null in a script that runs in the <head> before the body has been parsed.

It can be replaced by assigning a new <body> element, although that's rarely useful. For frameset documents it returns the outermost <frameset> instead.

To run code that needs document.body, place the script at the end of the body, use the defer attribute, or wait for DOMContentLoaded. The <body> element is also where page-wide events such as click bubble up to before reaching the document.

Syntax

document.body

Value

The document's <body> element.

Example

<p>Page content</p>
console.log(document.body.tagName);
document.body.style.background = '#f8fafc';
document.body.classList.add('ready');
console.log(document.body.className);

Browser Support

The following information will show you the current browser support for the Document.body property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee