What is a Body Tag in HTML
(HTML) Body Tag
<body> tag is the most important tag in any HTML document or webpage, the most useful content of the webpage is kept in the <body> tag only.
The <body> tag starts below the <head> tag and ends above the <footer> tag.
Syntax of <body> tag:
<body> “Content” </body>
Attributes of <body> tag:-
How to write attributes in <body> tag:
<body attributename=”value”>
content
</body>
List of attributes of <body> tag:
Attribute | Description | Example |
bgcolor | You can add background color | bgcolor=”yellow” |
alink | The <a> tag placed in the <body> can change the color of the link. | alink=”red” |
background | You can add an image in the background of <body> | background=”logo.png” |
link | You can set the color of the link (url) which the user has not visited. | link=”black” |
vlink | You can set the color of the link (url) which the user has visited. | vlink=”blue” |
text | You can set in what color all the text of <body> will appear. | text=”grey” |
onload | JavaScript function to run when the page is loading. | onload=”myFunction()” |
onunload | JavaScript function to run when the user leaves the page. | onunload=”leaveAlert()” |
onfocus | To run a JavaScript function when <body> gets user’s focus. | onfocus=”inFocus()” |
onblur | To run a JavaScript function when <body> is out of focus of the user. | onblur=”inFocusOut()” |
onerror | JavaScript function to run when some error occurs in the HTML document. | onerror=”errorOccur()” |
onresize | JavaScript function to run when the size of the webpage changes. | onresize=”pageResize()” |
Example:
A simple HTML document:
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Definition and Usage
The <body> tag defines the document’s body.
The <body> element contains all the contents of an HTML document, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
Note: There can only be one <body> element in an HTML document.