2.5. Body Section

The body section of the document is where the visible content appears. This content is typically a series of block tags containing in-line content—similar to paragraphs containing words and sentences.

The body section is delimited by opening and closing <body> tags and appears after the <head> section but within the <html> tags. For example, the following code shows the typical structure for a Web document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <title>...document title goes here...</title>
  <style type="text/css">
    ...style definitions go here ...
  </style>
  <script type="text/javascript">
    ...script code goes here...
  </script>
</head>
<body>
...document body goes here...
</body>
</html>

Prior to HTML 4.01 the <body> tag played host to a wealth of document format information, including the following:

  • Background color

  • Background image

  • The color of text

  • The color of links in the document

However, those attributes have been deprecated, and the appropriate CSS styles are now used instead.

Styles are covered in depth within Section II of this book.

The <body> tag does retain all of its event attributes—onload, onunload, onclick, and so on. These events can be used to trigger scripts upon the appropriate action. For example, the following <body> tag will cause the current document to close when the user clicks anywhere in the document:

<body onclick= "self.close()">

Events and scripts ...

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.