The <div> element is used as a container for other HTML elements.
The Element
The <div> element is by default a block element, meaning that it takes all available width, and comes with line breaks before and after.
Example
Lorem Ipsum <div>I am a div</div>
dolor sit amet.
The <div> element has no required attributes, but style, class and id are common.
as a container
The <div> element is often used to group sections of a web page together.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
Center align a element
If you have a <div> element that is not 100% wide, and you want to center-align it, set the CSS margin property to auto.
Example
<style>
div {
width:300px;
margin:auto;
}
</style>
Multiple elements
You can have many <div> containers on the same page.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
<div>
<h2>Oslo</h2>
<p>Oslo is the capital city of
Norway.</p>
<p>Oslo has over 700,000 inhabitants.</p>
</div>
<div>
<h2>Rome</h2>
<p>Rome is the capital city of
Italy.</p>
<p>Rome has over 4 million inhabitants.</p>
</div>
Aligning elements side by side
When building web pages, you often want to have two or more <div> elements side by side, like this:
London
London is the capital city of England.
London has over 9 million inhabitants.
Oslo
Oslo is the capital city of Norway.
Oslo has over 700,000 inhabitants.
Rome
Rome is the capital city of Italy.
Rome has over 4 million inhabitants.
There are different methods for aligning elements side by side, all include some CSS styling. We will look at the most common methods:
Float
The CSS float property was not originally meant to align <div> elements side-by-side, but has been used for this purpose for many years.
The CSS float property is used for positioning and formatting content and allows elements to be positioned horizontally, rather than vertically.
Example
<style>
.mycontainer {
width:100%;
overflow:auto;
}
.mycontainer div {
width:33%;
float:left;
}
</style>
Learn more about float in our CSS float tutorial.
Inline-block
If you change the <div> element's display property from block to inline-block, the <div> elements will no longer add a line break before and after, and will be displayed side by side instead of on top of each other.
Example
<style>
div {
width: 30%;
display:
inline-block;
}
</style>
Flex
The CSS Flexbox Layout Module was introduced to make it easier to design flexible responsive layout structure without using float or positioning.
To make the CSS flex method work, surround the <div> elements with another <div> element and give it the status as a flex container.
Example
<style>
.mycontainer {
display: flex;
}
.mycontainer
> div {
width:33%;
}
</style>
Learn more about flex in our CSS flexbox tutorial.
Grid
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.
Sounds almost the same as flex, but has the ability to define more than one row and position each row individually.
The CSS grid method requires that you surround the <div> elements with another <div> element and give the status as a grid container, and you must specify the width of each column.
Example
<style>
.grid-container {
display: grid;
grid-template-columns: 33% 33% 33%;
}
</style>
Learn more about grid in our CSS grid tutorial.
HTML Tags
Tag
Description
Defines a section in a document (block-level)
Note: For a complete list of all available HTML tags, visit our HTML Tag Reference.
Want to go beyond the notes?
Join CodingNow 2.0's HTML course — live mentorship, real projects, and 100% placement support.
Enroll Now — Free Demo Available
HTML Div – FAQs
Quick answers about learning HTML Div in HTML.
This free note from CodingNow 2.0 explains HTML Div in HTML — concept, syntax and worked code examples you can copy, run and revise before interviews.Yes. Every HTML topic on CodingNow 2.0, including HTML Div, is 100% free with no signup required.With focused practice, most students grasp HTML Div in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.

