概述

HTML body 元素表示文档的内容。document.body 属性提供了可以轻松访问文档的 body 元素的脚本。

内容分类 Sectioning root.
允许的内容 Flow content.
允许的父元素 它必须是 html 元素的直接子元素。
DOM 接口 HTMLBodyElement

属性

元素包含 全局属性

alink
超链接选中之后的文本颜色。此方法不符合规范,请使用 CSS 的 color 属性和 :active 伪类替代。
background
将URI所指向的图片作为背景。此方法不符合规范,请使用 CSS 的  background 属性替代。
bgcolor
文档的背景颜色。此方法不符合规范,请使用 CSS 的 background-color 属性替代。
bottommargin
body 底部留白。此方法不符合规范,请使用 CSS 的 margin-bottom 属性替代。
leftmargin
body 左边留白。此方法不符合规范,请使用 CSS 的 margin-left 属性替代。
link
未访问过的超链接文本颜色。此方法不符合规范,请使用 CSS 的 color 属性和 :link 伪类替代。
onafterprint
用户完成文档打印之后调用的函数。
onbeforeprint
用户要求打印文档之前调用的函数。
onbeforeunload
文档即将被关闭之前调用的函数。
onblur
文档失去焦点时调用的函数。
onerror
文档加载失败时调用的函数。
onfocus
文档获得焦点时调用的函数。
onhashchange
文档当前地址的片段标识部分(以('#')开始的部分)发生改变时调用的函数。
onlanguagechange
用户本地设置语言发生改变时调用的函数。
onload
文档完成加载时调用的函数。
onmessage
文档接收到消息时调用的函数。
onoffline
网络连接失败时调用的函数。
ononline
网络连接恢复时调用的函数。
onpopstate
用户回退历史记录时调用的函数。
onredo
用户重做操作时调用的函数。
onresize
文档尺寸发生改变时调用的函数。
onstorage
存储内容(localStorage / sessionStorage)发生改变时调用的函数。
onundo
用户撤销操作时调用的函数。
onunload
文档关闭时调用的函数。
rightmargin
body 右侧的留白。此方法不符合规范,请使用 CSS 的 margin-right 属性替代。
text
文本颜色。此方法不符合规范,请使用 CSS 的 color 属性替代。
topmargin
body 上方的留白。此方法不符合规范,请使用 CSS 的 margin-top 属性替代。
vlink
访问过的超链接的文本颜色。 此方法不符合规范,请使用 CSS color 属性和 :visited 伪类替代。

例子

<html>
  <head>
    <title>Document title</title>
  </head>
  <body>
    <p>This is a paragraph</p>
  </body>
</html>

技术规范

Specification Status Comment
HTML Living Standard
<body>
Living Standard 更改了不一致的特性列表。
HTML5
<body>
Recommendation 废弃了以前不赞成的属性。定义了没有标准化的 margintop, marginleft, marginrightmarginbottom 不一致的行为。增加了 on* 属性。
HTML 4.01 Specification
<body>
Recommendation 不赞成 alink, background, bgcolor, link, textvlink 属性。

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
alink
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
background
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
bgcolor
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
bottommargin
Deprecated
Chrome Full support YesEdge No support NoFirefox Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
IE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
leftmargin
Deprecated
Chrome Full support YesEdge No support NoFirefox Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
IE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
link
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onafterprintChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onbeforeprintChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onbeforeunloadChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onblurChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onerrorChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onfocusChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onhashchangeChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onlanguagechange
Experimental
Chrome ? Edge No support NoFirefox Full support 32IE No support NoOpera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile No support NoFirefox Android Full support 32Opera Android ? Safari iOS ? Samsung Internet Android ?
onloadChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onmessageChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onofflineChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
ononlineChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onpopstateChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onredoChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onresizeChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onstorageChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onundoChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
onunloadChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
rightmargin
Deprecated
Chrome Full support YesEdge No support NoFirefox Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
IE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
text
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
topmargin
Deprecated
Chrome Full support YesEdge No support NoFirefox Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
IE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android Full support 35
Notes
Full support 35
Notes
Notes Before Firefox 35, it was supported in Quirks Mode only.
Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
vlink
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.

参见

文档标签和贡献者

此页面的贡献者: eforegist, kite-js, hoyt, CodeDreamfy, JoshuaLee, sweetliu, pantao
最后编辑者: eforegist,