# `<div>`

> The `<div>` HTML element is a generic container used to group and style content.

## When should I use a `<div>` instead of a semantic element?

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.

- Topic: Basics
- Type: tag
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 1+, Safari iOS 1+

## Example

Wrong:

```html
<div class="btn" onclick="save()">
  Save
</div>
```

Right:

```html
<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.

## Related cards

- [`<span>`](https://wonderium.dev/html/span.md)
- [`<section>`](https://wonderium.dev/html/section.md)
- [Semantics](https://wonderium.dev/html/semantics.md)
- [generic](https://wonderium.dev/a11y/generic.md)
- [`<button>`](https://wonderium.dev/html/button.md)

---

- Level: [HTML](https://wonderium.dev/html.md)
- HTML version: https://wonderium.dev/html/div
- Last updated: 2026-11-25
