<div>

Term side of the Card.
Topic: Basics
Unit title: <div>
Categories: Tag
Explanation side of the Card

Explanation: The generic container element used to group together other elements. It has no specific meaning or styling by default, making it flexible for organizing content and applying styles or scripts to a section of a webpage.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wronghtml
<div class="btn" onclick="save()">
  Save
</div>
Righthtml
<button type="button" onclick="save()">
  Save
</button>

<button> gets focus, Enter and Space key support and the button role for free.

Common mistakes

  • Making a <div> clickable, which is unreachable by keyboard and silent for screen readers.
  • Wrapping everything in extra <div> layers that add no styling.

Key points

  • <div> is used only for layout or styling groups when no semantic element fits.
  • Interactive controls are <button> or <a>, not a <div> with a click handler.
  • Page regions use <header>, <nav>, <main> and <footer> instead of <div class="header">.

Interview questions

What is the difference between <div> and <span>?

<div> is a block-level container for grouping larger content, while <span> is an inline container for a part of text.

Is <div> bad for SEO?

No, but it carries no meaning, so semantic elements give search engines and assistive tech more context.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy