📺 CSS display
: Control How Elements Appear and Behave
The CSS display
property is one of the most important in web design. It controls how an HTML element is rendered on the page, determining whether it acts like a block, inline, flex container, grid, or even disappears completely.
🧾 What is display
?
display
defines the display behavior of an element, affecting its box generation, layout rules, and how it interacts with other elements.
🧬 Syntax
selector {
display: <value>;
}
🔑 Common Display Values
Value | Description | Example Use Case |
---|---|---|
block | Element takes full width, starts on a new line | <div> , <p> , <h1> |
inline | Element flows inline with text, width & height ignored | <span> , <a> |
inline-block | Inline flow but accepts width and height | Buttons or custom inline containers |
none | Element is not rendered (removed from layout) | Hide elements without deleting HTML |
flex | Defines a flex container for flexible layouts | Responsive row or column layouts |
inline-flex | Like flex, but behaves like an inline element | Small inline flexible containers |
grid | Defines a grid container for 2D layouts | Complex grid-based page designs |
inline-grid | Inline version of grid | Smaller grid containers in text flows |
table , table-row , table-cell | Mimics table elements | Custom table layouts without HTML <table> |
list-item | Behaves like a list item with a marker | <li> elements |
🎯 Examples
1. Block vs Inline
div {
display: block;
background: lightblue;
}
span {
display: inline;
color: red;
}
div
takes full width and starts a new line; span
flows inline with text.
2. Creating a Flexbox container
.container {
display: flex;
gap: 20px;
}
Allows child elements to be arranged in a row or column with flexible sizing.
3. Hiding elements
.hidden {
display: none;
}
Completely removes the element from the document flow and visual rendering.
🧠 How It Works
display
influences the box model of elements.block
elements create block boxes;inline
elements create inline boxes.- Modern layouts heavily use
flex
andgrid
values for powerful responsive designs. - Changing
display
can drastically alter page structure without changing HTML.
🛠️ Tips & Best Practices
- Use
display: none
carefully — hidden content is not accessible to screen readers or keyboard navigation. - Prefer
inline-block
if you want inline elements with controllable size. - Use
flex
for one-dimensional layouts (rows or columns). - Use
grid
for two-dimensional layouts. - Reset unwanted default styles by setting
display
explicitly (e.g.,<ul>
defaults toblock
).
✅ Browser Support
Supported universally in all browsers, including older versions:
- ✅ Chrome
- ✅ Firefox
- ✅ Safari
- ✅ Edge
- ✅ Internet Explorer 8+ (with limited support for flex and grid in older IE)
🔚 Conclusion
The CSS display
property is the backbone of layout design on the web. Mastering it lets you control how elements appear, flow, and interact — from simple inline text to complex responsive grids.