The <body></body> element surrounds all of a page's content that will actually be rendered on the web page. It is possible to specify a background color or image for the page by using the proper CSS property.

Example code

To apply this in an HTML document, use:

<!DOCTYPE html>
        <title>The title</title>
        Head content
        Body content


As of HTML 4.0, all presentational attributes on the body are deprected in favor of CSS.[1][2]

  • Global HTML attributes
  • HTML 4 & 5: onload, onunload
  • Deprecated in HTML 4: background, text, link, vlink, alink
  • HTML 5 only: onafterprint, onbeforeprint, onbeforeunload, onblur, onerror, onfocus, onhashchange, onmessage, onoffline, ononline, onpagehide, onpageshow, onpopstate, onredo, onresize, onscroll, onstorage, onundo


Most graphical web browsers add an 8 pixel margin around the body contents.

Typical CSS representation:

body {
    display: block;
    margin: 8px;

Coding rules

The <body> element is the second element inside the <html> element. (The <head> element is the first one.) Inside the <body> element, only elements from the Flow content category are allowed. The <body> element itself belongs to the Sectioning root category.

Both the start and end tags are optional. The <body> element is automatically generated when the tags are not used.


External links