search

div Tag in HTML

Sep 04, 2024 pm 04:26 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

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:


<title>how to work div</title>
<style type="text/css">
.one{
background-color:orange;
}
.two{
background-color:yellow;
}
</style>


<div class="one">
<h1 id="Content-of-div-tag-in-Html"> 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 id="Content-of-div-tag-in-Html"> 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>

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:


<title>how to work div</title>
<style type="text/css">
p{
background-color:orange;
}
h1{
background-color:yellow;
}
</style>


<h1 id="Content-of-div-tag-in-Html"> 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 id="Content-of-div-tag-in-Html"> 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>

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:


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


<div class="leftdiv">
<h2 id="Left-Side"> 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 id="Middle-Side"> 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 id="Right-Side"> 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>

</div>

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:


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


<div>
<h2 id="Student-Information"> 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>

Output:

div Tag in HTML

Example #3

div example with style.

This is a simple example of using CSS style.

Code:


<title> Example3 </title>
<style>
div{
height:300px;
width:500px;
color:white;
border:1px solid;
background-color:grey;
}
</style>


<center>
<div>
<caption>
<h2> div tags in HTML
</h2>
</caption>
<h3>
Div tag is division tag used for group many HTML tag like table, list, paragraph in web page.
</h3>
</div>
</center>

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
How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.