CSS display Property Explained
What the CSS display property does, with an example.
Published November 3, 2026
The CSS display property sets how an element generates boxes: block, inline, inline-block, flex, grid or none. It is the most fundamental layout property.
How it works
Block elements start on a new line and fill the width; inline elements flow within text and ignore width/height; inline-block flows inline but accepts size.
flex and grid turn an element into a layout container for its children; none removes it from the layout entirely.
Values and effects
display: block; → new line, full width
display: inline; → flows in text
display: inline-block; → inline with width/height
display: flex; → flexbox container
display: grid; → grid container
display: none; → removed from layout
Practical examples
Centre with flex
.box { display: flex; justify-content: center; align-items: center; }Hide an element
.hidden { display: none; }Inline list
li { display: inline-block; margin-right: 1rem; }Common mistakes
- Using display: none when you need to keep space (use visibility: hidden).
- Setting width on inline elements and wondering why nothing happens.
- Forgetting display: contents exists to remove a wrapper box.
Key takeaways
- display in one line: The CSS display property sets how an element generates boxes: block, inline, inline-block, flex, grid or none.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
display:none vs visibility:hidden?
none removes the element from layout; hidden keeps its space but makes it invisible.
Is display supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.