Logo

Advanced CSS Layout Generator

Visual CSS Grid & Flexbox builder — responsive code, SCSS, Tailwind, and more

Breakpoint

Presets

Grid Settings — desktop

Items (6)

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

Live Preview — desktop

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
💡 Click items to select & configure position🎯 Each breakpoint can have unique positioning

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-container to 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

•fr units: 1fr = one fraction of free space. repeat(3,1fr) = 3 equal columns.
•auto-fit magic: repeat(auto-fit,minmax(250px,1fr)) creates a fully responsive grid — no media queries needed.
•Spanning items: Use grid-column: span 2 or column-start: 1; column-end: 3 to make cells span multiple tracks.
•SCSS nesting: The SCSS output uses nested @media for cleaner, more maintainable code with CSS custom properties.
•align vs justify: In grid: align = block axis (vertical), justify = inline axis (horizontal).
•minmax(): 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

  1. Set the number of columns and rows you need.
  2. Use fr units for proportional tracks and fixed units only where a size is genuinely fixed.
  3. Switch an fr track to minmax(0, 1fr) if its content refuses to shrink.
  4. Add a gap rather than margins on the items — gap never applies at the outer edges.
  5. 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?

▼
Yes, completely free with no account or login required. You can generate and copy as many layouts as you need.

Does this generate responsive CSS with media queries?

▼
Yes. The generated CSS includes @media query breakpoints for desktop (default, no query), tablet (max-width: 1024px), and mobile (max-width: 768px). You configure each breakpoint separately.

Can I position individual grid items to span multiple columns or rows?

▼
Yes. In CSS Grid mode, click any item in the Items panel, then set grid-column-start, grid-column-end, grid-row-start, and grid-row-end. Values like "span 2" or "1" are supported. Each breakpoint can have different positioning.

What is the fr unit in CSS Grid?

▼
The fr unit stands for fraction of available space. repeat(3, 1fr) creates three equal columns. It is like a flexible percentage that automatically accounts for the gap between columns.

What does minmax() do in CSS Grid?

▼
minmax(min, max) sets a minimum and maximum size for a grid track. For example, minmax(250px, 1fr) makes a column at least 250px wide but able to grow. Combined with repeat(auto-fit, ...), it creates a fully responsive grid without media queries.

What is the difference between auto-fit and auto-fill?

▼
Both fill the grid with columns automatically. auto-fit collapses empty columns, allowing existing items to stretch. auto-fill keeps empty tracks, maintaining consistent column sizing. auto-fit is usually preferred for responsive card grids.

When should I use CSS Grid vs Flexbox?

▼
Use CSS Grid for two-dimensional layouts where you need explicit control over both rows and columns — page layouts, dashboards, card grids. Use Flexbox for one-dimensional layouts where items flow in a row or column — navigation bars, button groups, inline elements.

How do I use the generated CSS in my project?

▼
Copy the CSS and paste it into your stylesheet. Add the class name shown in the HTML Example (grid-container or flex-container) to your container element in HTML. If you positioned specific items, add grid-item-1, grid-item-2, etc. classes to those elements.

What does the fr unit actually mean?

▼
A fraction of the leftover space after fixed sizes and gaps are subtracted. Two columns at 1fr each split the remainder equally. It is not a percentage — it divides what is left rather than the whole, which is why it handles gaps correctly where percentages do not.

Why does my 1fr column overflow its content?

▼
Because an fr track has a minimum size of auto, and a long unbroken string or a wide image can force it past its share. Setting `minmax(0, 1fr)` instead lets it shrink properly. This is the most common grid frustration and the fix is obscure.

Should I use grid or flexbox?

▼
Grid for two-dimensional layout where rows and columns both matter — a page skeleton, a card gallery, a dashboard. Flexbox for one direction, like a navigation bar or a row of buttons. They are complementary rather than competing, and most real pages use both.

Where did these extra rows come from?

▼
The implicit grid. If you place more items than your defined rows hold, the grid creates rows automatically, sized by content rather than by your template. `grid-auto-rows` controls how those behave.

How do I make a grid responsive without media queries?

▼
`repeat(auto-fit, minmax(250px, 1fr))` is the pattern worth memorising. It fits as many columns of at least 250 pixels as will go and distributes the rest, reflowing on any screen with no breakpoints at all.

What is the difference between auto-fit and auto-fill?

▼
With fewer items than fit, auto-fit collapses the empty tracks so the items stretch across; auto-fill keeps them, leaving a gap on the right. For a gallery that may be sparsely filled, auto-fit usually looks better.

Does the visual order affect accessibility?

▼
Yes, and it is a genuine problem. Grid can place an item anywhere regardless of its position in the markup, but screen readers and keyboard navigation follow the source order. A layout that reads sensibly on screen can be incoherent to navigate.

Are grid template areas worth using?

▼
For a page skeleton, yes — naming regions and drawing the layout as a string grid is unusually readable, and rearranging it in a media query is a one-line change. For a simple repeating gallery it is more ceremony than the job needs.

Does this generator send anything to a server?

▼
No. It builds a CSS string in your browser and nothing is transmitted. The network panel stays empty while you use it.

Why is there a gap I did not add?

▼
Check whether it is the grid gap or margin on the items themselves. Grid gap applies between tracks only, never at the outer edges, so a space around the outside is coming from padding on the container or margins on the children.

Related Tools You Might Like

Advertisement