CSS Grid Generator
Generate CSS Grid layout code from columns, rows and gap.
About the CSS Grid Generator
Generates ready-to-use CSS for a grid container from the number of columns, rows and the gap between cells.
How to use
Enter columns, rows and gap, then click Generate.
Worked example
3 columns, 2 rows, 16px gap → a clean responsive grid template.
How to use this calculator
- Choose the number of columns and rows you want in the grid.
- Set the gap size to control spacing between items.
- Generate the CSS code and copy it into your stylesheet.
- Paste your grid items into the container and test the layout in a browser.
Step by step method
- Start with the structure you need, such as 3 columns and 2 rows.
- Decide whether tracks should share space evenly with fr units or size automatically.
- Enter the gap value so the tool can add spacing between grid cells.
- Generate the CSS and apply it to a container with child elements.
Worked example
You want a simple product gallery with 3 equal columns, 2 rows, and a 16 pixel gap between items.
- Set columns to 3, rows to 2, and gap to 16px.
- Use equal-width tracks, which means the column code can be written as \(repeat(3, 1fr)\) and the row code as \(repeat(2, 1fr)\).
- The tool generates a grid container style with those values and the 16px spacing.
Answer. CSS grid code for 3 equal columns, 2 rows, and a 16px gap.
Tips and common mistakes
- Use fr units when you want columns or rows to share the available space evenly.
- Use auto-fit or auto-fill when you want the grid to respond to container width.
- Remember that gap controls space between items, not the outer margin of the grid.
- If the layout looks too crowded, increase the gap or reduce the number of columns.
Frequently asked questions
What does 1fr mean?+
A fraction of the available space, equal columns each take 1fr.
How do I make it responsive?+
Use repeat(auto-fit, minmax(…)) instead of a fixed column count.
More Tech Tools Tools
Explore related calculators in this category
AI API Cost Calculator
Estimate LLM API cost from input/output tokens and per-token prices.
Accessible Color Pair Finder
Check if a text/background pair meets WCAG and suggest a fix. Free tool with instant calculations, the underlying formula, and an easy-to-follow example.
Barcode Generator
Generate Code 128 / EAN barcodes from your data.
Browser Info Detector
Show details about your browser, OS and screen.
You Might Also Like
Popular tools from other categories
.htaccess Generator
Generate common .htaccess rules, force HTTPS, www redirect, and caching, with checkboxes.
1031 Exchange Calculator - Free Online
Free Calculate tax deferral in a 1031 exchange. Step-by-step solutions and formulas included. Fast, accurate, and free, with formula and example.
4% Rule Calculator
Find the retirement nest egg you need using the 4% safe-withdrawal rule.
70% Rule Calculator
Calculate max offer using the 70% rule for flips.
Can't Find the Right Calculator?
Try our AI Math Solver, type any problem in plain English and get instant step-by-step solutions.