HTML Reference ยท Text Content
The <div> element
Reference for the HTML <div> element: a generic block container for styling and layout, when to prefer semantic elements, use inside <dl>, technical details.
The <div> element is a generic container for flow content. It carries no meaning: it simply groups elements so you can style them, lay them out or target them from JavaScript. Use it when no element with a real meaning fits.
HTML
<div class="card"> <h2>Weekly digest</h2> <p>Three new lessons this week.</p> </div>
Try it
Attributes
This element has no attributes of its own. It accepts the global attributes; class, id, style and data-* are the ones you will use most.
Usage notes
- Reach for semantics first. If the content is a navigation block, an article, a sidebar, a header or a footer, use
<nav>,<article>,<aside>,<header>or<footer>. Use<div>for the wrappers that exist only for styling. - Block vs inline.
<div>is the block-level counterpart of<span>. Both are meaningless; pick the one whose default display matches what you need. - Grouping in description lists. A
<div>may be a direct child of a<dl>when it wraps one complete group of<dt>and<dd>elements. - Not a button. A clickable
<div>can't be reached with the keyboard and isn't announced as a control. Use<button>or<a>instead. - Avoid "div soup". Deep stacks of nested divs make markup hard to read; modern CSS (Flexbox and Grid) usually needs far fewer wrappers.
Technical summary
| Content categories | Flow content, palpable content |
| Permitted content | Flow content; as a child of <dl>, one or more <dt> followed by one or more <dd>, optionally mixed with script-supporting elements |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts flow content, or a <dl> |
| Implicit ARIA role | generic |
| DOM interface | HTMLDivElement |
| Default display | block |
Browser support
Supported in every browser.
Related
<span>โ the inline generic container<section>and<article>โ meaningful containers- Lesson: Div and Span
- Lesson: Block and Inline Elements
- Lesson: Semantic Elements
- Lesson: Page Layout