TExcelTAD
Home › Tailwind CSS › Display & Position

Display & Position

Display utilities decide how an element takes part in layout; position utilities let you take an element out of the normal flow and place it precisely.

Display

Class CSS Typical use
block display: block full-width boxes
inline-block display: inline-block badges, buttons in text
inline display: inline text-level elements
flex / inline-flex flex container rows, centring
grid / inline-grid grid container two-dimensional layouts
hidden display: none hide completely
contents the element's box disappears; children stay wrappers you can't remove
sr-only visually hidden but read by screen readers accessible labels
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="space-y-3 p-4 text-sm">
  <p>Text with an <span class="inline-block rounded bg-sky-200 px-2 py-1">inline-block</span> badge inside.</p>
  <span class="block rounded bg-amber-200 p-2">A span made <b>block</b> fills the width.</span>
  <div class="hidden">You can't see me (hidden).</div>
  <button class="inline-flex items-center gap-2 rounded bg-gray-900 px-3 py-2 text-white">
    <span aria-hidden="true">🔍</span><span class="sr-only">Search</span> icon-only button
  </button>
</body>
</html>

Visibility and overflow

Class Effect
invisible / visible hide but keep the space (visibility)
overflow-hidden clip content that sticks out
overflow-auto scrollbars only when needed
overflow-x-auto horizontal scrolling (wide tables)
overflow-clip clip without creating a scroll container

Position

Class Behaviour
static default flow
relative normal flow, but becomes the reference for absolute children
absolute removed from flow, placed relative to the nearest positioned ancestor
fixed placed relative to the viewport, doesn't scroll
sticky scrolls normally until it reaches its top-* offset, then sticks

Place positioned elements with inset utilities:

Class CSS
top-0 / right-4 / bottom-2 / left-1/2 single side
inset-0 all four sides 0 (fill the parent)
inset-x-0 / inset-y-4 left+right / top+bottom
-top-2 negative offset
z-10, z-20, z-50, z-auto stacking order (z-index)
html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="flex gap-8 p-8">
  <button class="relative rounded-lg bg-slate-800 px-4 py-2 text-white">
    Messages
    <span class="absolute -top-2 -right-2 flex size-6 items-center justify-center rounded-full bg-red-500 text-xs font-bold">3</span>
  </button>
  <div class="relative size-36 overflow-hidden rounded-xl bg-linear-to-br from-teal-400 to-sky-600">
    <span class="absolute top-2 left-2 rounded bg-white/80 px-2 text-xs">top-left</span>
    <span class="absolute right-2 bottom-2 rounded bg-white/80 px-2 text-xs">bottom-right</span>
    <div class="absolute inset-x-0 bottom-10 bg-black/40 py-1 text-center text-xs text-white">inset-x-0 bar</div>
  </div>
</body>
</html>

The badge works because its parent button is relative. Without it, absolute would position the badge relative to the page.

Overlays with inset-0

absolute inset-0 stretches an element over its whole parent — the standard way to put a tint or a label over a picture.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-6">
  <div class="relative flex h-44 w-72 items-center justify-center rounded-2xl bg-linear-to-r from-orange-400 to-rose-500 text-7xl">
    🏔️
    <div class="absolute inset-0 flex items-end rounded-2xl bg-linear-to-t from-black/70 to-transparent p-4">
      <p class="font-semibold text-white">Alpine weekend — from $199</p>
    </div>
  </div>
</body>
</html>

Sticky headers

Scroll inside the preview: the header sticks to the top of its scroll container.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-4">
  <div class="h-56 overflow-y-auto rounded-lg border border-gray-300">
    <h3 class="sticky top-0 z-10 bg-indigo-600 px-3 py-2 font-semibold text-white">A — sticky</h3>
    <p class="p-3">Alice</p><p class="p-3">Amir</p><p class="p-3">Anna</p>
    <h3 class="sticky top-0 z-10 bg-indigo-600 px-3 py-2 font-semibold text-white">B — sticky</h3>
    <p class="p-3">Bao</p><p class="p-3">Bella</p><p class="p-3">Bruno</p><p class="p-3">Bianca</p>
  </div>
</body>
</html>

Tip: sticky needs an offset (top-0) and won't work if an ancestor between it and the scroll container has overflow-hidden.

Test yourself

An absolute badge appears in the corner of the page instead of its button. What is the likely fix?

  1. Add z-50 to the badge
  2. Add relative to the button
  3. Use fixed on the badge
  4. Add block to the button

Which class hides an element visually but keeps it available to screen readers?

  1. hidden
  2. invisible
  3. sr-only
  4. opacity-0

What does absolute inset-0 do?

  1. Removes all padding
  2. Stretches the element to cover its positioned parent
  3. Centres the element
  4. Resets the z-index