Grid Generator
Adjust columns, gap, and item count to generate CSS Grid layout code.
Category: Dev Tools
When to use?
Use it for UIs with a regular cell structure — product card lists, dashboard widgets, image galleries, settings panels. Change columns and gap with a preview and get ready-to-paste CSS Grid code.
How to use
- Set the column count and gap.
- Adjust the item count to preview close to the real list size.
- Check the grid layout in the preview.
- Copy the generated CSS Grid code.
Input Explanation
Set the number of columns, the gap between columns, and the child item count. A repeat column structure suits even card grids.
Calculation Basis
It builds grid-template-columns: repeat([Columns], 1fr) from the column count and applies the gap, reflecting it in the grid container's inline style.
Usage Examples
- Draft a grid - Quickly make CSS for repeat-column card lists, galleries, and dashboards.
- Compare spacing - Change the gap to check that card spacing is not too tight or wide.
- Aid design review - Paste the generated CSS into docs or review comments to clarify layout intent.
Examples
- 3 columns, 16px gap → display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
- 4 columns, 24px gap → grid layout code for a product list
- 2 columns, 12px gap → a 2-column mobile settings card draft
Cautions
- Generated output is for reference; test carefully before production use.
- Specific specs or framework-only syntax may cause compatibility issues.
Guides
Core CSS Grid properties
grid-template-columns and grid-template-rows define column and row sizes. The fr unit splits remaining space by ratio.
gap and auto-placement
gap sets cell spacing, and grid-auto-flow sets the auto-placement direction. For complex layouts, name areas with grid-area to use named templates.
Card list layout
Grid fits screens where same-shaped items repeat — product cards, tool lists, image galleries. Decide columns and gap first to quickly compare layout density.
Responsive expansion
Switch the generated repeat columns to an auto-fit + minmax combination to make a responsive grid where column count reduces with screen width.
FAQ
What Grid code does it generate?
A basic grid-template-columns based on repeat(n, minmax(0, 1fr)).
Can I preview the grid?
Yes. Changing columns and gap updates the preview grid instantly.
Can I make a responsive grid?
It is repeat/minmax based, so switching to auto-fit makes a responsive grid where column count adjusts to width.
When do I use Grid vs. Flexbox?
Grid suits card lists/galleries controlling rows and columns; Flexbox is simpler for single-direction alignment.
Related Tools
- Flexbox Generator - Adjust flex-direction, justify-content, align-items, and gap to generate Flexbox CSS.
- CSS clamp() Generator - Auto-generate a CSS clamp() function from min/max values and a viewport range.
- CSS vw Unit Converter - Convert px to viewport-width vw units, or the reverse.
- CSS border-radius Generator - Check rounded-corner values with a preview and generate border-radius CSS.
- JSON Formatter - Beautify or minify JSON strings instantly and check for validity errors.
- UUID Generator - Generate up to 20 cryptographically secure UUID v4 values at once.