<div> is the abbreviation for "division" in HTML, meaning a section. It's a box that has no meaning on its own: you put text, images, buttons, or other divs inside it, then style this box however you want with CSS. It's the most basic way to group sections on a page.
div is a block element. This means by default it takes up the full width of a line, and any content after it starts on the next line.
The simplest usage
<div>
<h2>About Me</h2>
<p>I develop web and mobile software.</p>
</div>
Nothing changes in appearance in the browser; div is an invisible frame. Its real work begins when you give it a class and style it with CSS:
<div class="card">
<h2>About Me</h2>
<p>I develop web and mobile software.</p>
</div>
<style>
.card { padding: 20px; border-radius: 12px; background: #f4ead6; }
</style>
Nested div usage
On real pages, divs are usually nested: an outer container, rows inside it, cards inside those. For example, two cards side by side:
<div class="row">
<div class="card">Website</div>
<div class="card">Mobile app</div>
</div>
<style>
.row { display: flex; gap: 16px; }
.card { flex: 1; padding: 20px; background: #f4ead6; border-radius: 12px; }
</style>
Here the outer div handles the layout (side-by-side arrangement), and the inner ones carry the content. The rule is simple: each div should do one job. Adding divs "just in case" makes code unreadable.
What goes inside a div?
Almost anything: headings, paragraphs, images, forms, lists, even embedded videos from other pages. One thing to watch: you can't put a div inside a <p> tag. The browser will close the paragraph before the div, breaking your layout.
div or semantic tag?
HTML5 brought tags that give meaning to sections:
<header>: the top of a page or section<nav>: navigation menu<main>: the main content of a page<section>: a section with a heading<article>: self-contained content (blog post, product card)<footer>: the bottom section
These help both Google and screen readers understand your page better. My rule is this: if a section has meaning, use the semantic tag; if you just need a box for layout, use div. On this site's code, the menu is <nav>, posts are <article>; the rows where cards are arranged are divs.
The difference between div and span
Both are meaningless boxes. The difference is in placement: div is a block element that takes up the full line; <span> is inline and flows with text. Use span to highlight a single word in a paragraph, use div to group a section.
<p>Price: <span class="highlight">1,500 TL</span></p>
Common mistakes
- Unclosed div: Every
<div>needs a</div>. Forgetting one shifts the rest of the page. Code editors' matching tag feature saves the day here. - Div soup: Wrapping everything in divs. The semantic tags above both simplify code and boost SEO.
- Building layout in HTML: Instead of adding empty divs for spacing, use CSS's
margin,padding, andgap. - Clickable div: If you want something clickable, use
<button>or<a>instead of div. It becomes keyboard-accessible and screen readers recognize it.
In summary
div is HTML's most basic and most used tag: an invisible box that groups content. It gets its power from CSS; when used in balance with semantic tags, it creates clean pages that search engines love.
If you have a website or app idea and wonder "how do I build this", you can check out what I've made on the services page or write to me directly.
ASILTECHSOFT