- gogoacademy
Here’s a simple complete code example that showcases the usage of the <body> tag:
open notepad ++ the write the following code :
<!DOCTYPE html> <html> <head> <title>My Webpage</title> </head> <body> <h1>Welcome to My Webpage</h1> <p>This is the main content of the webpage.</p> <img src="gogoacademy.png" alt="An image"> <a href="https://gogoacademy.net">Visit gogoacademy</a> </body> </html>
In this example:
Remember that the <body> tag should always be placed after the opening <html> tag and before the closing </html> tag in an HTML document.
save the file as (test,html)
then open the file with a browser to see the following output:

1-Structuring Content:
2-Displaying Text and Media:
3-Creating Layout:
Here some of global attributes with complete code examples:
Example:
<body class="container"> <!-- Content goes here --> </body>
Example:
<body id="main"> <!-- Content goes here --> </body>
Example:
<body style="background-color: #f2f2f2; font-family: Arial, sans-serif;"> <!-- Content goes here --> </body>
Example:
<body data-page-type="home" data-analytics-id="123456"> <!-- Content goes here --> </body>
These are some of the commonly used global attributes that can be applied to elements within the <body> tag.
complete code examples
Here are complete code examples showcasing the usage of attributes with the <body> tag:
Example using the class attribute:
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
<style>
.container {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
</style>
</head>
<body class="container">
<h1>Welcome to My Webpage</h1>
<p>This is the main content of the webpage.</p>
</body>
</html>
In this example:
Example using the id attribute:
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body id="main">
<h1>Welcome to My Webpage</h1>
<p>This is the main content of the webpage.</p>
<a href="#footer">Go to Footer</a>
<!-- ... -->
<footer id="footer">
<p>Footer content goes here.</p>
</footer>
</body>
</html>
In this example:

Example using the data-* attribute:
<!DOCTYPE html> <html> <head> <title>My Webpage</title> </head> <body data-page-type="home" data-analytics-id="123456"> <h1>Welcome to My Webpage</h1> <p>This is the main content of the webpage.</p> </body> </html>
In this example, the <body> tag has two data-* attributes:
Quiz about <body> tag with answers
Here’s a multiple-choice quiz about the <body> tag:
1-What is the purpose of the <body> tag in HTML?
a) It defines the document type
b) It defines the webpage title
c) It defines the main content area of the webpage
d) It defines the CSS styles for the webpage
Answer: c) It defines the main content area of the webpage.
2-Which attribute is commonly used with the <body> tag to apply CSS styles?
a) class
b) id
c) style
d) data
Answer: c) style
3-What does the class attribute do with the <body> tag?
a) It assigns a unique identifier to the element
b) It applies inline CSS styles to the element
c) It allows you to store custom data within the element
d) It assigns one or more class names to the element
Answer: d) It assigns one or more class names to the element.
4-Which of the following is a valid use of the <body> tag?
a) Defining the webpage title
b) Embedding a video
c) Including external CSS files
d) Declaring JavaScript functions
Answer: b) Embedding a video.
5-Can you have multiple <body> tags in a single HTML document?
a) Yes, it is allowed
b) No, it is not allowed
Answer: b) No, it is not allowed. There should only be one <body> tag per HTML document.
6-Which of the following elements is typically placed inside the <body> tag?
a) <head>
b) <footer>
c) <title>
d) <link>
Answer: b) <footer>
7-Which attribute is commonly used with the <body> tag to uniquely identify an element?
a) class
b) id
c) style
d) data
Answer: b) id
8-What is the purpose of the <body> tag in terms of accessibility?
a) It improves search engine optimization (SEO) for the webpage.
b) It defines the layout and design of the webpage.
c) It provides a structure for assistive technologies to navigate and understand the content.
d) It enhances the security of the webpage.
Answer: c) It provides a structure for assistive technologies to navigate and understand the content.
9-Which of the following elements is not typically placed inside the <body> tag?
a) <h1>
b) <script>
c) <meta>
d) <p>
Answer: c) <meta>
10-Is the <body> tag required in an HTML document?
a) Yes, it is always required.
b) No, it is optional.
Answer: a) Yes, it is always required. Every valid HTML document should have a <body> tag.
11-Which of the following is true regarding the <body> tag?
a) It must be placed before the <head> tag in an HTML document.
b) It is used to define the structure of a webpage.
c) It is an optional tag in HTML.
d) It is used to define the metadata of a webpage.
Answer: b) It is used to define the structure of a webpage.
12-Which of the following elements can be nested inside the <body> tag?
a) <header>
b) <script>
c) <nav>
d) All of the above
Answer: d) All of the above
13-What is the purpose of the <body> tag in terms of SEO (Search Engine Optimization)?
a) It determines the webpage’s ranking in search engine results.
b) It defines the keywords that are relevant to the webpage.
c) It provides a description of the webpage’s content.
d) It contains the main content that search engines index.
Answer: d) It contains the main content that search engines index.
14-Can you have multiple <body> tags in a single HTML document?
a) Yes, but it is not recommended.
b) No, it is not allowed.
c) Yes, it is allowed and often used for complex web pages.
d) Yes, but it requires special configuration.
Answer: b) No, it is not allowed. There should only be one <body> tag per HTML document.
15-Which attribute is commonly used with the <body> tag to specify the background image of a webpage?
a) background
b) style
c) class
d) id
Answer: a) background