Display Utilities
The display property is the most fundamental
CSS layout property — it controls how an element participates in the document flow.
Tailwind provides a utility class for every display
value: block, inline, inline-block, flex, inline-flex, grid, inline-grid,
hidden, contents, flow-root, and the full set of table utilities. Mastering
these unlocks everything that comes next — flexbox, grid, and positioning.
flex vs inline-flex, and grid vs inline-grid
hidden — removing elements from
layout entirely vs CSS visibility
contents — removing a wrapper
from layout without removing from the DOM
flow-root — creating a block
formatting context to contain floats
All Display Classes at a Glance
Tailwind maps every CSS display value to a
utility class of the same name. These are the most commonly used — we'll go deep
on each in the sections below.
block, inline & inline-block
These three values are the foundation of CSS layout. Understanding the difference between them is essential before learning flex and grid.
<!-- BLOCK — full width, stacks vertically -->
<span class="block">Force a span to behave like a div</span>
<a class="block w-full py-3 text-center">Full-width link button</a>
<img class="block w-full h-auto" src="..."> <!-- removes inline gap under images -->
<!-- INLINE — flows with text, no sizing control -->
<div class="inline">Force a div to flow inline with text</div>
<span class="inline text-cyan-500">Highlighted word</span> in a sentence.
<!-- INLINE-BLOCK — inline flow + full box model -->
<span class="inline-block px-4 py-2 bg-cyan-500 text-white rounded-lg">
Badge with padding
</span>
<a class="inline-block px-6 py-3 bg-blue-500 text-white rounded-xl">
Pill button — not full-width
</a>
<!-- Practical: make image links block so they don't have gap -->
<a class="block" href="...">
<img class="block w-full" src="..." alt="...">
</a>
flex & inline-flex
flex and inline-flex
both create a flex container — children become flex items. The only difference is
how the container itself participates in the surrounding layout.
<!-- flex — full-width container, use for layout sections -->
<div class="flex items-center justify-between gap-4">
<span class="font-bold">Logo</span>
<nav class="flex gap-6">Nav links</nav>
</div>
<!-- inline-flex — sits inside text flow, perfect for badges/buttons -->
<span class="inline-flex items-center gap-1.5 px-3 py-1
bg-cyan-100 text-cyan-700 rounded-full text-sm font-medium">
<iconify-icon icon="solar:check-circle-bold" width="14"></iconify-icon>
Active
</span>
<!-- inline-flex for icon + text buttons that sit inside a sentence -->
<a class="inline-flex items-center gap-2 text-cyan-500 hover:text-cyan-600" href="...">
Learn more
<iconify-icon icon="solar:arrow-right-linear" width="14"></iconify-icon>
</a>
<!-- ── Quick rule ─────────────────────────────────────── */
<!-- Use flex for layout containers (navbars, card rows) -->
<!-- Use inline-flex for components inside text or lists -->
grid & inline-grid
grid creates a block-level grid container.
inline-grid creates an inline grid that shrinks to
its content. Both need grid-cols-* to define columns —
without it they behave like a single-column block.
<!-- grid — block-level, stretches full parent width -->
<div class="grid grid-cols-3 gap-6">
<div>Card 1</div>
<div>Card 2</div>
<div>Card 3</div>
</div>
<!-- Responsive grid — 1 col → 2 → 3 -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
...
</div>
<!-- inline-grid — shrinks to content, rare but useful -->
<span class="inline-grid grid-cols-2 gap-1 p-2 bg-gray-100 rounded-lg">
<span class="text-xs bg-white rounded p-1 text-center">A</span>
<span class="text-xs bg-white rounded p-1 text-center">B</span>
</span>
<!-- grid without cols — single column stack (same as block) -->
<div class="grid gap-4">
<div>Stacked item 1</div>
<div>Stacked item 2 — gap-4 adds spacing between</div>
</div>
Responsive Show & Hide Patterns
Combining hidden with responsive prefixes is
how you show or hide elements at specific breakpoints. Tailwind is
mobile-first, so the pattern involves hiding on mobile and showing
on larger screens, or vice versa.
<!-- Desktop navbar — hidden on mobile, flex on md+ -->
<nav class="hidden md:flex items-center gap-6">
<a href="...">Home</a>
<a href="...">About</a>
</nav>
<!-- Hamburger button — visible on mobile, hidden on md+ -->
<button class="block md:hidden" aria-label="Open menu">
<iconify-icon icon="solar:list-bold" width="24"></iconify-icon>
</button>
<!-- Sidebar — hidden on mobile, block on lg+ -->
<aside class="hidden lg:block w-64 flex-none">
Sidebar content
</aside>
<!-- Mobile-only card — visible on mobile only -->
<div class="block sm:hidden bg-cyan-50 rounded-xl p-4">
Mobile-only notice
</div>
<!-- Tablet only — sm to lg range -->
<div class="hidden sm:block lg:hidden">
Tablet-only element
</div>
<!-- Dark mode display control -->
<div class="block dark:hidden">Light mode icon</div>
<div class="hidden dark:block">Dark mode icon</div>
hidden md:block means "hidden on mobile, block from 768px up."
The reverse block md:hidden means "block on mobile, hidden from 768px up."
contents & flow-root
Two less-commonly used but powerful display values that solve specific layout problems.
display: contents. The element's box is removed from
layout but its children remain and participate in the parent's layout
context. Useful when you need a semantic wrapper (e.g. a <label>
or <li>) to not create a new layout context.Use case: you have a
div inside a flex or grid
container that shouldn't be its own flex/grid item — its children should be
the direct items instead.
display: flow-root. Creates a new block formatting
context (BFC) — this contains any floated children and prevents
margin collapsing with adjacent elements.Use case: wrapping floated images in article content where the container collapses.
flow-root is the modern alternative
to the old clearfix hack.
<!-- ── contents ─────────────────────────────────────── -->
<!-- Problem: wrapper div creates an extra flex item -->
<div class="flex gap-4">
<button>Button 1</button>
<!-- This wrapper would be a flex item, not the children -->
<div class="contents"> <!-- box removed — children go directly into flex row -->
<button>Button 2</button> <!-- now a direct flex item -->
<button>Button 3</button> <!-- now a direct flex item -->
</div>
<button>Button 4</button>
</div>
<!-- Result: all 4 buttons are direct flex children with gap-4 -->
<!-- ── flow-root ─────────────────────────────────────── -->
<!-- Contains floated children — modern clearfix -->
<div class="flow-root">
<img class="float-left mr-4 mb-2 w-48 rounded-xl" src="..." alt="...">
<p>Article text wraps around the floated image...</p>
</div>
<!-- The parent div now contains the float — no collapse -->
Table Display Utilities
Tailwind exposes all CSS table display values as utility classes. These are rarely used for layout (use Grid or Flexbox instead) but are valuable when building semantic HTML tables or when working with elements that need CSS table behaviour for specific alignment effects.
| Class | CSS value | Use |
|---|---|---|
| table | display: table | Like a <table> element — full-width block |
| table-caption | display: table-caption | Like a <caption> element |
| table-cell | display: table-cell | Like a <td> — enables vertical-align on non-table elements |
| table-column | display: table-column | Like a <col> element |
| table-column-group | display: table-column-group | Like a <colgroup> element |
| table-footer-group | display: table-footer-group | Like a <tfoot> element |
| table-header-group | display: table-header-group | Like a <thead> element |
| table-row-group | display: table-row-group | Like a <tbody> element |
| table-row | display: table-row | Like a <tr> element |
<!-- table + table-cell: old-school vertical centering trick -->
<!-- (Use flex/grid for new projects — this is for legacy compat) -->
<div class="table w-full h-screen">
<div class="table-cell align-middle text-center">
Vertically and horizontally centred
</div>
</div>
<!-- Modern equivalent — use flex instead: -->
<div class="flex items-center justify-center h-screen">
Vertically and horizontally centred
</div>
<!-- Responsive table with overflow scroll -->
<div class="overflow-x-auto">
<table class="table w-full text-sm">
<thead class="table-header-group bg-gray-50 dark:bg-gray-800">
<tr class="table-row">
<th class="table-cell px-4 py-3 text-left font-semibold">Name</th>
<th class="table-cell px-4 py-3 text-left font-semibold">Status</th>
</tr>
</thead>
</table>
</div>
list-item & subgrid
Two additional display values that Tailwind exposes — list-item for non-list elements that should behave like list items (with bullets/numbers), and subgrid for the modern CSS subgrid specification.
<!-- list-item — makes non-list elements show bullet/marker -->
<div class="list-item list-disc ml-5">This div has a bullet marker</div>
<div class="list-item list-decimal ml-5">This div has a number</div>
<!-- Typical use — custom styled list without ul/li -->
<div class="space-y-2 ml-6">
<div class="list-item list-disc text-gray-700 dark:text-gray-300">First item</div>
<div class="list-item list-disc text-gray-700 dark:text-gray-300">Second item</div>
</div>
<!-- subgrid — v3.4+ · child participates in parent's grid tracks -->
<div class="grid grid-cols-3 gap-4">
<!-- Card that spans 2 columns and uses subgrid internally -->
<div class="col-span-2 grid subgrid gap-4">
<div>Aligned to parent grid track 1</div>
<div>Aligned to parent grid track 2</div>
</div>
</div>
- block — full-width, stacks vertically, respects all box model properties.
Use to turn inline elements (
span,a,img) into block-level elements. - inline — flows with text, no width/height control, vertical margins
ignored. Use sparingly —
inline-blockorinline-flexare more useful. - inline-block — flows inline but respects full box model. Perfect for badges, pill buttons, and small interactive elements that live inside text.
- flex vs inline-flex — both create flex containers.
flexis block-level (full width).inline-flexshrinks to content and sits inline — ideal for badges and icon+text combos. - grid vs inline-grid — same pattern as flex/inline-flex. Always add
grid-cols-*to define columns, otherwise grid behaves like a single-column block container. - hidden =
display: none— removes element from layout and accessibility tree. Usesr-onlyto hide visually but keep accessible,invisibleto hide but preserve layout space. - Responsive show/hide — combine
hiddenwith responsive prefixes:hidden md:flex(desktop-only),flex md:hidden(mobile-only). - contents — removes the wrapper's box from layout while keeping its children as participants in the parent's flex/grid. flow-root — creates a block formatting context to contain floats (modern clearfix).
Quick Check — Questions & Answers
Click each question to reveal the detailed answer.
hidden (display: none) — the element is
completely removed from the document flow. It takes up no space, cannot be
interacted with, and is not accessible to screen readers.invisible (visibility: hidden) — the
element is invisible but still occupies its layout space. Other
elements don't shift to fill the gap. Not accessible to screen readers.opacity-0 (opacity: 0) — the element is
transparent but fully present in the layout and accessible to screen readers
and pointer events. Adding pointer-events-none prevents
interaction.Choose based on need: toggling visibility →
hidden.
Preserving layout space → invisible. Fade animation →
opacity-0 transition-opacity.
inline-flex when the flex container should sit inside text
or other inline content rather than taking the full width of its
parent.Common use cases for
inline-flex:• Badge/pill components:
inline-flex items-center gap-1.5 px-3 py-1• Icon + text buttons that don't need to be full-width
• Menu items in a horizontal navigation that sits inside a flex row
• Status indicators next to text
Use
flex when: the container should be block-level and
stretch the full available width — navbars, card bodies, section layouts.
hidden lg:block (or hidden lg:flex if it
needs to be a flex container):<nav class="hidden lg:flex items-center gap-6">Breakdown:
•
hidden — starts hidden on all screens (mobile-first default)•
lg:flex — becomes a flex container at ≥1024pxFor a desktop-only sidebar:
hidden lg:block w-64For a mobile-only hamburger:
block lg:hiddenRemember: Tailwind is mobile-first — unprefixed
hidden applies from
0px, then responsive prefixes override it at their breakpoint.
contents removes the element's own box from the layout while leaving
its children to participate directly in the parent's layout — as if
the wrapper element didn't exist.Use case: you have a flex or grid container and you want to wrap some children in a semantic element (for CSS selectors, JavaScript, or accessibility grouping) but that wrapper should NOT create a new flex/grid item. With
contents, the wrapper's children become direct flex/grid items of the
grandparent.Important caveats: elements with
display: contents
lose their own visual properties (background, border, padding). They also have some
accessibility issues in certain browsers — screen readers may still see the element
or ignore it inconsistently. Use with care and test with a screen reader.
inline by default, which means they sit on the text
baseline. This creates a small gap below the image (typically 3–5px
depending on the font's baseline) because the browser reserves space for descenders
(letters like g, y, p).Adding
block to an image (<img class="block">)
removes it from inline flow, eliminating the gap. This is why you'll see
block w-full h-auto on most images in Tailwind layouts.Tailwind's Preflight reset already sets all images to
display: block
automatically — so if you're using Preflight (the default), you don't need to add
block to images manually. If you've disabled Preflight, you need to add
it yourself.
MCQ Quiz — Test Yourself
Select the best answer. The correct option is revealed after you click.
hidden vs one with invisible — what is the key
difference?grid grid-cols-3 to a parent.
Inside you have a wrapper div
that groups two children. You want those two children to each be a grid item, not the
wrapper. Which class goes on the wrapper div?
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.