Home
Daily
TailwindCSS 5: Grid - Create Clean & Responsive Layouts
December 05, 2025
1 min

Table Of Contents

01
🎯 What You Will Learn in This Lesson
02
🧱 Enable Grid Layout (grid)
03
🧮 Set Number of Columns (grid-cols-*)
04
🎨 Spacing Between Grid Items (gap-*)
05
📱 Responsive Grid (Mobile → Desktop)
06
🖼 Mini Demo: Build a Photo Gallery
07
✅ Summary

In the previous lesson, we learned how to use Flexbox in TailwindCSS to align and arrange items horizontally or vertically. Flexbox is great for one-dimensional layouts — like navbars and item rows.

But what if we want to create:

  • Photo galleries
  • Product card layouts
  • Multi-column sections
  • Responsive content grids

For these structures, the best tool is:

CSS Grid — and TailwindCSS makes it incredibly easy.


🎯 What You Will Learn in This Lesson

ConceptPurpose
gridEnable grid layout
grid-cols-*Control number of columns
gap-*Add spacing between grid items
Responsive grid classesMake layouts adapt to screen sizes

Let’s start building 👇


🧱 Enable Grid Layout (grid)

Activating grid is simple:

<div class="grid">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>

Now we need to tell the grid how many columns it should have.


🧮 Set Number of Columns (grid-cols-*)

<div class="grid grid-cols-3 gap-4">
<div class="bg-gray-200 p-4">A</div>
<div class="bg-gray-200 p-4">B</div>
<div class="bg-gray-200 p-4">C</div>
</div>

This creates 3 equal columns with spacing between them.

Common column utilities:

ClassLayout
grid-cols-1One column
grid-cols-2Two columns
grid-cols-3Three columns
grid-cols-4Four columns

🎨 Spacing Between Grid Items (gap-*)

Just like flexbox, gap-* works beautifully with grid:

<div class="grid grid-cols-2 gap-6">
<div class="bg-blue-200 p-6">Item</div>
<div class="bg-blue-200 p-6">Item</div>
</div>

gap-6 = evenly spaced layout → clean & modern.


📱 Responsive Grid (Mobile → Desktop)

Tailwind’s responsive system works perfectly with grid.

<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
<div class="bg-gray-100 p-4">Card 1</div>
<div class="bg-gray-100 p-4">Card 2</div>
<div class="bg-gray-100 p-4">Card 3</div>
<div class="bg-gray-100 p-4">Card 4</div>
</div>

This means:

  • On mobile → 1 column
  • On small screens → 2 columns
  • On medium screens → 3 columns
  • On large screens → 4 columns

✅ Perfect for galleries and product grids.


<section class="p-8">
<h2 class="text-2xl font-bold mb-6">Photo Gallery</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
<img src="https://picsum.photos/300/200?1" class="rounded shadow" />
<img src="https://picsum.photos/300/200?2" class="rounded shadow" />
<img src="https://picsum.photos/300/200?3" class="rounded shadow" />
<img src="https://picsum.photos/300/200?4" class="rounded shadow" />
<img src="https://picsum.photos/300/200?5" class="rounded shadow" />
<img src="https://picsum.photos/300/200?6" class="rounded shadow" />
</div>
</section>

What’s happening here:

  • grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 → responsive layout
  • gap-4 → nice spacing
  • rounded shadow → polished UI

Beautiful, simple, fast ✨


✅ Summary

Tailwind UtilityUsage
gridEnables CSS Grid layout
grid-cols-*Sets number of columns
gap-*Spacing between items
sm:*, md:*, lg:*Responsive breakpoints

Grid + Responsive classes = Professional layouts in seconds



Tags

#tailwindcss

Share

Related Posts

Tailwind CSS
TailwindCSS 9: Using `tailwind.config.js` to Create Your Own Design System
December 09, 2025
1 min
© 2025, All Rights Reserved.
Powered By

Social Media

githublinkedinyoutube