Elements of HTML named body

html body element tutorial
10 November 2024

When we look at HTML, one of the most important tags that contains the main content of a webpage is the body tag. This tag includes everything we want to display in the browser, such as text, images, links, and ...

The body tag comes after the head tag and is directly under the html tag. What's interesting is that metadata and settings related to the page are placed in the head tag, while the actual and visible content of the page is placed within the body tag.

Another important feature of the body tag is that we can use CSS styles on it, for example, to change the background color, fonts, link styles, and even control the positioning of the page content. This is why web designers typically use this tag directly or indirectly.

In general, everything that is placed within the body is considered the visible content of the page; therefore, it must be designed to be user-friendly. In this regard, the importance of adhering to coding standards in the use of the body tag is very crucial.

HTML Code Example Using the body Tag


  <!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>Example Page</title>
</head>
<body>
<h1>Welcome to our page!</h1>
<p>This is an example of using the body tag in HTML.</p>
<img src="image.jpg" alt="example image">
</body>
</html>

Line-by-Line Code Explanation

<!DOCTYPE html>
This line specifies the HTML5 doctype.
<html lang="fa">
Starts the HTML tag and defines the language of the page as Persian.
<head>
Starts the Head tag which includes metadata and the page title.
<meta charset="UTF-8">
Sets the character encoding of the page to UTF-8.
<title>Example Page</title>
The title of the page that is displayed in the browser tab.
</head>
End of the Head tag.
<body>
Starts the Body tag which holds the content of the page.
<h1>Welcome to our page!</h1>
The main heading of the page.
<p>This is an example of using the body tag in HTML.</p>
A paragraph of text.
<img src="image.jpg" alt="example image">
An image with a source and an alternative text.
</body>
End of the Body tag.
</html>
End of the HTML tag.

FAQ

?

Why should we use the body tag?

?

Can I apply CSS styles to the body tag?

?

Are there other tags similar to the body tag?