DOM Document.body Property
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.bodyValue
The document's <body> element.
Example
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.
Desktop





Tablets & Mobile





