Introduction to div Tag in HTML

div tag in html

Introduction to div Tag in HTML

In this article, we will learn about the div Tag in HTML. HTML has two important tags which are used for a group many other HTML tags and content One is <div> tag another is <span> tag. The span tag is used for a group of content and tag in one line. Vertically grouping with style and the different tag is happened by span tag. The div tag is a division tag used for many HTML tags like table, list, and paragraph on the web page. Mostly div tag used an empty web page to partition or make a section for content or HTML tags. To make a particular design for some special content div tag is useful because it does not affect the div layout and any CSS design.

Syntax:

The various HTML tag has opening and closing tag like

  • <p> </p>,
  • <div> </div>,
  • <table> </table>.

div tag has compulsory to opening <div> and closing </div> tag. Required HTML tags and content put inside of div tag.

<div>
Content of Div tag in HTML
</div>

To make the section of required data or content multiple div tags are used in a container. Example: header, footer, navigation bar, table, images, texts, etc. Different div tag we can design differently using CSS and easily apply conditions using JavaScript.

How <div> Tag Works In HTML?

div tag can hold various HTML tags and texts together. You can see the example of using a div tag and without a div tag.

Using <div> tag in HTML

Code:

<html>
<head>
<title>how to work div</title>
<style type=text/css>
.one{
background-color:orange;
}
.two{
background-color:yellow;
}
</style>
</head>
<body>
<div class="one" >
<h1> Content1 of div tag in Html </h1>
<p>   Div tag is used for group many HTML tag like table, list, paragraph in web page.
Mostly div tag used in empty web page to partition or make section for content or HTML tags. </p>
</div>
<div class="two">
<h1> Content2 of div tag in Html </h1>
<p>   To make section of required data or content multiple div tags are used in container.
Example: header, footer, navigation bar, table, images, texts etc. </p>
</div>
</body>
</html>

Output:

Div Tag in HTML - 1

Explanation of the above code: The above exam is using a div tag in HTML. The first div is orange in color, and the second div is a yellow color. Div contains a header tag and paragraph together. Two div tags divide container with different content.

Without using <div> tag in HTML

Code:

<html>
<head>
<title>how to work div</title>
<style type=text/css>
p{
background-color:orange;
}
h1{
background-color:yellow;
}
</style>
</head>
<body>
<h1> Content1 of div tag in Html </h1>
<p>   Div tag is used for a group many HTML tags like table, list, a paragraph on a web page.
Mostly div tag used in empty web page to partition or make section for content or HTML tags. </p>
<h1> Content2 of div tag in Html </h1>
<p>   To make section of required data or content multiple div tags are used in container.
Example: header, footer, navigation bar, table, images, texts etc.</p>
</body>
</html>

Output:

Div Tag in HTML - 2

Explanation of the above code: The above example is without using a div tag in HTML. The header and their paragraph are in a different section. The header is yellow, and the paragraph is in orange color. All headers and their content paragraphs have different sizes.

Uses of div Tag

Below are the uses and needs of the div tag: Popular Course in this categoryHTML Training (12 Courses, 19+ Projects, 4 Quizzes)12 Online Courses | 19 Hands-on Projects | 89+ Hours | Verifiable Certificate of Completion | Lifetime Access | | 4 Quizzes with Solutions
4.5 (6,492 ratings)Course Price
₹6999 ₹41999
View Course


Related CoursesBootstrap Training (2 Courses, 6+ Projects)XML Training (5 Courses, 6+ Projects)CSS Training (9 Courses, 9+ Projects)

  • div tag mainly used for grouping of tags and elements like images and their descriptions. In web pages uses many HTML tags to create content. All HTML tags are different with particular meanings. div tag combines all required HTML tags.
  • A div tag means division tags. In web pages, much entity like header, footer, navigation bar, etc. div tag makes many sections in one container to make all sections elegant.
  • It is easily used for styling using CSS and manipulating with JavaScript. It is not affecting in context as well as layout. The Steady style using a div tag is easy.
  • The div tag is useful for a web page is look attractive and understand the content for the user.
  • Remove the complexity of the program for a web developer; the div tag is useful.

