- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <div> Tag
HTML Tags
HTML <div> Tag
The div tag is a plain box. It means nothing by itself; it groups other elements so you can style them or lay them out together. It is the most used tag on the web, and often used where a more meaningful tag would be better.
That is the rule of thumb: if the box is a header, a navigation menu, an article or a footer, use those semantic tags. Use <div> for everything else, like wrappers for layout and styling.
Syntax
html
<div>
Content goes here...
</div>There are no special attributes, only the global ones. class is the one you will use most, to connect the div to CSS.
Example
html
<!DOCTYPE html>
<html>
<head>
<title>DIV Example</title>
<style>
.box {
width: 200px;
padding: 20px;
background-color: lightblue;
border: 2px solid #333;
margin-bottom: 20px;
}
</style>
</head>
<body>
<h2>DIV Example</h2>
<div class="box">
This is a content box inside a DIV.
</div>
<div class="box">
Another DIV with the same CSS class.
</div>
</body>
</html>Two light blue boxes with a border appear, one below the other. Both use the same box class, so they share the same look.
Where divs belong
- Wrappers for layout: a container with Flexbox or Grid inside.
- Cards and boxes that have no more specific meaning.
- Groups that JavaScript needs to show, hide or move together.
Comparing it with its inline cousin is covered in HTML Div & Span.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Good to know
HTML <div> Tag exercises
Group for styling
Make a container with the class panel that holds two paragraphs: One and Two.
Result
