How to create a section in a document in HTML?


Use the <div> tag to add a section in a document. The HTML <div> tag is used for defining a section of your document. With the div tag, you can group large sections of HTML elements together and format them with CSS.

Example

You can try the following code to create a section −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML div Tag</title>
   <link rel = "stylesheet" href = "style2.css">
   </head>
   <body>
      <div id = "contentinfo">
         <p>Welcome to our website. We provide tutorials on various subjects.</p>
      </div>
   </body>
</html>

The following is the css file style2.css

#contentinfo p {
   line-height: 20px;
   margin: 30px;
   padding-bottom: 20px;
   text-align: justify;
   width: 140px;
   color: red;
}

Updated on: 03-Mar-2020

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements