Skip to content

HTML <body> Tag

The <code><body></code> tag defines a web page's content (text, images, links, etc.). It is placed inside the <html> element, after the <head> element. In an HTML document, we can use only one <code><body></code> tag.

CSS classes are commonly added to the <code><body></code> element, allowing JavaScript developers and designers to target pages easily. Even if these classes are not used, they won’t cause any problems.

Syntax

The <code><body></code> tag comes in pairs. The content is written between the opening (<code><body></code>) and closing (<code></body></code>) tags.

Example of the HTML <code><body></code> tag:

HTML <body> Tag

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <p>Content of the document</p>
  </body>
</html>

Result

body example

Example of the HTML <code><body></code> tag used with the CSS color and line-height properties:

Example of the HTML <body> tag with the CSS properties

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      body {
        color: #444444;
        line-height: 1.5;
      }
    </style>
  </head>
  <body>
    <h1>HTML body tag example</h1>
    <p>Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>
  </body>
</html>

Attributes

AttributeValueDescription
alinkcolorDefines the color of the active link. Not used in HTML5.
backgroundURLDefines the background image. Not used in HTML5.
bgcolorcolorDefines the background color. Not used in HTML5.
linkcolorDefines the color of unvisited links. Not used in HTML5.
textcolorDefines the color of the text in a document. Not used in HTML5.
vlinkcolorDefines the color of the visited link. Not used in HTML5.

The <code><body></code> tag supports the Global Attributes and the Event Attributes.

Note: The attributes listed in the table above are deprecated in HTML5. Modern web development relies on CSS for styling. Use global attributes like `class`, `id`, and `style` to apply styles and structure to the <code><body></code> element.

Practice

What is true about the HTML <body> tag according to the information on the webpage?

Dual-run preview — compare with live Symfony routes.