Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. HTML Tag Dictionary
  3. <div>

<div>

The div element is a generic block-level container in HTML. It carries no inherent meaning on its own and is used to group other elements together for layout and styling purposes.

Syntax

<div>content</div>

<!-- Use class or id to connect with CSS and JavaScript -->
<div class="container">
  <div id="header">Header</div>
  <div id="main">Main content</div>
</div>

Main Attributes

AttributeDescription
classSpecifies one or more CSS classes. Multiple classes can be separated by spaces.
idSpecifies a unique identifier for the element. Must not be duplicated within the same page.
styleApplies inline CSS styles directly to the element.
data-*A custom data attribute. Used to store and retrieve data from JavaScript.

Sample Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <style>
    .card {
      border: 1px solid #ccc;
      padding: 16px;
      margin: 8px;
      border-radius: 4px;
    }
    .card-title {
      font-weight: bold;
      font-size: 1.2em;
    }
    .card-body {
      color: #555;
    }
  </style>
</head>
<body>

  <!-- Create a card component using div -->
  <div class="card">
    <div class="card-title">Title</div>
    <div class="card-body">The card body text goes here.</div>
  </div>

  <div class="card">
    <div class="card-title">Second Card</div>
    <div class="card-body">Nesting div elements lets you build complex layouts.</div>
  </div>

</body>
</html>

Result

Two bordered cards are displayed stacked vertically. Inside each card, a title and body text are grouped together.

<!-- The browser renders the output like this -->
┌─────────────────────────┐
│ Title                   │
│ The card body text...   │
└─────────────────────────┘
┌─────────────────────────┐
│ Second Card             │
│ Nesting div elements... │
└─────────────────────────┘

Notes

The div element is one of the most commonly used elements in HTML. It behaves as a block-level element, meaning it starts on a new line and stretches to fill the full width of its parent by default. It serves as a general-purpose "container" for grouping elements to apply CSS styles or manipulate them with JavaScript.

However, for meaningful document structure, prefer appropriate semantic elements. Use header for page headers, nav for navigation, main for the main content, and footer for footers. Reserve div for generic grouping that does not fit any semantic element.

To group inline content, use span — the inline generic container — instead of div.

Browser Compatibility

Chrome Chrome
49+
Supported in all versions
Firefox Firefox
57+
Supported in all versions
Safari Safari
18+
Supported in all versions
Edge Edge
80+
11 or earlier ×
IE IE
11 or earlier ×
Opera Opera
48+
14 or earlier ×
iOS Safari iOS Safari
18+
Supported in all versions
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .