Skip to main content
D
HTML
HTML Div Element

HTML Div Element

The HTML div element acts as a generic container.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

HTML provides the `
` tag to group elements together. It holds no semantic meaning on its own. Developers use it to apply CSS styles or structure sections of a page.

Syntax

Syntax
1<!-- div syntax -->
2<div class="container">
3  <p>Grouped content</p>
4</div>

Example

Example
1<!-- this defines a div -->
2<!DOCTYPE html>
3<html lang="en">
4  <head>
5    <meta charset="UTF-8">
6    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7    <title>Div Container</title>
8  </head>
9  <body>
10    <div id="main">
11      <h2>Section</h2>
12      <p>Content.</p>
13    </div>
14  </body>
15</html>

Try it Yourself

Hands-on Practice
Modify the code below to see how it affects the output. This is the best way to learn!
Interactive Editor
1234567891011121314151617181920
Live Preview

Key Points

  • The `
    ` tag holds no semantic meaning.
  • The `
    ` tag creates a block-level container.
  • Classes and IDs style the container.
  • Semantic tags replace `
    ` when possible.

Up Next

Continue your journey with the next topic.

Go to HTML Classes