Tailwind CSS Cheatsheet

Flexbox

Use this Tailwind CSS reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Enabling Flexbox

<div class="flex">...</div>
<div class="inline-flex">...</div>

Flex Direction

ClassCSS
flex-rowflex-direction: row (default)
flex-row-reverseflex-direction: row-reverse
flex-colflex-direction: column
flex-col-reverseflex-direction: column-reverse
<div class="flex flex-col md:flex-row gap-4">
  <div>Stacked on mobile, side-by-side on md+</div>
  <div>Second item</div>
</div>

Flex Wrap

ClassCSS
flex-nowrapflex-wrap: nowrap (default)
flex-wrapflex-wrap: wrap
flex-wrap-reverseflex-wrap: wrap-reverse
<div class="flex flex-wrap gap-2">
  <span class="px-3 py-1 bg-blue-100 rounded-full">Tag 1</span>
  <span class="px-3 py-1 bg-blue-100 rounded-full">Tag 2</span>
  <span class="px-3 py-1 bg-blue-100 rounded-full">Tag 3</span>
</div>

Justify Content (Main Axis)

ClassCSS
justify-startjustify-content: flex-start
justify-endjustify-content: flex-end
justify-centerjustify-content: center
justify-betweenjustify-content: space-between
justify-aroundjustify-content: space-around
justify-evenlyjustify-content: space-evenly
justify-stretchjustify-content: stretch
justify-normaljustify-content: normal
justify-baselinejustify-content: baseline
<!-- Spread nav items -->
<nav class="flex justify-between items-center px-6 py-4">
  <a href="/">Logo</a>
  <ul class="flex gap-6">...</ul>
</nav>

Align Items (Cross Axis)

ClassCSS
items-startalign-items: flex-start
items-endalign-items: flex-end
items-centeralign-items: center
items-baselinealign-items: baseline
items-stretchalign-items: stretch (default)

Align Content (Multi-row Cross Axis)

Only has effect when there are multiple rows (flex-wrap).

ClassCSS
content-startalign-content: flex-start
content-endalign-content: flex-end
content-centeralign-content: center
content-betweenalign-content: space-between
content-aroundalign-content: space-around
content-evenlyalign-content: space-evenly
content-stretchalign-content: stretch
content-normalalign-content: normal
content-baselinealign-content: baseline

Align Self (Individual Item Cross Axis)

Overrides align-items for a single child.

ClassCSS
self-autoalign-self: auto
self-startalign-self: flex-start
self-endalign-self: flex-end
self-centeralign-self: center
self-stretchalign-self: stretch
self-baselinealign-self: baseline
<div class="flex items-start h-32">
  <div class="self-center">Vertically centered</div>
  <div class="self-end">Pinned to bottom</div>
</div>

Flex Grow and Shrink

ClassCSS
growflex-grow: 1
grow-0flex-grow: 0
shrinkflex-shrink: 1
shrink-0flex-shrink: 0
shrink-[2]flex-shrink: 2
<!-- Sidebar + fluid main -->
<div class="flex">
  <aside class="w-64 shrink-0">Sidebar</aside>
  <main class="grow min-w-0">Main content (grows to fill)</main>
</div>

min-w-0 on grow children prevents overflow when content is wider than the available space.

Flex Basis

Sets the initial main-size of a flex item before grow/shrink.

<div class="flex">
  <div class="basis-1/3">33%</div>
  <div class="basis-2/3">67%</div>
</div>
PatternExampleValue
Fixed sizebasis-6416rem
Fractionbasis-1/250%
Fullbasis-full100%
Autobasis-autoauto
Zerobasis-00px
Arbitrarybasis-[200px]200px

Flex Shorthand

ClassCSS
flex-1flex: 1 1 0%
flex-autoflex: 1 1 auto
flex-initialflex: 0 1 auto
flex-noneflex: none
<!-- Three equal-width columns -->
<div class="flex gap-4">
  <div class="flex-1">A</div>
  <div class="flex-1">B</div>
  <div class="flex-1">C</div>
</div>

Order

Reorder flex (or grid) items visually without changing the DOM.

ClassCSS
order-firstorder: -9999
order-lastorder: 9999
order-noneorder: 0
order-1order-12order: 1order: 12
order-[13]order: 13
<div class="flex">
  <div class="order-last">Shows last</div>
  <div class="order-first">Shows first</div>
  <div>Middle</div>
</div>

Gap

Space between flex items (and grid items).

ClassCSS
gap-0gap: 0
gap-1gap: 0.25rem
gap-2gap: 0.5rem
gap-4gap: 1rem
gap-8gap: 2rem
gap-x-4column-gap: 1rem
gap-y-4row-gap: 1rem
gap-[1.5rem]gap: 1.5rem
<div class="flex flex-wrap gap-x-6 gap-y-3">
  <!-- Different horizontal and vertical gaps -->
</div>

Common Flex Patterns

Centered content (both axes)

<div class="flex items-center justify-center h-screen">
  <p>Perfectly centered</p>
</div>

Sticky footer

<body class="flex flex-col min-h-screen">
  <header>...</header>
  <main class="grow">...</main>
  <footer>...</footer>
</body>

Card with top icon and bottom action

<div class="flex flex-col h-full p-6 border rounded-xl">
  <div class="grow">
    <h3>Title</h3>
    <p>Description</p>
  </div>
  <button class="mt-4">Action</button>
</div>

Space between left and right groups

<div class="flex justify-between items-center">
  <span>Left content</span>
  <div class="flex gap-2">
    <button>A</button>
    <button>B</button>
  </div>
</div>

Push last item to end with ml-auto

<div class="flex items-center gap-4">
  <a href="/">Home</a>
  <a href="/about">About</a>
  <button class="ml-auto">Sign in</button>
</div>