Defining Grid Columns
Create multi-column layouts with grid-cols-1 through grid-cols-12 and use grid-cols-none for custom configurations.
Defining Grid Columns is a free Tailwind CSS Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Tailwind CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
CSS Grid in Tailwind
CSS Grid is a two-dimensional layout system that lets you place items in rows and columns simultaneously. Tailwind CSS provides utility classes that map directly to CSS Grid properties, so you never have to write display: grid or grid-template-columns by hand. You simply add the right class names to your HTML elements.
<div class="grid">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>Activating Grid Display
To turn an element into a grid container, apply the grid class. Without any column definition, all children stack into a single column by default. This is the starting point for any Tailwind Grid layout — every grid utility you add builds on top of the grid class.
<!-- Single-column grid by default -->
<div class="grid gap-4">
<div class="bg-blue-100 p-4">Card 1</div>
<div class="bg-blue-100 p-4">Card 2</div>
<div class="bg-blue-100 p-4">Card 3</div>
</div>The grid-cols-N Utilities
Tailwind provides grid-cols-1 through grid-cols-12 to divide the container into equal-width columns. Under the hood, grid-cols-3 compiles to grid-template-columns: repeat(3, minmax(0, 1fr)). This means all columns share the available width equally, making it perfect for card grids and feature sections.
<!-- 3-column equal grid -->
<div class="grid grid-cols-3 gap-4">
<div class="bg-green-100 p-4">Col 1</div>
<div class="bg-green-100 p-4">Col 2</div>
<div class="bg-green-100 p-4">Col 3</div>
<div class="bg-green-100 p-4">Col 4</div>
<div class="bg-green-100 p-4">Col 5</div>
<div class="bg-green-100 p-4">Col 6</div>
</div>Common Column Counts
Different column counts suit different use cases. A 2-column grid works well for split-content sections, 3 columns for feature rows, and 4 or 6 columns for product or image galleries. Tailwind supports every integer from 1 to 12, giving you the same range as Bootstrap's grid system but without the row wrappers.
<!-- 2-col layout -->
<div class="grid grid-cols-2 gap-6">
<div class="bg-purple-100 p-6">Left panel</div>
<div class="bg-purple-100 p-6">Right panel</div>
</div>
<!-- 4-col product grid -->
<div class="grid grid-cols-4 gap-4">
<div class="bg-yellow-100 p-4">Product</div>
<div class="bg-yellow-100 p-4">Product</div>
<div class="bg-yellow-100 p-4">Product</div>
<div class="bg-yellow-100 p-4">Product</div>
</div>The 12-Column Grid System
The 12-column grid is a classic design convention because 12 is divisible by 1, 2, 3, 4, and 6, giving you lots of layout flexibility. With Tailwind's grid-cols-12, each child occupies one column by default. You then use col-span-* on individual children to make them span multiple columns — which we will explore in the next lesson.
<!-- 12-column base -->
<div class="grid grid-cols-12 gap-2">
<!-- Each child spans 1 col unless told otherwise -->
<div class="bg-red-100 p-2">1</div>
<div class="bg-red-100 p-2">2</div>
<div class="bg-red-100 p-2">3</div>
<!-- ...up to 12 -->
</div>grid-cols-none for Custom Grids
When the predefined 1–12 presets are not enough, use grid-cols-none to remove any column template, then define your own with grid-cols-[...] arbitrary values. The bracket notation lets you write any valid CSS grid-template-columns value directly inside a class name, giving you infinite flexibility without leaving HTML.
<!-- Custom column widths with arbitrary values -->
<div class="grid grid-cols-[200px_1fr_2fr] gap-4">
<div class="bg-indigo-100 p-4">Fixed 200px</div>
<div class="bg-indigo-100 p-4">1 fraction</div>
<div class="bg-indigo-100 p-4">2 fractions</div>
</div>Subgrid With Tailwind
Modern browsers support the subgrid keyword, which lets a nested grid inherit its parent's column tracks. Tailwind v3.4+ includes grid-cols-subgrid for this purpose. Subgrid is powerful for aligning form labels inside card components that sit in a parent grid — each card's internal elements align with the overall grid lines.
<!-- Parent grid with 3 columns -->
<div class="grid grid-cols-3 gap-4">
<!-- Child that spans 2 cols and uses subgrid internally -->
<div class="col-span-2 grid grid-cols-subgrid gap-2">
<div class="bg-teal-100 p-3">A</div>
<div class="bg-teal-100 p-3">B</div>
</div>
<div class="bg-teal-200 p-3">C</div>
</div>Combining Grid With Gap
The gap-* utilities add consistent spacing between grid cells. Use gap-4 for uniform spacing in both directions, gap-x-4 for horizontal-only gaps, and gap-y-6 for vertical-only gaps. Unlike margins, gap does not add extra space on the outside edges of the grid, keeping your layout clean and predictable.
<!-- Different horizontal and vertical gaps -->
<div class="grid grid-cols-3 gap-x-8 gap-y-4">
<div class="bg-orange-100 p-4">A</div>
<div class="bg-orange-100 p-4">B</div>
<div class="bg-orange-100 p-4">C</div>
<div class="bg-orange-100 p-4">D</div>
<div class="bg-orange-100 p-4">E</div>
<div class="bg-orange-100 p-4">F</div>
</div>Responsive Column Definitions
In most real-world layouts you want fewer columns on small screens and more on larger ones. Tailwind's responsive prefixes make this trivial: grid-cols-1 md:grid-cols-2 lg:grid-cols-4 stacks items on mobile, shows two columns on tablets, and four on desktops. This mobile-first approach means the unprefixed class is the baseline, and prefixed classes override it at larger breakpoints.
<!-- Mobile: 1 col, tablet: 2 cols, desktop: 4 cols -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div class="bg-sky-100 p-6 rounded-lg">Card A</div>
<div class="bg-sky-100 p-6 rounded-lg">Card B</div>
<div class="bg-sky-100 p-6 rounded-lg">Card C</div>
<div class="bg-sky-100 p-6 rounded-lg">Card D</div>
</div>Auto-Fill vs Auto-Fit Columns
CSS Grid's auto-fill and auto-fit keywords create dynamic column counts based on available space. With Tailwind's arbitrary value syntax you can write grid-cols-[repeat(auto-fill,minmax(200px,1fr))] to automatically add columns as space allows. auto-fill keeps empty tracks, while auto-fit collapses them — both create truly fluid grids without media queries.
<!-- Auto-filling card grid: min 250px per card -->
<div class="grid gap-4" style="grid-template-columns: repeat(auto-fill, minmax(250px, 1fr))">
<div class="bg-pink-100 p-4 rounded">Card 1</div>
<div class="bg-pink-100 p-4 rounded">Card 2</div>
<div class="bg-pink-100 p-4 rounded">Card 3</div>
<div class="bg-pink-100 p-4 rounded">Card 4</div>
<div class="bg-pink-100 p-4 rounded">Card 5</div>
</div>Practical Three-Column Feature Grid
Putting it all together, here is a real feature section pattern used on marketing pages. Each feature card has an icon, heading, and description. The grid is grid-cols-1 sm:grid-cols-3 so it stacks on mobile and spreads into three columns on larger screens. Consistent padding and a subtle background create visual separation without borders.
<section class="grid grid-cols-1 sm:grid-cols-3 gap-8 px-8 py-12">
<div class="text-center">
<div class="text-4xl mb-4">🚀</div>
<h3 class="font-bold text-lg mb-2">Fast</h3>
<p class="text-gray-600">Ships in milliseconds.</p>
</div>
<div class="text-center">
<div class="text-4xl mb-4">🔒</div>
<h3 class="font-bold text-lg mb-2">Secure</h3>
<p class="text-gray-600">Built-in protection.</p>
</div>
<div class="text-center">
<div class="text-4xl mb-4">📱</div>
<h3 class="font-bold text-lg mb-2">Responsive</h3>
<p class="text-gray-600">Works on all devices.</p>
</div>
</section>Quick Check
Test your understanding of Tailwind CSS Mastery concepts from this lesson.
Lesson Recap
In this lesson you learned: the grid class activates a CSS Grid container, grid-cols-1 through grid-cols-12 define equal-width column tracks, and responsive prefixes like md:grid-cols-3 switch column counts at breakpoints. Next up we explore how to make grid items span multiple columns and rows for complex layouts.
Frequently asked questions
Is the “Defining Grid Columns” lesson free?
Yes — the full text of “Defining Grid Columns” is free to read here on the web, and the Tailwind CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Tailwind CSS Academy course, upgrade to CoddyKit PRO.
What will I learn in “Defining Grid Columns”?
Create multi-column layouts with grid-cols-1 through grid-cols-12 and use grid-cols-none for custom configurations. You practise Tailwind CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Tailwind CSS Academy?
No prior experience is required. Tailwind CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Defining Grid Columns” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Tailwind CSS Academy lesson?
Yes. Every Tailwind CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Defining Grid Columns
- Column and Row Spanning
- Grid Rows and Auto Placement
- Gap, Justify, and Align in Grid