Skip to main content

CSS Display Property Guide

Complete visual reference for all CSS display values.
Click any value to copy the CSS to your clipboard.

Basic Display Values

ValueCSSDescription
blockdisplay: block;Takes full width, stacks vertically
inlinedisplay: inline;Flows with text, ignores width/height
inline-blockdisplay: inline-block;Inline but accepts width/height
nonedisplay: none;Removes element from layout entirely

Basic Display Values - Visual Examples

display: block

Each block element takes full width and stacks vertically

Block 1 (full width)
Block 2 (full width)
Block 3 (full width)

display: inline

Inline elements flow with text, width/height are ignored

This is text with inline 1 and inline 2 elements that flow with the text.

display: inline-block

Inline-block flows inline but respects width/height

24x1632x1220x20

display: none

Element is completely removed from the layout

Visible
Visible

The middle element has display: none - notice there's no gap

Flex Display

ValueCSSDescription
flexdisplay: flex;Creates a flex container (block-level)
inline-flexdisplay: inline-flex;Creates an inline flex container

Flex Display - Visual Examples

display: flex

Creates a block-level flex container - children become flex items

Flex Item 1
Flex Item 2
Flex Item 3

The flex container takes full width (block-level)

display: inline-flex

Creates an inline-level flex container

Text before 123 text after

The inline-flex container flows with surrounding text

Grid Display

ValueCSSDescription
griddisplay: grid;Creates a grid container (block-level)
inline-griddisplay: inline-grid;Creates an inline grid container

Grid Display - Visual Examples

display: grid

Creates a block-level grid container for 2D layouts

1
2
3
4
5
6

Grid container with 3 columns

display: inline-grid

Creates an inline-level grid container

Text before 1234 text after

The inline-grid container flows with surrounding text

Other Display Values

ValueCSSDescription
contentsdisplay: contents;Children become direct children of parent
flow-rootdisplay: flow-root;Creates new block formatting context
tabledisplay: table;Behaves like <table> element
table-rowdisplay: table-row;Behaves like <tr> element
table-celldisplay: table-cell;Behaves like <td> element

Other Display Values - Visual Examples

display: contents

The element's box disappears, children become direct children of parent

Item 1
Nested A
Nested B
Item 2

The wrapper with display: contents is invisible - its children (A, B) appear as siblings

display: flow-root

Creates a new block formatting context - useful for containing floats

Without flow-root (float escapes):

Floated

Container collapses

With flow-root (float contained):

Floated

Container contains float

display: table, table-row, table-cell

Create table layouts without using table elements

Cell 1
Cell 2
Cell 3
Cell 4
Cell 5
Cell 6

Block vs Inline vs Inline-Block Comparison

Propertyblockinlineinline-block
Takes full widthYesNoNo
Starts on new lineYesNoNo
Respects width/heightYesNoYes
Respects top/bottom marginYesNoYes
Respects top/bottom paddingYesVisual only*Yes
Can sit next to other elementsNoYesYes

* Inline elements can have padding, but it won't affect layout/push other elements away

Visual Comparison:

block elements:

Block takes full width
Each on new line

inline elements:

Inline 1Inline 2Inline 3

inline-block elements with width/height:

100x64
128x48
80x80

Common Patterns

Hiding Elements

display: none

Removes from layout, not accessible to screen readers

visibility: hidden

Hidden but still takes up space in layout

opacity: 0

Invisible but clickable, takes space, can animate

A
B
C

Responsive Display

Change display at different breakpoints:

.element {
  display: none;
}

@media (min-width: 768px) {
  .element {
    display: block;
  }
}

Centering with Flex

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
Centered

Grid Layout

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
1
2
3

About the Display Property

The display property is one of the most important CSS properties for controlling layout. It determines how an element generates boxes and how it participates in the layout.

Modern layouts typically use display: flex for one-dimensional layouts (rows or columns) and display: grid for two-dimensional layouts (rows and columns simultaneously).

Understanding the difference between block, inline, and inline-block is fundamental to mastering CSS layout.