Skip to main content

How to Create a Responsive Grid in CSS

Learn to build responsive grid layouts with CSS Grid and Flexbox. Step-by-step tutorial with live interactive demos.

What is a Responsive Grid?

A responsive grid automatically adjusts the number of columns based on screen size. Modern CSS gives us powerful tools to create grids that:

  • Auto-adjust columns - Automatically change from 4 to 3 to 2 to 1 columns as space decreases
  • No media queries needed - Using auto-fit and minmax() for fluid layouts
  • Maintain minimum sizes - Items never shrink below a readable width
  • Fill available space - Items expand to use all available width
1
2
3
4
5
6

Resize your browser to see the grid adapt

Step-by-Step Tutorial

Follow these 6 steps to master responsive CSS grids. Click any code block to copy.

1

Basic Grid Setup

Start by applying display: grid to your container.

2

Define Columns with repeat()

Use grid-template-columns with repeat() to define your columns.

3

Make it Responsive with minmax()

The magic happens with minmax(). Combined with auto-fit, columns wrap automatically!

4

auto-fit vs auto-fill Explained

auto-fit collapses empty tracks so items stretch. auto-fill keeps empty tracks.

5

Add Gap and Alignment

Use the gap property for consistent spacing between items.

6

Grid Areas for Complex Layouts

For complex layouts like dashboards, use grid-template-areas to create named regions.

Live Interactive Demo

Drag the slider to resize the container and see how the grid responds.

100%
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8

grid-template-columns: repeat(auto-fit, minmax(120px, 1fr))

auto-fit vs auto-fill Comparison

See the difference between auto-fit and auto-fill with fewer items than can fill the container.

auto-fitItems stretch to fill space

Empty tracks collapse, items expand

1
2

auto-fillEmpty tracks preserved

Track sizes stay consistent

1
2

Multiple Approaches

There are several ways to create responsive grids. Each has its use cases.

CSS Grid with Media Queries

Preview

1
2
3
4
5
6

Resize browser to see breakpoint changes

Tailwind CSS Examples

Here are the same techniques using Tailwind CSS utility classes.

Auto-fit with Arbitrary Values

Use arbitrary values for auto-fit + minmax in Tailwind

Responsive Breakpoints

Use Tailwind responsive prefixes for specific column counts

Flexbox Grid

Use flex utilities for a responsive flexbox grid

Common Grid Patterns

Real-world examples you can use in your projects.

Card Grid (1-2-3-4 Columns)

Preview

Browser Support

CSS Grid is Fully Supported

CSS Grid has excellent browser support (97%+ globally). You can use it confidently in production.

Chrome

57+

Firefox

52+

Safari

10.1+

Edge

16+

Opera

44+

Frequently Asked Questions

What is the difference between auto-fit and auto-fill?

auto-fit collapses empty tracks to zero width, allowing items to stretch and fill available space. auto-fill keeps empty tracks, maintaining their size even when there aren't enough items to fill them. Use auto-fit when you want items to expand, and auto-fill when you want consistent track sizes regardless of content.

How does minmax() work in CSS Grid?

minmax() sets a minimum and maximum size for grid tracks. For example, minmax(250px, 1fr) means the column will be at least 250px wide but can grow to fill available space (1fr). It's essential for creating responsive grids that adapt to different screen sizes without media queries.

Should I use CSS Grid or Flexbox for responsive layouts?

Use CSS Grid for two-dimensional layouts (rows AND columns) like card grids, dashboards, and page layouts. Use Flexbox for one-dimensional layouts (either row OR column) like navigation bars, centering content, or distributing items in a single line. Many modern layouts use both together.

How do I make a responsive grid without media queries?

Use CSS Grid with repeat(auto-fit, minmax(min-size, 1fr)). This creates columns that automatically adjust based on available space. Items will wrap to new rows when they can't fit, and expand to fill space when there's room. No media queries needed for basic responsive behavior.

What is the fr unit in CSS Grid?

The fr (fraction) unit represents a fraction of available space in the grid container. If you have grid-template-columns: 1fr 2fr, the second column gets twice the space of the first. It's like flex-grow in Flexbox but for grid tracks.