TExcelTAD
Home › Tailwind CSS › Layout Patterns

Layout Patterns

Most pages are built from a handful of recurring layouts. This lesson collects the patterns you'll reuse again and again, each in a few lines of Tailwind.

Pattern Key classes
Centred container mx-auto max-w-5xl px-4
Sticky footer flex min-h-dvh flex-col + flex-1 on main
Sidebar layout grid grid-cols-[200px_1fr] or flex + w-* + flex-1
Holy grail grid grid-rows-[auto_1fr_auto]
Auto-fit card grid grid grid-cols-[repeat(auto-fit,minmax(10rem,1fr))]
Split hero grid md:grid-cols-2 items-center
Full-screen centre grid min-h-dvh place-items-center

The page container

Content shouldn't stretch across a 2000px monitor. Limit its width, centre it and add side padding for phones:

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="bg-slate-200">
  <div class="mx-auto max-w-lg bg-white px-4 py-6 sm:px-6">
    <h1 class="text-xl font-bold">mx-auto max-w-lg px-4</h1>
    <p class="mt-2 text-sm text-slate-600">The white column never grows beyond 32rem and stays centred. On narrow screens the padding keeps text off the edges.</p>
  </div>
</body>
</html>

Note: v3's container class still exists in v4, but it is just width: 100% plus a max-width at each breakpoint — it no longer has center or padding options. Most people use mx-auto max-w-* px-* instead.

Sticky footer

On a short page the footer should sit at the bottom of the window, not halfway up. Make the body a column and let the main area grow:

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 min-h-dvh flex-col">
  <header class="bg-indigo-600 p-3 text-white">Header</header>
  <main class="flex-1 p-3">Short content… the footer still hugs the bottom.</main>
  <footer class="bg-gray-800 p-3 text-sm text-gray-300">© 2026 Footer</footer>
</body>
</html>

Dashboard: sidebar + header + scrolling content

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="h-dvh">
  <div class="flex h-full">
    <aside class="hidden w-44 shrink-0 flex-col gap-1 bg-slate-900 p-3 text-sm text-slate-300 sm:flex">
      <p class="mb-2 font-bold text-white">📊 Admin</p>
      <a class="rounded bg-slate-700 px-2 py-1 text-white" href="#">Overview</a>
      <a class="rounded px-2 py-1 hover:bg-slate-800" href="#">Customers</a>
      <a class="rounded px-2 py-1 hover:bg-slate-800" href="#">Settings</a>
    </aside>
    <div class="flex min-w-0 flex-1 flex-col">
      <header class="flex h-12 shrink-0 items-center border-b border-slate-200 px-4 font-semibold">Overview</header>
      <main class="flex-1 space-y-3 overflow-y-auto bg-slate-50 p-4">
        <div class="h-24 rounded-lg bg-white shadow-sm"></div>
        <div class="h-24 rounded-lg bg-white shadow-sm"></div>
        <div class="h-24 rounded-lg bg-white shadow-sm"></div>
        <p class="text-xs text-slate-400">Only this area scrolls. The sidebar hides below 640px.</p>
      </main>
    </div>
  </div>
</body>
</html>

Two details matter: overflow-y-auto on main (only the content scrolls) and min-w-0 on the flex column (so wide content can't push the layout wider than the screen).

Auto-fit grid without breakpoints

repeat(auto-fit, minmax(…)) creates as many columns as fit — the layout adapts to its container, not to fixed breakpoints:

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="grid grid-cols-[repeat(auto-fit,minmax(7rem,1fr))] gap-3">
    <div class="flex aspect-square items-center justify-center rounded-xl bg-rose-200 text-3xl">🍰</div>
    <div class="flex aspect-square items-center justify-center rounded-xl bg-amber-200 text-3xl">🥐</div>
    <div class="flex aspect-square items-center justify-center rounded-xl bg-lime-200 text-3xl">🥗</div>
    <div class="flex aspect-square items-center justify-center rounded-xl bg-sky-200 text-3xl">🍣</div>
    <div class="flex aspect-square items-center justify-center rounded-xl bg-violet-200 text-3xl">🍇</div>
  </div>
</body>
</html>

Split hero section

Text on one side, a visual on the other; stacked on phones.

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="bg-white">
  <section class="grid items-center gap-6 p-6 md:grid-cols-2">
    <div>
      <h1 class="text-3xl font-extrabold tracking-tight text-balance text-gray-900">Plan trips together, effortlessly</h1>
      <p class="mt-2 text-gray-600">Shared itineraries, budgets and maps for your whole group.</p>
      <a href="#" class="mt-4 inline-block rounded-lg bg-sky-600 px-5 py-2.5 font-semibold text-white hover:bg-sky-500">Get started</a>
    </div>
    <div class="flex aspect-video items-center justify-center rounded-2xl bg-linear-to-br from-sky-300 via-cyan-200 to-emerald-200 text-7xl max-md:order-first">🗺️</div>
  </section>
</body>
</html>

max-md:order-first puts the picture on top only on small screens, while keeping text first in the HTML for screen readers and SEO.

Tip: Start every layout on a phone-width preview. If it works at 360px, adding md: and lg: enhancements is easy; going the other way is much harder.

Test yourself

Which classes keep a footer at the bottom of a short page?

  1. fixed bottom-0 on the footer
  2. flex min-h-dvh flex-col on the body and flex-1 on main
  3. absolute bottom-0 on main
  4. grid-rows-3 on the footer

What does grid-cols-[repeat(auto-fit,minmax(7rem,1fr))] do?

  1. Always creates 7 columns
  2. Creates as many columns at least 7rem wide as fit, sharing the leftover space
  3. Creates one 7rem column
  4. Hides overflowing items

In a flex dashboard, why add min-w-0 to the main column?

  1. To hide it on mobile
  2. So wide content can shrink instead of forcing the layout wider than the screen
  3. To remove padding
  4. It enables scrolling in the sidebar