The HTML <div> tag
The HTML <div> element is a generic block-level container with no semantic meaning. Use it to group content for styling with CSS or scripting with JavaScript — but choose a semantic element such as <section>, <article> or <nav> whenever one fits.
Overview
The <div> (content division) element is the generic block-level container. It carries no meaning of its own — it exists purely to group elements so you can lay them out with CSS or target them from JavaScript.
As a block-level element it starts on a new line and fills the available width by default. It is the workhorse of CSS layout: a <div> with display: flex or display: grid arranges its children, and a class provides the styling hook.
Because it is meaningless, reach for it last. If the content is a self-contained article, a thematic section, a navigation block or complementary content, use <article>, <section>, <nav> or <aside> — they convey structure to browsers, search engines and assistive technology.
Syntax
<div class="card">
<h2>Title</h2>
<p>Some content.</p>
</div>
Example
<div style="border:1px solid #e2e8f0; border-radius:10px; padding:16px; max-width:320px;">
<h3 style="margin:0 0 6px;">Card title</h3>
<p style="margin:0; color:#475569;">A div grouping a heading and text into a styled card.</p>
</div>
Best practices
- Prefer semantic elements (<section>, <article>, <nav>, <main>) when they fit; use
<div>only for generic grouping. - Hook styling with a class rather than inline styles.
- Use
<div>elements as flexbox or grid containers for layout. - Never make a bare
<div>clickable on its own — use a <button> or <a>, or add a role, tabindex and keyboard handlers. - Keep nesting shallow and purposeful to avoid "div soup."
Accessibility
A <div> has no implicit ARIA role, so assistive technology treats it as invisible structure. That is perfect for layout, but it has two consequences:
- Do not build interactive controls from a bare
<div>. A click handler alone cannot be reached by keyboard and is not announced — use a native <button>, or addrole, tabindex="0" and key handlers. - For page regions, prefer landmark elements such as <nav> and <main> so screen-reader users can jump between them.
Frequently asked questions
What is the <div> element used for?
What is the difference between <div> and <span>?
<div> is block-level (it starts on a new line and fills the width); <span> is inline (it flows within a line of text). Both are generic and meaningless.When should I use a <div> instead of a semantic element?
Is using too many <div>s bad?
Does the <div> element affect SEO?
How do I center a div?
display: flex; justify-content: center; align-items: center;. To center a fixed-width block horizontally, set margin: 0 auto; on the div. CSS Grid also works with display: grid; place-items: center;.How do I create a div in HTML?
<div>…</div>. Add a class to style it with CSS or target it from JavaScript.