Advanced CSS Layout Generator
Visual CSS Grid & Flexbox builder — responsive code, SCSS, Tailwind, and more
Breakpoint
Presets
Grid Settings — desktop
Items (6)
Live Preview — desktop
Generated Code
/* Desktop (Default) */
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
grid-auto-rows: minmax(150px, auto);
}
/* Tablet */
@media (max-width: 1024px) {
.grid-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 16px;
grid-auto-rows: minmax(120px, auto);
}
}
/* Mobile */
@media (max-width: 768px) {
.grid-container {
display: grid;
grid-template-columns: 1fr;
gap: 12px;
grid-auto-rows: minmax(100px, auto);
}
}Implementation Guide
- • Copy the code above and paste into your stylesheet
- • Add class
grid-containerto your container element - • The layout responds automatically to screen size changes
HTML Example
<div class="grid-container"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> <div>Item 4</div> <div>Item 5</div> <div>Item 6</div> </div>
Pro Tips
1fr = one fraction of free space. repeat(3,1fr) = 3 equal columns.repeat(auto-fit,minmax(250px,1fr)) creates a fully responsive grid — no media queries needed.grid-column: span 2 or column-start: 1; column-end: 3 to make cells span multiple tracks.@media for cleaner, more maintainable code with CSS custom properties.align = block axis (vertical), justify = inline axis (horizontal).minmax(min,max) = column is at least min, at most max. Combine with auto-fit for zero-query responsive layouts.How the fr unit divides space differently from percentages
The fr unit is what makes grid pleasant to work with, and understanding it removes most layout arithmetic.
One fr is one share of the space left after fixed-size tracks and all the gaps have been subtracted. Define `200px 1fr 1fr` with a 20px gap and the grid works out the remainder itself, then splits it in two.
Percentages cannot do this. `200px 40% 40%` adds up to more than the container once the gaps are included, so something overflows and you end up calculating `calc(40% - 13.33px)` by hand. Change the gap and every calculation is wrong again.
That is the practical win: fr tracks stay correct when you change the gap, add a fixed sidebar, or resize the container, because the browser does the subtraction rather than you.
Why a 1fr track refuses to shrink
This is the grid problem that wastes the most time, because the cause is genuinely non-obvious.
An fr track is shorthand for `minmax(auto, 1fr)`. The auto minimum means the track will not shrink below the size its content needs. Put a long URL with no spaces, a wide image or a table in that cell and it pushes the track past its fair share, breaking the layout and often adding a horizontal scrollbar.
The fix is `minmax(0, 1fr)`, which sets the minimum to zero and lets the track shrink as the fraction demands. The content then overflows its cell instead of distorting the grid, which is usually what you wanted, and you handle it with `overflow: hidden` or `min-width: 0` on the child.
It is worth knowing this before you need it. The symptom — one column mysteriously wider than its siblings — looks like a grid bug and is correct behaviour.
Choosing between grid and flexbox for a layout
These get framed as rivals and are not. They solve different shapes of problem.
Grid is two-dimensional. You define rows and columns and place items into that structure, including across several cells. Use it when the alignment of both axes matters: a page skeleton with header, sidebar and content, a card gallery where items must line up in both directions, a dashboard of panels.
Flexbox is one-dimensional. Items flow along a single axis and you control how they grow, shrink and align. Use it for a navigation bar, a row of buttons, a label beside an input, or anything where you care about distribution along one line.
Most real interfaces use both: grid for the page structure, flexbox inside individual components. Reaching for grid to lay out three buttons in a row works and is more machinery than the job needs.
Making a responsive grid without breakpoints
The most useful thing grid gives you is a layout that reflows with no media queries at all.
The pattern is `repeat(auto-fit, minmax(250px, 1fr))`. It reads as: fit as many columns as will go, each at least 250 pixels wide, and share any leftover space between them. On a phone that resolves to one column, on a tablet two or three, on a wide monitor five. You wrote no breakpoints.
Choose between auto-fit and auto-fill by what happens when items are sparse. auto-fit collapses unused tracks so three items stretch across the row; auto-fill keeps the empty tracks, leaving the items at their natural size with space to the right.
One caveat worth stating, because generators rarely mention it. Grid places items wherever you tell it, but screen readers and keyboard focus follow the order of your markup. A layout rearranged visually can be baffling to navigate, so keep the source order close to the reading order and use grid for presentation rather than for sequence.
How to use the CSS Grid Generator
- Set the number of columns and rows you need.
- Use fr units for proportional tracks and fixed units only where a size is genuinely fixed.
- Switch an fr track to minmax(0, 1fr) if its content refuses to shrink.
- Add a gap rather than margins on the items — gap never applies at the outer edges.
- Check the source order matches the visual order before shipping the layout.
What this tool handles
Visual track editing
Set columns and rows and see the result, rather than guessing at the syntax.
fr and fixed units
Mix proportional and fixed tracks, with gaps accounted for correctly.
Gap control
Set row and column gaps independently instead of using margins on children.
Copyable CSS
Standard grid properties ready to paste, with no framework needed.
Frequently asked questions
Is this CSS grid generator free?
▼
Does this generate responsive CSS with media queries?
▼
Can I position individual grid items to span multiple columns or rows?
▼
What is the fr unit in CSS Grid?
▼
What does minmax() do in CSS Grid?
▼
What is the difference between auto-fit and auto-fill?
▼
When should I use CSS Grid vs Flexbox?
▼
How do I use the generated CSS in my project?
▼
What does the fr unit actually mean?
▼
Why does my 1fr column overflow its content?
▼
Should I use grid or flexbox?
▼
Where did these extra rows come from?
▼
How do I make a grid responsive without media queries?
▼
What is the difference between auto-fit and auto-fill?
▼
Does the visual order affect accessibility?
▼
Are grid template areas worth using?
▼
Does this generator send anything to a server?
▼
Why is there a gap I did not add?
▼
Related Tools You Might Like
JSON Formatter
Format, validate, and minify JSON data
HTML Minifier
Minify HTML code for better performance
Color Picker
Pick colors and generate beautiful color palettes
Website Content Extractor
Extract structured content, meta tags, and SEO data from any website
Google Dork Generator
Build advanced search operator queries without memorising the syntax
Google Search Operators
Every search operator, tagged with whether Google still supports it
