CSS Grid Generator
Build complex grid structures visually and accurately
Sketch a grid layout, then copy the rules
CSS Grid is powerful, but syntax like repeat(), fr units and span values is easy to mix up. This generator lets you set the shape of the grid with sliders, click cells to stretch them across several tracks, and see the layout instantly. Once it matches your plan, you copy the CSS instead of typing it.
Working through the controls
- In Grid Structure, drag Cols and Rows from 1 to 12. The preview redraws with that many numbered cells.
- Use the two drop-downs beneath them to size the tracks: 1fr shares space equally, while 100px sets a fixed size. One drop-down controls columns and the other controls rows.
- Click any numbered cell in the preview to select it. The Item Placement heading shows which one.
- Set Col Span and Row Span to make that cell cover more tracks, and optionally type an Area Name such as header.
- Use the two Gaps sliders, each from 0 to 50 pixels. The first controls the gap between columns and the second the gap between rows.
- Click Generate Grid CSS, then Copy CSS.
The code you receive
The tool writes a .grid-container rule with display grid, grid-template-columns and grid-template-rows using repeat(), and a gap declaration with the row gap first and the column gap second. For each cell you changed, it adds a rule named after its number, for example .item-4, holding grid-column and grid-row span values and, if you typed one, a grid-area name.
Practical scenarios
- Planning a page skeleton with a header, sidebar, content and footer.
- Making a photo gallery in which a few images span two columns.
- Building dashboard tiles of different sizes.
- Teaching yourself how fr units and spans behave before touching production code.
What to remember
All columns share one unit and all rows share another; you cannot mix a fixed and a flexible column in the same grid here. Uneven track lists, minmax(), auto-fit and named template areas are not available, so add them by hand if your design needs them. When you make a cell span several tracks, the preview keeps the total number of cells, so later cells may wrap to new rows in ways that differ from your final markup.
Item numbers refer to the order of cells in this preview, and .grid-container and .item-N are placeholder names, so rename them to match your own HTML. Changing any control hides the old code until you click the Generate button again. All calculations are performed in the browser.
Related Articles
Related Tools