English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM body attribute

HTML DOM Document Object

InBodyThe property sets or returns the main element of the document.

This property returns the elements of the current document.

Setting new text on the document will effectively delete all current children of the existing elements.

Please refer todocument.documentElementProperty, which returns the root (<html>) element.

Syntax:

Return the body property:

document.body

Set the body property:

document.body = content
document.body.style.background = "coral";
Test and see‹/›

Browser Compatibility

All browsers fully support the body property:

Property
bodyIsIsIsIsIs

Appropriate Value

ValueDescription
contentThe document.body property uses a single valueContent,which is used to add new content to the body element

Technical Details

Return Value:Reference to the Body object, which represents an element
DOM Version:DOM Level1

More Examples

Change the HTML content of the current document:

document.body.innerHTML = "<h1>Hello world</h1>";
Test and see‹/›

HTML DOM Document Object