W3cubDocs

/Web APIs

Document: body property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨May 2018⁩.

The Document.body property represents the <body> or <frameset> node of the current document, or null if no such element exists.

Value

One of the following:

Examples

// Given this HTML: <body id="oldBodyElement"></body>
alert(document.body.id); // "oldBodyElement"

const newBodyElement = document.createElement("body");

newBodyElement.id = "newBodyElement";
document.body = newBodyElement;
alert(document.body.id); // "newBodyElement"

Notes

document.body is the element that contains the content for the document. In documents with <body> contents, returns the <body> element, and in frameset documents, this returns the outermost <frameset> element.

Though the body property is settable, setting a new body on a document will effectively remove all the current children of the existing <body> element.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
body 1 12 60
1–60Only supported for HTMLDocument, not all Document objects.
9.6 1 18 60
4–60Only supported for HTMLDocument, not all Document objects.
10.1 1 1.0 4.4 1

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document/body