The <div> element is by default a block element, meaning that it takes all available width, and comes with line breaks before and after.
Example
Lorem Ipsum <div>I am a div</div>
dolor sit amet.
The <div> element has no required attributes, but style, class and id are common.
as a container
The <div> element is often used to group sections of a web page together.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
Center align a element
If you have a <div> element that is not 100% wide, and you want to center-align it, set the CSS margin property to auto.
Example
<style>
div {
width:300px;
margin:auto;
}
</style>
Multiple elements
You can have many <div> containers on the same page.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
<div>
<h2>Oslo</h2>
<p>Oslo is the capital city of
Norway.</p>
<p>Oslo has over 700,000 inhabitants.</p>
</div>
<div>
<h2>Rome</h2>
<p>Rome is the capital city of
Italy.</p>
<p>Rome has over 4 million inhabitants.</p>
</div>
Aligning elements side by side
When building web pages, you often want to have two or more <div> elements side by side, like this:
London
London is the capital city of England.
London has over 9 million inhabitants.
Oslo
Oslo is the capital city of Norway.
Oslo has over 700,000 inhabitants.
Rome
Rome is the capital city of Italy.
Rome has over 4 million inhabitants.
There are different methods for aligning elements side by side, all include some CSS styling. We will look at the most common methods:
Float
The CSS float property was not originally meant to align <div> elements side-by-side, but has been used for this purpose for many years.
The CSS float property is used for positioning and formatting content and allows elements to be positioned horizontally, rather than vertically.
Example
<style>
.mycontainer {
width:100%;
overflow:auto;
}
.mycontainer div {
width:33%;
float:left;
}
</style>
Learn more about float in our CSS float tutorial.
Inline-block
If you change the <div> element's display property from block to inline-block, the <div> elements will no longer add a line break before and after, and will be displayed side by side instead of on top of each other.
Example
<style>
div {
width: 30%;
display:
inline-block;
}
</style>
Flex
The CSS Flexbox Layout Module was introduced to make it easier to design flexible responsive layout structure without using float or positioning.
To make the CSS flex method work, surround the <div> elements with another <div> element and give it the status as a flex container.
Example
<style>
.mycontainer {
display: flex;
}
.mycontainer
> div {
width:33%;
}
</style>
Learn more about flex in our CSS flexbox tutorial.
Grid
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.
Sounds almost the same as flex, but has the ability to define more than one row and position each row individually.
The CSS grid method requires that you surround the <div> elements with another <div> element and give the status as a grid container, and you must specify the width of each column.
Example
<style>
.grid-container {
display: grid;
grid-template-columns: 33% 33% 33%;
}
</style>
Learn more about grid in our CSS grid tutorial.
HTML Tags
Tag
Description
Defines a section in a document (block-level)
Note: For a complete list of all available HTML tags, visit our HTML Tag Reference.
Want to go beyond the notes?
Join CodingNow 2.0's HTML course — live mentorship, real projects, and 100% placement support.
Enroll Now — Free Demo Available
HTML Div – FAQs
Quick answers about learning HTML Div in HTML.
This free note from CodingNow 2.0 explains HTML Div in HTML — concept, syntax and worked code examples you can copy, run and revise before interviews.Yes. Every HTML topic on CodingNow 2.0, including HTML Div, is 100% free with no signup required.With focused practice, most students grasp HTML Div in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
The <div> element is often used to group sections of a web page together.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
Center align a element
If you have a <div> element that is not 100% wide, and you want to center-align it, set the CSS margin property to auto.
Example
<style>
div {
width:300px;
margin:auto;
}
</style>
Multiple elements
You can have many <div> containers on the same page.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
<div>
<h2>Oslo</h2>
<p>Oslo is the capital city of
Norway.</p>
<p>Oslo has over 700,000 inhabitants.</p>
</div>
<div>
<h2>Rome</h2>
<p>Rome is the capital city of
Italy.</p>
<p>Rome has over 4 million inhabitants.</p>
</div>
Aligning elements side by side
When building web pages, you often want to have two or more <div> elements side by side, like this:
London
London is the capital city of England.
London has over 9 million inhabitants.
Oslo
Oslo is the capital city of Norway.
Oslo has over 700,000 inhabitants.
Rome
Rome is the capital city of Italy.
Rome has over 4 million inhabitants.
There are different methods for aligning elements side by side, all include some CSS styling. We will look at the most common methods:
Float
The CSS float property was not originally meant to align <div> elements side-by-side, but has been used for this purpose for many years.
The CSS float property is used for positioning and formatting content and allows elements to be positioned horizontally, rather than vertically.
Example
<style>
.mycontainer {
width:100%;
overflow:auto;
}
.mycontainer div {
width:33%;
float:left;
}
</style>
Learn more about float in our CSS float tutorial.
Inline-block
If you change the <div> element's display property from block to inline-block, the <div> elements will no longer add a line break before and after, and will be displayed side by side instead of on top of each other.
Example
<style>
div {
width: 30%;
display:
inline-block;
}
</style>
Flex
The CSS Flexbox Layout Module was introduced to make it easier to design flexible responsive layout structure without using float or positioning.
To make the CSS flex method work, surround the <div> elements with another <div> element and give it the status as a flex container.
Example
<style>
.mycontainer {
display: flex;
}
.mycontainer
> div {
width:33%;
}
</style>
Learn more about flex in our CSS flexbox tutorial.
Grid
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.
Sounds almost the same as flex, but has the ability to define more than one row and position each row individually.
The CSS grid method requires that you surround the <div> elements with another <div> element and give the status as a grid container, and you must specify the width of each column.
Example
<style>
.grid-container {
display: grid;
grid-template-columns: 33% 33% 33%;
}
</style>
Learn more about grid in our CSS grid tutorial.
HTML Tags
Tag
Description
Defines a section in a document (block-level)
Note: For a complete list of all available HTML tags, visit our HTML Tag Reference.
Want to go beyond the notes?
Join CodingNow 2.0's HTML course — live mentorship, real projects, and 100% placement support.
Enroll Now — Free Demo Available
If you have a <div> element that is not 100% wide, and you want to center-align it, set the CSS margin property to auto.
Example
<style>
div {
width:300px;
margin:auto;
}
</style>
Multiple elements
You can have many <div> containers on the same page.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
<div>
<h2>Oslo</h2>
<p>Oslo is the capital city of
Norway.</p>
<p>Oslo has over 700,000 inhabitants.</p>
</div>
<div>
<h2>Rome</h2>
<p>Rome is the capital city of
Italy.</p>
<p>Rome has over 4 million inhabitants.</p>
</div>
Aligning elements side by side
When building web pages, you often want to have two or more <div> elements side by side, like this:
London
London is the capital city of England.
London has over 9 million inhabitants.
Oslo
Oslo is the capital city of Norway.
Oslo has over 700,000 inhabitants.
Rome
Rome is the capital city of Italy.
Rome has over 4 million inhabitants.
There are different methods for aligning elements side by side, all include some CSS styling. We will look at the most common methods:
Float
The CSS float property was not originally meant to align <div> elements side-by-side, but has been used for this purpose for many years.
The CSS float property is used for positioning and formatting content and allows elements to be positioned horizontally, rather than vertically.
Example
<style>
.mycontainer {
width:100%;
overflow:auto;
}
.mycontainer div {
width:33%;
float:left;
}
</style>
Learn more about float in our CSS float tutorial.
Inline-block
If you change the <div> element's display property from block to inline-block, the <div> elements will no longer add a line break before and after, and will be displayed side by side instead of on top of each other.
Example
<style>
div {
width: 30%;
display:
inline-block;
}
</style>
Flex
The CSS Flexbox Layout Module was introduced to make it easier to design flexible responsive layout structure without using float or positioning.
To make the CSS flex method work, surround the <div> elements with another <div> element and give it the status as a flex container.
Example
<style>
.mycontainer {
display: flex;
}
.mycontainer
> div {
width:33%;
}
</style>
Learn more about flex in our CSS flexbox tutorial.
Grid
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.
Sounds almost the same as flex, but has the ability to define more than one row and position each row individually.
The CSS grid method requires that you surround the <div> elements with another <div> element and give the status as a grid container, and you must specify the width of each column.
Example
<style>
.grid-container {
display: grid;
grid-template-columns: 33% 33% 33%;
}
</style>
Learn more about grid in our CSS grid tutorial.
HTML Tags
Tag
Description
Defines a section in a document (block-level)
Note: For a complete list of all available HTML tags, visit our HTML Tag Reference.
Want to go beyond the notes?
Join CodingNow 2.0's HTML course — live mentorship, real projects, and 100% placement support.
Enroll Now — Free Demo Available
You can have many <div> containers on the same page.
Example
<div>
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
<div>
<h2>Oslo</h2>
<p>Oslo is the capital city of
Norway.</p>
<p>Oslo has over 700,000 inhabitants.</p>
</div>
<div>
<h2>Rome</h2>
<p>Rome is the capital city of
Italy.</p>
<p>Rome has over 4 million inhabitants.</p>
</div>
Aligning elements side by side
When building web pages, you often want to have two or more <div> elements side by side, like this:
London
London is the capital city of England.
London has over 9 million inhabitants.
Oslo
Oslo is the capital city of Norway.
Oslo has over 700,000 inhabitants.
Rome
Rome is the capital city of Italy.
Rome has over 4 million inhabitants.
There are different methods for aligning elements side by side, all include some CSS styling. We will look at the most common methods:
Float
The CSS float property was not originally meant to align <div> elements side-by-side, but has been used for this purpose for many years.
The CSS float property is used for positioning and formatting content and allows elements to be positioned horizontally, rather than vertically.
Example
<style>
.mycontainer {
width:100%;
overflow:auto;
}
.mycontainer div {
width:33%;
float:left;
}
</style>
Learn more about float in our CSS float tutorial.
Inline-block
If you change the <div> element's display property from block to inline-block, the <div> elements will no longer add a line break before and after, and will be displayed side by side instead of on top of each other.
Example
<style>
div {
width: 30%;
display:
inline-block;
}
</style>
Flex
The CSS Flexbox Layout Module was introduced to make it easier to design flexible responsive layout structure without using float or positioning.
To make the CSS flex method work, surround the <div> elements with another <div> element and give it the status as a flex container.
Example
<style>
.mycontainer {
display: flex;
}
.mycontainer
> div {
width:33%;
}
</style>
Learn more about flex in our CSS flexbox tutorial.
Grid
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.
Sounds almost the same as flex, but has the ability to define more than one row and position each row individually.
The CSS grid method requires that you surround the <div> elements with another <div> element and give the status as a grid container, and you must specify the width of each column.
Example
<style>
.grid-container {
display: grid;
grid-template-columns: 33% 33% 33%;
}
</style>
Learn more about grid in our CSS grid tutorial.
HTML Tags
Tag
Description
Defines a section in a document (block-level)
Note: For a complete list of all available HTML tags, visit our HTML Tag Reference.
When building web pages, you often want to have two or more <div> elements side by side, like this:
London
London is the capital city of England.
London has over 9 million inhabitants.
Oslo
Oslo is the capital city of Norway.
Oslo has over 700,000 inhabitants.
Rome
Rome is the capital city of Italy.
Rome has over 4 million inhabitants.
There are different methods for aligning elements side by side, all include some CSS styling. We will look at the most common methods:
Float
The CSS float property was not originally meant to align <div> elements side-by-side, but has been used for this purpose for many years.
The CSS float property is used for positioning and formatting content and allows elements to be positioned horizontally, rather than vertically.
Example
<style>
.mycontainer {
width:100%;
overflow:auto;
}
.mycontainer div {
width:33%;
float:left;
}
</style>
Learn more about float in our CSS float tutorial.
Inline-block
If you change the <div> element's display property from block to inline-block, the <div> elements will no longer add a line break before and after, and will be displayed side by side instead of on top of each other.
Example
<style>
div {
width: 30%;
display:
inline-block;
}
</style>
Flex
The CSS Flexbox Layout Module was introduced to make it easier to design flexible responsive layout structure without using float or positioning.
To make the CSS flex method work, surround the <div> elements with another <div> element and give it the status as a flex container.
Example
<style>
.mycontainer {
display: flex;
}
.mycontainer
> div {
width:33%;
}
</style>
Learn more about flex in our CSS flexbox tutorial.
Grid
The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning.
Sounds almost the same as flex, but has the ability to define more than one row and position each row individually.
The CSS grid method requires that you surround the <div> elements with another <div> element and give the status as a grid container, and you must specify the width of each column.
Example
<style>
.grid-container {
display: grid;
grid-template-columns: 33% 33% 33%;
}
</style>
Learn more about grid in our CSS grid tutorial.
HTML Tags
| Tag | Description |
|---|---|
| Defines a section in a document (block-level) |
Note: For a complete list of all available HTML tags, visit our HTML Tag Reference.
Want to go beyond the notes?
Join CodingNow 2.0's HTML course — live mentorship, real projects, and 100% placement support.
Enroll Now — Free Demo AvailableHTML Div – FAQs
Quick answers about learning HTML Div in HTML.