Computer >> Computer tutorials >  >> Programming >> HTML

How do we style HTML elements using the division tag <div>?


With the <div> tag, easily define a section of your HTML Document. Group large sections of HTML elements together and easily format them. The <div> tag is used with block-level elements.

How do we style HTML elements using the division tag <div>?

You can try to run the following code to style HTML element using the <div> tag. The style rule added gets applied to the element with id=”content”.
Here id is the CSS Selector.

Example

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

Here’s the CSS file style.css,

#container p {
   line-height: 15px;
   margin: 20px;
   padding-bottom: 15px;
   text-align: justify;
   width: 130px;
   color: blue;
}