HTML5 Div Span
HTML
What are <div>
and <span>
in HTML5?
They are generic container elements used to group other HTML content.
They have no semantic meaning on their own — they’re purely structural, used mainly for styling with CSS or scripting with JavaScript.
<div>
– Block-level container
Definition:
- A block-level element.
- Starts on a new line and stretches to the full width of its parent container.
Use cases:
- Group sections of a page.
- Create layouts (columns, rows, wrappers).
Apply styles or scripts to an entire block of content.
<span>
– Inline container
Definition:
- An inline element.
- Does not start on a new line.
- Only takes up as much width as its content.
Use cases:
Style or manipulate small pieces of text inside other elements.
Comparison Table
Tag | Type | Starts on new line? | Typical use |
---|---|---|---|
<div> | Block-level | Yes | Grouping larger blocks (like sections, layouts) |
<span> | Inline | No | Wrapping small parts of text or inline elements |