Grid Layout Fundamentals: Mastering Columns in Tailwind CSS
Master CSS Grid in Tailwind to build complex, responsive layouts. Learn to define columns, manage gaps, and span grid items with ease.

Previously in this course, we covered Flexbox Layout Basics: Mastering Alignment with Tailwind CSS. While Flexbox is excellent for one-dimensional alignment (rows OR columns), CSS Grid allows us to control layout in two dimensions simultaneously.
Today, we’re moving beyond linear stacks to build sophisticated, multi-column designs using Tailwind’s grid utilities.
Understanding Grid Containers
In CSS, a layout is only as strong as its container. To start using grid, you must transform a block element into a grid formatting context. In Tailwind, this is achieved with the grid class.
Once you have a grid container, you need to define how many columns it should hold. Unlike Flexbox, where you define sizing on the children, Grid allows you to define the structure on the parent.
Defining Column Counts
To set up your columns, use the grid-cols-{n} utility. If you want a standard three-column layout, you apply grid-cols-3 to your parent container.
HTMLstyle="color:#808080"><style="color:#4EC9B0">div class="grid grid-cols-3 gap-4"> style="color:#808080"><style="color:#4EC9B0">div class="bg-blue-200">Item 1style="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"><style="color:#4EC9B0">div class="bg-blue-200">Item 2style="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"><style="color:#4EC9B0">div class="bg-blue-200">Item 3style="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"></style="color:#4EC9B0">div>
The gap-{size} utility is a massive quality-of-life improvement over old-school margin hacks. It applies spacing between both rows and columns automatically without adding extra space to the container's outer edges.
Spanning Grid Items

Sometimes, your layout isn't a uniform set of boxes. You might have a header or a featured item that needs to span across multiple columns. This is where the col-span-{n} utility becomes essential.
Consider a layout where you have a wide banner followed by smaller feature cards. You can tell a specific child element to stretch across the available columns:
HTMLstyle="color:#808080"><style="color:#4EC9B0">div class="grid grid-cols-3 gap-4"> <!-- This item spans all 3 columns --> style="color:#808080"><style="color:#4EC9B0">div class="col-span-3 bg-indigo-500 text-white p-4">Featured Bannerstyle="color:#808080"></style="color:#4EC9B0">div> <!-- These items occupy 1 column each --> style="color:#808080"><style="color:#4EC9B0">div class="bg-gray-200 p-4">Card Astyle="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"><style="color:#4EC9B0">div class="bg-gray-200 p-4">Card Bstyle="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"><style="color:#4EC9B0">div class="bg-gray-200 p-4">Card Cstyle="color:#808080"></style="color:#4EC9B0">div> style="color:#808080"></style="color:#4EC9B0">div>
Hands-on Exercise
In our ongoing marketing site project, we want to display our "Services" section.
- Create a
divwith the classgrid. - Apply
grid-cols-1for mobile andgrid-cols-3for larger screens (we will learn responsive modifiers in upcoming lessons, so for now, stick togrid-cols-3). - Add a
gap-6to ensure the cards have breathing room. - Add three child
divelements, each containing a heading and some placeholder text. - Apply a border and padding to each card to see how the grid manages the flow.
Common Pitfalls
- Forgetting the Container: If you apply
col-spanto an element that isn't a direct child of agridcontainer, the utility will have no effect. - Over-nesting: Beginners often wrap grid items in unnecessary
divtags. Remember thatcol-spanonly applies to the immediate children of the grid container. - Ignoring Implicit Rows: If you define
grid-cols-3but have 4 items, Grid automatically creates a new row. Don't fight this—embrace it as the primary way to handle list-based content.
Quick Reference: Flex vs. Grid
| Feature | Flexbox | CSS Grid |
|---|---|---|
| Dimension | 1D (Row or Column) | 2D (Rows AND Columns) |
| Control | Driven by children | Driven by container |
| Use Case | Navigation, centering, buttons | Page layouts, galleries, complex cards |
For more advanced layout patterns, check out our guide on CSS Overlapping Cards: A Responsive Stack Pattern with Tailwind to see how these grid utilities handle more complex, layered UI designs.
Recap

You’ve now learned the foundation of two-dimensional layout:
- Use
gridto initialize the container. - Use
grid-cols-{n}to define your column structure. - Use
gap-{n}to manage whitespace between items. - Use
col-span-{n}to adjust how elements occupy the available grid tracks.
Up next: We will apply these concepts to build out the feature section of our project in "Designing the Feature Grid."
Work with me

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.

Next.js Website & Landing Page Development
A blazing-fast, SEO-optimized website or landing page in Next.js — the kind that loads instantly and ranks. Design-to-code, done right.

