November 15, 2026
What Is the HTML Body Element and How Is It Used?
The body element most important part of a webpage. All the content of a webpage must specify or written within <body></body> element. It is a longest part of any HTML file which contains actual contents which appear on the webpage. The body tag indicates the start and end of HTML files main body. Body tags described below:
Syntax
<body>
Body content here...
</body>
Example
<html>
<head>
<title>A HTML Example</title>
</head>
<body>
HTML is very easy to learn.
</body>
</html>
Save above code with .htm or .html extension and open with any web browser. Then you will find that the title will appear at the title bar of the browser and "HTML" is very easy to learn "will appear " body or main area of web browser.
Output
HTML is very easy to learn.
Attribute
There are some attributes present for body <body></body> tag which are described below:
| Attribute
| Description
|
| Background='URL' |
This attribute set a image as background of a webpage . |
| Bgcolor='#RRGGBB' |
This attribute use to set default background color of webpage. |
| Text='#RRGGBB' |
This attribute use to set default text color of webpage. |
| Link='RRGGBB' |
This attribute use to set default link color of webpage. |
| Vlink='RRGGBB' |
This attribute use to set default visited link color of webpage. |
| Leftmargin='n' |
This attribute use to set default left margin of webpage. |
| Topmagin='n' |
This attribute use to set default top margin of webpage. |
FAQ
1. Can CSS be applied to the HTML body element?
Yes, CSS can be applied directly to the
element. For example, developers can use CSS properties such as background-color, color, font-family, and margin to control the overall appearance of a webpage.
2. What happens if we do not write the body tag in HTML?
Modern web browsers can automatically create a body element when it is missing from an HTML document. However, explicitly writing the opening and closing body tags is recommended because it makes the document structure easier to understand and maintain.