div and span — Generic Containers
When no semantic HTML tag fits, use <div> for block-level grouping or <span> for inline text grouping. They have no meaning on their own — they exist purely as CSS and JavaScript hooks.
div — Block Container
<!-- div groups block-level elements --> <div class="card"> <img src="photo.jpg" alt="Profile"/> <h3>Shiva Saini</h3> <p>Founder, CIWeb</p> </div> <div class="card"> <img src="photo2.jpg" alt="Profile"/> <h3>Team Member</h3> <p>Developer</p> </div>
Founder, CIWeb
Developer
span — Inline Container
<!-- span targets a specific word/phrase within text --> <p> This course has <span style="color:red;font-weight:bold">22 lessons</span> and a real certificate. </p> <p> Price: <span class="price">FREE</span> — No credit card needed. </p>
This course has 22 lessons and a real certificate.
Price: FREE — No credit card needed.
Before using a div, ask: "Is there a more meaningful tag?" Navigation? Use nav. Blog post? Use article. Page section? Use section. Header area? Use header. div should be the last resort, not the first choice.
The div element was created in HTML as a "generic flow container" — a blank box with no semantic implication. It was designed to be styled by CSS. Overusing div (called div soup) makes code hard to read and hurts accessibility.