The <div> element
The <div> tag is a generic block-level container in HTML with no semantic meaning of its own. It’s used to group other elements together so you can style them with CSS or manipulate them with JavaScript — most often as a layout wrapper for a section of a page.
Last updated: October 3, 2026
Quick facts
| Category | Flow content, palpable content |
| Content model | Flow content — can contain any other flow elements or text |
| Tag omission | Neither the start nor end tag can be omitted |
| Permitted parents | Any element that accepts flow content |
| DOM interface | HTMLDivElement |
Syntax
Live example
Edit the code below and watch the preview update instantly.
Attributes
| Attribute | Description |
|---|---|
| — | <div> has no attributes of its own — only the global attributes shared by every HTML element (id, class, style, title, data-*, etc.). |
Common examples
Group content so you can style it together
Wrap related elements in a <div> with a class, then style the whole group with CSS. This is the classic way to build a “card”.
Build a two-column layout with flexbox
Most page layouts are rows and columns of divs arranged with CSS flexbox or grid.
How to center a div
One of the most searched HTML questions. The simplest modern answer is CSS grid with place-items: center on the parent.
<div> vs <span>
Both are generic containers with no meaning of their own, so the choice comes down to how they sit on the page. A <div> is a block element: it starts on a new line and stretches to the full width available. A <span> is inline: it flows inside a line of text and is only as wide as its content.
Use a div to group whole sections — cards, columns, wrappers for layout — and a span to style or target a few words inside a sentence. If the content has a real meaning, reach for a semantic element before either of them.
| <div> | <span> | |
|---|---|---|
| Display | Block (new line, full width) | Inline (flows with text) |
| Typical use | Layout, grouping sections | Styling words inside text |
| Can contain | Almost any content | Inline content only |
Common mistakes to avoid
- “Divitis”: using
<div>for everything. If a part of the page has a meaning, use the semantic element instead: <header>, <nav>, <main>, <article> or <footer>. - Making a div act as a button. A clickable div can’t be reached with the Tab key or activated with Enter. Use a real <button>.
- Putting a div inside a paragraph or span. A
<p>can only hold inline content, so the browser closes the paragraph early and your layout breaks. - Losing track of closing tags. Deeply nested divs with a missing
</div>are a common cause of broken layouts. Indent your code, or run it through the HTML formatter to spot the problem.
Accessibility & SEO tips
- A
<div>has no meaning for screen readers or search engines; they simply read the text inside it. Semantic elements give both of them a map of your page. - Use landmark elements (
<header>,<nav>,<main>,<footer>) for the big regions, and divs for styling wrappers inside them. - Only add ARIA roles to a div when no native element fits — native HTML elements come with keyboard support and meaning built in.
Browser support
Supported in every browser, including Chrome, Edge, Firefox, Safari and their mobile versions — it has been part of HTML since the very first versions.
Tutorials: How to add a background image, How to center a div