Tailwind CSS Handbook v4.3

Display

Control how an element generates boxes with block, inline, flex, grid, hidden and the rest — the first decision in every layout.

display decides what kind of box an element creates and how its children are laid out. Almost every layout problem starts here.

Overview#

Loading preview…

Reference#

UtilityCSSUse for
blockdisplay: blockFull-width boxes, stacked children
inlinedisplay: inlineText-level elements; ignores width/height
inline-blockdisplay: inline-blockFlows inline but accepts width, height and vertical padding
flexdisplay: flexOne-dimensional layout
inline-flexdisplay: inline-flexA flex container that sits inside a line of text
griddisplay: gridTwo-dimensional layout
inline-griddisplay: inline-gridGrid that flows inline
flow-rootdisplay: flow-rootContains floats and stops margin collapse
contentsdisplay: contentsRemoves the box, promoting children to the parent's layout
table, table-row, table-celldisplay: table*Emulating table layout on non-table elements
list-itemdisplay: list-itemElements that should render a marker
hiddendisplay: noneRemove from layout and the accessibility tree

When to use which#

block vs inline-block vs inline#

  • inline ignores width, height and vertical margin. Padding renders but does not push surrounding lines apart.
  • inline-block respects all box properties while still sitting in the text flow — good for badges and buttons inside a paragraph.
  • block takes the full available width and starts a new line.
Loading preview…

flex vs grid#

flexgrid
DimensionsOne (a row or a column)Two (rows and columns)
Sizing driven byContentThe track definition
Best forToolbars, nav bars, button groups, card internalsPage shells, galleries, forms, dashboards
Alignment across siblingsOnly along one axisRows and columns line up

Rule of thumb: if you are describing a line of things, use Flexbox. If you are describing a matrix, use Grid. See Flexbox and Grid.

flow-root#

Creates a new block formatting context. Two things it fixes:

HTML
<!-- 1. Contains floated children -->
<div class="flow-root">
  <img class="float-left mr-4" src="…" alt="">
  <p>Text wraps, and the parent still has height.</p>
</div>

<!-- 2. Stops the first child's margin escaping the parent -->
<div class="flow-root bg-gray-100">
  <p class="mt-8">The margin stays inside the grey box.</p>
</div>

contents#

Removes the wrapper's own box so its children participate in the grandparent's layout. Useful when a component adds a wrapper that would otherwise break a grid.

HTML
<div class="grid grid-cols-3 gap-4">
  <div class="contents">
    <div>1</div>
    <div>2</div>
    <div>3</div>
  </div>
</div>

Hiding elements#

There are three different meanings of "hidden", and they are not interchangeable.

ApproachOccupies spaceScreen readersUse for
hiddenNoNot announcedGenuinely irrelevant content
invisibleYesNot announcedReserving space while hidden
opacity-0YesStill announcedFade transitions
sr-onlyNo (visually)AnnouncedLabels for icon-only controls
Loading preview…

Use not-sr-only to reveal it again at a breakpoint: sr-only sm:not-sr-only.

Common patterns#

Responsive show/hide#

HTML
<nav class="hidden md:flex">Desktop navigation</nav>
<button class="md:hidden">Open menu</button>

Icon and label alignment#

HTML
<a href="#" class="inline-flex items-center gap-2 text-indigo-600 hover:text-indigo-500">
  <svg class="size-4" …></svg>
  Documentation
</a>

inline-flex keeps the link inline while aligning the icon to the text.

Toggling with data-*#

HTML
<div data-open="false" class="hidden data-[open=true]:block">…</div>

Common mistakes#

  • Setting width on an inline element. It has no effect. Use inline-block.
  • Using hidden for content that should stay available to screen readers. Use sr-only.
  • Reaching for opacity-0 to hide interactive content. It stays focusable and announced. Pair with pointer-events-none and aria-hidden, or use hidden.
  • flex on the item instead of the container. flex makes an element's children flex items.
  • Expecting gap-* to work without flex or grid. It does nothing on a block element.