My Favorite Responsive CSS Grid Techniques

In this article, I want to share two responsive techniques that I learned from Wes Bos’ CSS Grid Tutorial. Thanks, Wes!

Template Areas

You can make a site responsive simply by changing the template areas with a media query.

In this example, let’s imagine a regular page where on desktop the main and aside are side by side, and on mobile, they stack on top of each other. The header, nav and footer always span across the entire page.

Here’s the mobile first CSS that would accomplish that just by reconfiguring the template areas. No need to modify the main or aside themselves:

Responsive Equal Width Elements

It’s common to have a series of elements (pictures, products, cards, rectangles of some sort) in a grid. You may want to show 4 or 5 per row, but as the screen gets smaller, show fewer, until you only see one per row.

You don’t even need a media query for this one:

Rachel Andrew wrote an article more in-depth about using minmax and autofill.

Further Reading

Check out Wes Bos’ tutorial, anything by Rachel Andrew, or Mozilla’s web docs.