document.body is the <body> (or <frameset>) node of the current document, or null if none exists (MDN). It is the usual container for visible page content.
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use document.body. Start with this line.
JavaScript
document.body
Call
What it does
document.body
Primary signature.
Built into the browser. Read or assign document.body — no import required.
Library declarations
JavaScript
document.body
Parameters
Parameter
Description
Writable?
Required. Replacing clears old body children (MDN)
Return Value
Return Value
Description
*
HTMLBodyElement | HTMLFrameSetElement | null
JavaScript Examples
Example 1 — Read document.body.id (MDN)
Given <body id="oldBodyElement">, read the id from JavaScript.
Old children disappear — MDN: replacement clears the previous body’s content.
Use rarely — prefer appending or updating nodes inside the existing body.
Compatibility
Browser Support
Document.body is a core DOM property. MDN marks it Baseline Widely available (since May 2018). It works across modern browsers and long-standing engines.
✓ Baseline · Widely available
Document.body
Returns the document’s body or frameset element, or null. Safe for everyday web apps.
MDN: the <body> or <frameset> node of the current document, or null if no such element exists. Typically an HTMLBodyElement.
No. MDN marks Document.body as Baseline Widely available (since May 2018). It is not Deprecated, Experimental, or Non-standard.
Yes. The property is settable. MDN: setting a new body effectively removes all current children of the existing <body>.
document.documentElement is the root <html> element. document.body is the <body> (or frameset) that holds the page content you usually manipulate.
When the document has no body yet (for example during early parsing) or in document types without a body. Check before use in edge cases.
Yes, when you need the page content container — appending nodes, body-level styles, or reading body attributes. Prefer a more specific selector when you target one region.