CSS Display Types
CSS
What is display in CSS?
The display property defines how an element is displayed on the page — whether it takes up the whole line, can sit next to others, or behaves like a container.
CSS Display Types
1. display: block
- Takes up the full width.
- Starts on a new line.
- You can set width, height, margin, padding.
2. display: inline
- Sits next to other elements.
- Ignores width and height.
- Respects padding and margin only horizontally.
3. display: inline-block
- Like inline, but respects width and height.
- Best of both: flows inline, but can be styled like a block.
4. display: none
- Completely hides the element from the page (not even space left behind).
5. display: flex
- Turns the element into a flex container.
- Great for layouts, aligning items horizontally or vertically.
6. display: grid
- Turns the element into a grid container.
- Useful for creating 2D layouts (rows and columns).
7. display: inline-flex / inline-grid
- Same as flex or grid, but behaves like an inline element.