Definition and Usage
The <body> tag represents the contents of the HTML document.
Basic Example
To understand the <body> tag, you need to understand the basic structure of HTML.
<!DOCTYPE html>
<html>
<head>
<!-- The document's metadata -->
</head>
<body>
<!-- The document's content -->
</body>
</html>
<!DOCTYPE html>: This part declares the document type and serves to ensure that the browser follows the latest web standards and renders the document correctly. It is not an HTML element.<html>: The root element, which is the top-level element of an HTML document. All HTML elements must be contained within the<html>element.<head>: This part defines the metadata and header information of the HTML document. It provides information about the document to the browser and can be used to link external stylesheets, JavaScript files, and more.<body>: This part defines the body content of the HTML document. The content that is actually displayed on the web page is written in this section, and various elements such as text, images, links, tables, and forms can be included.
When you create an HTML document with this basic structure, the browser correctly interprets the document and displays it as a web page.
Technical Summary
The <body> tag is a required tag that is essential for the basic structure of HTML.
A standards-compliant HTML document must contain only one <body> tag.
This is critical both from a semantic perspective, as the <body> tag represents the content ("body") of the HTML document, and in terms of compatibility with predictable scripting when using the document.body property to access the <body> tag in JavaScript, where the tag is expected to be unique within the document.
The <body> tag must be the second child element of the <html> element.
The following table summarizes the technical syntax of the <body> tag.
Incorrect Markup Examples
The following are examples of incorrect markup using the <body> tag.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
<body> <!-- Only one body tag is allowed in an HTML document. -->
</body>
</html>
The <body> tag is an essential tag that forms the basic structure of HTML.
An HTML document must contain only one <body> tag.
<!DOCTYPE html>
<html>
<head>
</head>
<div> <!-- The body tag is missing -->
</div>
</html>
The <body> tag must be the second child element of the <html> element. This rule is critical. Incorrect markup that violates this rule significantly increases the possibility of errors when integrating with JavaScript or other web technologies.
As the <body> tag is a fundamental component of the basic HTML structure and is used in interactions with scripts and other applications, it must be marked up correctly according to official standards.
Specifications
| Specification | |
|---|---|
<body>
|
HTML Standard #the-body-element |
Browser Compatibility
| Tag |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
<body>
|
1 | 12 | 1 | 1 |