<body>
The <body>
tag is an essential element in HTML. It contains all the visible content of a web page, such as buttons, images, and text elements.
The content placed within the <body>
tag is then displayed by the browser to be visible and usable on the users' screens.
It is always included after the
<head>
tag. 😉
Structure and syntax of the <body>
tag
Basic structure and syntax
The <body>
tag is a container: it is therefore used with:
- an opening tag
<body>
; - and a closing tag
</body>
.
Here is how to use it (quite simple as you will see!):
<body>
<!-- Your image, button, and text tags -->
</body>
Usage example
As it is always easier to get an idea with a complete example, here is one! ☝️
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of body tag</title>
</head>
<body>
<header>
<h1>Welcome to my site</h1>
</header>
<main>
<p>This is an example of content within the <strong><body></strong> tag.</p>
<a href="https://believemy.com">Visit this link</a>
</main>
<footer>
<p>Copyright © 2025</p>
</footer>
</body>
</html>
As we can see here, only the elements within <body>
are displayed on the users' screens. Try it yourself:
Attributes of the <body>
tag
The <body>
tag can include all "classic" attributes but it also contains two other specific ones.
Attribute | Description |
---|---|
onload | Executes JavaScript after the page has loaded. |
onunload | Executes JavaScript just before leaving the page. |
Browser compatibility
As you might expect, the <body>
tag is compatible with all browsers!
At the same time, without it... There would be no "standardized" web page (that adheres to the standards of the W3C).
Element | Google Chrome | Safari | Mozilla Firefox | Edge |
<body> | Yes | Yes | Yes | Yes |