June 26, 2025
O. Wolfson
CSS display is one of the most important properties in web layout. It determines how elements appear and interact with other elements on the page. Here's a breakdown of the most commonly used display types and how they affect layout behavior:
display: block;
blockBehavior:
Examples:
<div>, <section>, <p>
Use case: Structuring large containers and layout sections.
inlineBehavior:
Examples:
<span>, <a>, <strong>
Use case: Styling small pieces of content within text.
Example: Highlight a word in a sentence:
html<div style="font-size: 16px;">
The quick <span style="display: inline; background: yellow;">brown</span> fox
jumps over the lazy dog.
</div>
The quick brown fox jumps over the lazy dog.
inline-blockBehavior:
inline (flows with text)Use case: Buttons, badges, icons with spacing but still inline with text.
Example 1: Styled badge inside text:
html<div style={{ fontSize: "16px" }}>
Your order status:{" "}
<span
style={{
display: "inline-block",
background: "#0d9488",
color: "white",
padding: "2px 6px",
borderRadius: "4px",
}}
>
Delivered
</span>
</div>
Your order status:
Delivered
Example 2: 3 items side by side (without flex or grid):
html<div style={{ fontSize: 0 }}>
<div style={{ display: "inline-block", width: "100px", height: "80px", background: "#60a5fa", marginRight: "10px" }}></div>
<div style={{ display: "inline-block", width: "100px", height: "80px", background: "#34d399", marginRight: "10px" }}></div>
<div style={{ display: "inline-block", width: "100px", height: "80px", background: "#f87171" }}></div>
</div>
Example 3: Button-style elements:
html<div style={{ fontSize: "16px" }}>
<span
style={{
display: "inline-block",
background: "#3b82f6",
color: "white",
padding: "16px",
paddingTop: "14px",
paddingLeft: "18px",
paddingRight: "18px",
borderRadius: "6px",
cursor: "pointer",
}}
>
Click Me
</span>
</div>
Click Me
flexBehavior:
Use case: One-dimensional layouts (e.g. nav bars, card layouts, toolbars)
css.container {
display: flex;
justify-content: space-between;
align-items: center;
}
gridBehavior:
Use case: Two-dimensional layouts (e.g. dashboards, complex forms)
css.container {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 1rem;
}
noneBehavior:
Use case:
Temporarily hiding elements
(Use visibility: hidden if you want to hide but keep layout space)
| Display Type | Layout Style | Accepts Width/Height? | Starts New Line? |
|---|---|---|---|
block | Full-width box | ✅ | ✅ |
inline | Text flow | ❌ | ❌ |
inline-block | Inline + box |
| ✅ |
| ❌ |
flex | Flex container | ✅ | Depends on layout |
grid | Grid container | ✅ | Depends on layout |
none | Removed from layout | ❌ | ❌ |