CSS Grid Generator
Build CSS grid layouts with a live preview: column and row templates with fr, px, auto, repeat() and minmax(), gaps and alignment. Copy the grid CSS.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the CSS Grid Generator
- 1 Pick a preset or type your own grid-template-columns and rows.
- 2 Set the gaps, alignment and number of items; check the preview.
- 3 Copy the CSS.
About the CSS Grid Generator
CSS grid lays out items in rows and columns at the same time. You describe the tracks on the container: grid-template-columns: 200px 1fr gives a fixed sidebar and a flexible content column; repeat(3, 1fr) gives three equal columns. The fr unit shares the remaining space in proportion.
The generator shows your template immediately on numbered items, so you can try track sizes, gaps and alignment without writing a page first. Items are placed automatically in order; for a dashboard or magazine layout you can add grid-column and grid-row rules to individual items afterwards.
The "responsive cards" preset uses repeat(auto-fill, minmax(160px, 1fr)): the browser fits as many columns of at least 160px as the width allows and stretches them to fill the row, a responsive grid without any media queries.
Frequently asked questions
What does 1fr mean?
One fraction of the free space. In 1fr 2fr the second column gets twice as much of the remaining width as the first.
What is the difference between auto-fill and auto-fit?
Both create as many columns as fit. auto-fill keeps empty columns when there are few items; auto-fit collapses them so the items stretch.
How do I make an item span two columns?
Give that item grid-column: span 2 (or grid-column: 1 / 3).
Grid or flexbox?
Grid for two-dimensional layouts and when you want items to line up in columns; flexbox for a single row or column of items.