March 2026
Space Items Evenly with CSS Grid (instead of Flexbox)
TL;DR
Go read this for how to do a grid layout
How to create a responsive grid system with CSS Grid by Chris Ferdinandi.
I'll update this post with that approach later. For now, just know that you probably want to use grid instead of flexbox and do something like this to get started.
Output
HTML
CSS
}
}
Semi-Flexible
Here's the flexbox approach.
Output
HTML
CSS
}
}
One Row Only
Note that this probably doesn't do what you want if items are going to wrap rows and there's not enough items for each row to have the same number of item. For example:
Output
HTML
The two items on the second row get pushed to the edges which tends to look weird. Hence the grid solution at the top of this post.
-a
end of line