The `block` display mode makes elements occupy the full width of their container.
The `inline` display mode allows elements to flow inline with text.
The `inline-block` display mode combines `inline` and `block` behaviors, allowing elements to flow inline but maintain block-level dimensions.
The `flex` display mode creates a flexible layout container.
The `inline-flex` display mode allows flexbox layouts to flow inline with text or other elements.
The `grid` display mode creates a grid-based layout.
The `none` display mode hides the element from the layout.
The box above is hidden using `display: none`.
The `visibility` property controls whether an element is visible, hidden, or collapses (for table elements).
| test | tested |
|---|---|
| test | test |
The second box is hidden using `visibility: hidden`, but it still occupies space. The third box collapses as it is a table element.
| Property | Option | Behavior |
|---|---|---|
| display | block | Full-width, block-level layout. |
| display | inline | Flows inline with text, no block-level behavior. |
| display | inline-block | Flows inline but retains block-level dimensions. |
| display | flex | Creates a flexible container for child elements. |
| display | inline-flex | Inline layout with flexible child alignment. |
| visibility | visible | Element is visible and occupies space. |
| visibility | hidden | Element is invisible but occupies space. |
| visibility | collapse | Element is hidden and collapses (for tables). |
Different display types affect how padding and margin behave.
Below is a visual demo and an explanation table for common display types.
Inline elements only respect horizontal padding and margins. Vertical padding and margins don't significantly affect the layout.
Inline Element Inline ElementBlock elements respect both horizontal and vertical padding and margins.
Inline-block elements respect padding and margins in all directions while flowing inline.
Inline-Block Inline-BlockFlex containers and items respect padding and margins fully. Layout behavior depends on the flex container's properties.
Grid containers and items respect padding and margins fully.
Elements with display: none are not rendered, so padding and margin have no effect.
The box above is hidden and doesn't take up space in the layout.
| Display Type | Effect on Padding | Effect on Margin |
|---|---|---|
| inline | Horizontal only | Horizontal only |
| block | Full (all directions) | Full (all directions) |
| inline-block | Full (all directions) | Full (all directions) |
| flex | Full (all directions) | Full (all directions) |
| grid | Full (all directions) | Full (all directions) |
| none | No effect (hidden) | No effect (hidden) |