Tailwind CSS Cheatsheet

Grid

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 Grid

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

Grid Template Columns

Define the number (and width) of columns.

ClassCSS
grid-cols-1grid-template-columns: repeat(1, minmax(0, 1fr))
grid-cols-2grid-template-columns: repeat(2, minmax(0, 1fr))
grid-cols-3grid-cols-12repeat N equal columns
grid-cols-nonegrid-template-columns: none
grid-cols-subgridgrid-template-columns: subgrid
grid-cols-[200px_1fr_2fr]custom template
<!-- Three equal columns with gap -->
<div class="grid grid-cols-3 gap-4">
  <div>A</div>
  <div>B</div>
  <div>C</div>
</div>

<!-- Responsive columns -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
  ...
</div>

<!-- Custom template -->
<div class="grid grid-cols-[1fr_2fr_1fr] gap-4">
  <aside>Sidebar</aside>
  <main>Content</main>
  <aside>Sidebar</aside>
</div>

Grid Template Rows

ClassCSS
grid-rows-1grid-rows-6repeat N equal rows
grid-rows-nonegrid-template-rows: none
grid-rows-subgridgrid-template-rows: subgrid
grid-rows-[100px_auto_100px]custom template
<!-- Full-height page layout -->
<div class="grid grid-rows-[auto_1fr_auto] min-h-screen">
  <header>Header</header>
  <main>Main grows to fill</main>
  <footer>Footer</footer>
</div>

Column Span (col-span)

How many columns a child item occupies.

ClassCSS
col-span-1col-span-12grid-column: span N / span N
col-span-fullgrid-column: 1 / -1
<div class="grid grid-cols-12 gap-4">
  <div class="col-span-8">Main content</div>
  <div class="col-span-4">Sidebar</div>
  <div class="col-span-full">Full-width footer row</div>
</div>

Column Start and End

ClassCSS
col-start-1col-start-13grid-column-start: N
col-start-autogrid-column-start: auto
col-end-1col-end-13grid-column-end: N
col-end-autogrid-column-end: auto
<!-- Item starts at column 2, ends at column 5 -->
<div class="col-start-2 col-end-5">Spans columns 2-4</div>

<!-- Shorthand using span with explicit start -->
<div class="col-start-3 col-span-2">Starts at 3, spans 2</div>

Row Span (row-span)

ClassCSS
row-span-1row-span-6grid-row: span N / span N
row-span-fullgrid-row: 1 / -1

Row Start and End

ClassCSS
row-start-1row-start-7grid-row-start: N
row-end-1row-end-7grid-row-end: N
row-start-auto / row-end-autoauto placement
<!-- Magazine-style layout with a tall featured image -->
<div class="grid grid-cols-3 grid-rows-3 gap-4">
  <div class="col-span-2 row-span-2">Featured</div>
  <div>Small 1</div>
  <div>Small 2</div>
  <div class="col-span-3">Banner</div>
</div>

Grid Auto Flow

Controls how auto-placed items fill the grid.

ClassCSS
grid-flow-rowgrid-auto-flow: row (default)
grid-flow-colgrid-auto-flow: column
grid-flow-densegrid-auto-flow: dense
grid-flow-row-densegrid-auto-flow: row dense
grid-flow-col-densegrid-auto-flow: column dense
<!-- Fill columns first (creates implicit columns) -->
<div class="grid grid-flow-col grid-rows-3 gap-4">
  <div>1</div><div>2</div><div>3</div>
  <div>4</div><div>5</div><div>6</div>
</div>

<!-- Dense packing fills holes left by spanning items -->
<div class="grid grid-cols-3 grid-flow-dense gap-4">...</div>

Grid Auto Columns / Rows

Size of implicitly created tracks.

ClassCSS
auto-cols-autogrid-auto-columns: auto
auto-cols-mingrid-auto-columns: min-content
auto-cols-maxgrid-auto-columns: max-content
auto-cols-frgrid-auto-columns: minmax(0, 1fr)
auto-cols-[200px]grid-auto-columns: 200px
auto-rows-autogrid-auto-rows: auto
auto-rows-mingrid-auto-rows: min-content
auto-rows-maxgrid-auto-rows: max-content
auto-rows-frgrid-auto-rows: minmax(0, 1fr)
auto-rows-[100px]grid-auto-rows: 100px
<!-- Carousel: auto flow columns, fixed height rows -->
<div class="grid grid-flow-col auto-cols-[260px] gap-4 overflow-x-auto">
  <div class="h-40 bg-slate-200 rounded-xl">Card</div>
  <div class="h-40 bg-slate-200 rounded-xl">Card</div>
</div>

Gap

Identical to flexbox — see Flexbox for full table.

<div class="grid grid-cols-3 gap-4">...</div>
<div class="grid grid-cols-3 gap-x-6 gap-y-3">...</div>

Justify Items (Inline Axis, All Cells)

ClassCSS
justify-items-startjustify-items: start
justify-items-endjustify-items: end
justify-items-centerjustify-items: center
justify-items-stretchjustify-items: stretch (default)

Justify Self (Inline Axis, Single Cell)

ClassCSS
justify-self-autojustify-self: auto
justify-self-startjustify-self: start
justify-self-endjustify-self: end
justify-self-centerjustify-self: center
justify-self-stretchjustify-self: stretch

Align Items / Align Self / Align Content

Same classes as flexbox (items-*, self-*, content-*) apply identically to grid.

Place Content, Items, and Self

Shorthand that sets both align and justify at once.

ClassCSS
place-content-centerplace-content: center
place-content-betweenplace-content: space-between
place-items-centerplace-items: center
place-items-startplace-items: start
place-self-centerplace-self: center
place-self-endplace-self: end
<!-- Centering a grid cell's content both axes -->
<div class="grid place-items-center h-32 w-32 bg-slate-100">
  <span>Centered</span>
</div>

Common Grid Patterns

Auto-fill responsive cards (no media queries needed)

<div class="grid gap-6" style="grid-template-columns: repeat(auto-fill, minmax(240px, 1fr))">
  <div class="rounded-xl border p-4">Card</div>
  <div class="rounded-xl border p-4">Card</div>
  <div class="rounded-xl border p-4">Card</div>
</div>

Or with arbitrary value:

<div class="grid grid-cols-[repeat(auto-fill,minmax(240px,1fr))] gap-6">...</div>

Holy grail layout

<div class="grid grid-cols-[200px_1fr_200px] grid-rows-[auto_1fr_auto] min-h-screen">
  <header class="col-span-3 p-4">Header</header>
  <nav class="p-4 border-r">Left nav</nav>
  <main class="p-6">Content</main>
  <aside class="p-4 border-l">Right aside</aside>
  <footer class="col-span-3 p-4">Footer</footer>
</div>

Named grid areas (arbitrary)

<div class="grid [grid-template-areas:'header_header''sidebar_main'] grid-cols-[200px_1fr]">
  <header class="[grid-area:header]">Header</header>
  <nav class="[grid-area:sidebar]">Nav</nav>
  <main class="[grid-area:main]">Main</main>
</div>

Subgrid (v4 / modern browsers)

<div class="grid grid-cols-3 gap-4">
  <div class="grid grid-cols-subgrid col-span-3">
    <!-- children align to parent's column tracks -->
    <span>A</span><span>B</span><span>C</span>
  </div>
</div>