CSS Grid Generator
Build a CSS grid layout visually: set the columns, rows and gaps, see a live preview and copy the CSS and HTML.
Input
Output
Readme
What is a CSS grid?
CSS grid layout places the children of an element in rows and columns. You define the tracks on the container with grid-template-columns and grid-template-rows, and the space between them with gap; every child then takes the next free cell. It's the usual way to build card grids, photo galleries, dashboards and page layouts with a sidebar.
How to use the generator
- Pick the number of columns and rows with the sliders or by typing.
- Set the column gap and row gap in pixels.
- Give each column and row a size. Every new track starts at
1fr, an equal share of the free space. - Watch the preview, then copy the CSS and the HTML, or download them as files.
The preview box has a fixed height so that rows sized in fr fill it the way they would in a container with a set height.
Sizes you can use
Each field takes one track size, the same values CSS accepts:
frunits for shares of the free space, like1fror2fr- lengths and percentages, like
200px,12remor25% auto,min-contentandmax-contentminmax(150px, 1fr)for a track that never gets narrower than 150pxfit-content(300px)
A single column can also hold a whole responsive pattern, such as repeat(auto-fill, minmax(150px, 1fr)), which fits as many columns as there's room for.
Your browser checks every size. A size it doesn't accept is marked red and 1fr takes its place in the code until you fix it.
The code
When all columns have the same size, the CSS uses repeat(), like repeat(3, 1fr); different sizes are listed in order, like 200px 1fr 1fr. Equal gaps become a single gap value, and different ones are written as the row gap followed by the column gap. The HTML is a container with one numbered child per cell.
Examples
- Three equal columns:
grid-template-columns: repeat(3, 1fr); - A sidebar and a main area: column sizes
250pxand1fr - A header, content and footer: row sizes
auto,1frandauto - A responsive card grid: one column sized
repeat(auto-fill, minmax(200px, 1fr))
Features
- Columns, rows and gaps with sliders
- A size for every column and row, checked by your browser
- Live preview with numbered cells
- CSS and HTML to copy or download
- Runs in your browser