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
Syntax:
The various HTML tag has opening and closing tag like:
The div tag has compulsory to opening
<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.
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.
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:
Explanation:
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:
Explanation:
Below are the uses and needs of the div tag:
Given below are the examples mentioned:
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 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 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:
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!