Examples to Implement in div Tag HTML

Below are the examples to Implement in div Tag HTML:

1. div tag using the class

This example is a div tag with classes. for example, left, middle and right class. div is container comes in vertically. But we can place different div in one section as right, left or middle side; this is useful for position management for content.

Code:

<html>
<head>
<title> Example1 </title>
<style type=text/css>
.leftdiv
{
float: left;
background-color:blue;
}
.middlediv
{
float: left;
background-color:green;
}
.rightdiv
{
float: left;
background-color:black;
}
div{
padding : 1%;
color: white;
background-color:grey;
width: 28%;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="leftdiv">
<h2> Left Side </h2>
<p>Div tag is used for group many HTML tag like table, list, paragraph in web page.
Mostly div tag used for a web page to partition or make a section for content or HTML tags.
To make a particular design for some special content div tag is useful because it does not
affect the div layout and any CSS design.
</p>
</div>
<div class="middlediv">
<h2> Middle Side </h2>
<p>Div tag is used for group many HTML tag like table, list, paragraph in web page.
Mostly div tag used in empty web page to partition or make section for content or HTML tags.
To make particular design for some special content div tag is useful because it is does not
affect on the div layout and any CSS design.
</p>
</div>
<div class="rightdiv">
<h2> Right Side </h2>
<p>Div tag is used for group many HTML tag like table, list, paragraph in web page.
Mostly div tag used for a web page to partition or make a section for content or HTML tags.
To make particular design for some special content div tag is useful because it is does not
affect on the div layout and any CSS design.
</p>
</p>
</div>
</body>
</html>

Output:

tag using the class

2. div tag for the table

In this example, we used div tags for the table. Sometimes table layout changes, but table put in div tag then not affected on layouts.

Code:

<html>
<head>
<title> Example2 </title>
<style type=text/css>
div{
color:white;
background-color:grey;
border:solid black;
}
tr, td{
border: 1px solid grey;
padding-top: 10px;
padding-bottom: 10px;
}
th {
padding-top: 10px;
padding-bottom: 10px;
text-align: left;
}
</style>
</head>
<body>
<div>
<h2> Student Information </h2>
<table>
<tr>
<th>student name</th>
<th>specialisation</th>
<th>city</th>
</tr>
<tr>
<td>vishu</td>
<td>computer and IT </td>
<td>kolkatta</td>
</tr>
<tr>
<td>john</td>
<td> graphics design</td>
<td> delhi</td>
</tr>
<tr>
<td>nagma</td>
<td> mechatronics</td>
<td>nagpur</td>
</tr>
<tr>
<td>erfan </td>
<td>animation video </td>
<td>mumbai</td>
</tr>
<tr>
<td> swadut </td>
<td> electronics</td>
<td> pune</td>
</tr>
<tr>
<td> manasi </td>
<td> CS </td>
<td> pune</td>
</tr>
</table>
</div>
</body>
</html>

Output:

Div tag for the table

3. div Example with style

This is a simple example of using CSS style.

Code:

<html>
<head>
<title> Example3 </title>
<style>
div{
height:300px;
width:500px;
color:white;
border:1px solid;
background-color:grey;
}
</style>
</head>
<body>
<center>
<div>
<caption>
<h2> div tags in HTML</h3>
</caption>
<h3>
Div tag is division tag used for group many HTML tag like table, list, paragraph in web page.
</h3>
</div>
</center>
</body>
</html>

Output:

Example with style

Conclusion

The div tag is a division tag to make a partition on a web page. This is one empty container to contain HTML tags and contents. Using div tag web application looks neat, clean and attractive. The web application is easier to understand to users and developers.

Recommended Articles

This is a guide to div Tag in HTML. Here we discuss how <div> Tag Works In HTML, uses of Div Tag and the examples to implement with the respective sample code. You can also go through our other related articles to learn more –

  1. Embed Tag in HTML
  2. Canvas Tag in HTML
  3. HTML Event Attributes
  4. Types of Tags in HTML

Leave a Comment

Your email address will not be published. Required fields are marked *