Choose Your Language
What is a Body Tag in HTML | HARTRON EXAM

What is a Body Tag in HTML

What is a Body Tag in HTML
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:

AttributeDescriptionExample
bgcolorYou can add background colorbgcolor=”yellow”
alinkThe <a> tag placed in the <body> can change the color of the link.alink=”red”
backgroundYou can add an image in the background of <body>background=”logo.png”
linkYou can set the color of the link (url) which the user has not visited.link=”black”
vlinkYou can set the color of the link (url) which the user has visited.vlink=”blue”
textYou can set in what color all the text of <body> will appear.text=”grey”
onloadJavaScript function to run when the page is loading.onload=”myFunction()”
onunloadJavaScript function to run when the user leaves the page.onunload=”leaveAlert()”
onfocusTo run a JavaScript function when <body> gets user’s focus.onfocus=”inFocus()”
onblurTo run a JavaScript function when <body> is out of focus of the user.onblur=”inFocusOut()”
onerrorJavaScript function to run when some error occurs in the HTML document.onerror=”errorOccur()”
onresizeJavaScript function to run when the size of the webpage changes.onresize=”pageResize()”
(HTML) Body Tag
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.

Leave a Reply

Your email address will not be published.

%d bloggers like this: