Home  >  Article  >  Web Front-end  >  div Tag in HTML

div Tag in HTML

PHPz
PHPzOriginal
2024-09-04 16:26:20907browse

In this article, we will see 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

tag another is 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:

The div tag has compulsory to opening

and closing
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
Tag Works In HTML?

The 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.

a. Using
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

Explanation:

  • 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.

b. Without using
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

Explanation:

  • 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:

  • The div tag is 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 of div Tag HTML

Given below are the examples mentioned:

Example #1

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:

div Tag in HTML

Example #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 in HTML

Example #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:

div Tag in HTML

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.

The above is the detailed content of div Tag in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:SUP Tag in HTMLNext article:SUP Tag in HTML