Developer tool

CSS Grid and Flexbox Generator

Choose Grid or Flexbox and set the layout properties to create copyable CSS.

Runs in your browser. No upload.

Values are processed locally in this browser.

Result

—

About this tool

CSS Grid and Flexbox Generator made simple.

The tool creates a CSS snippet, not a full page. Test breakpoints and content sizing in your own design before shipping.

Guide

Using CSS Grid and Flexbox Generator

The CSS Grid and Flexbox Generator writes a short block of CSS for a layout of equal columns. You pick Grid or Flexbox, a number of columns from 1 to 12, a gap in pixels and a vertical alignment, then copy the result. It writes one rule for a container class, not a full page, and it makes no rows, areas, breakpoints or HTML.

How to use it

  1. Choose the layout type: CSS Grid or Flexbox. Grid sets equal columns on the container. Flexbox lets items wrap and gives each item a share of the row width.
  2. Enter the number of columns as a whole number from 1 to 12. The box starts at 3. In Flexbox mode this number decides how wide each item is.
  3. Set the gap in pixels, from 0 to 200, and pick Start, Center, End or Stretch for the alignment. The alignment becomes the align-items value.
  4. Press Calculate, read the CSS in the result box and press Copy result. Rename the .container selector to match your own HTML, then test it with real content.

Worked examples

Three equal Grid columns

You enter
Kind
grid
Columns
3
Gap
16
Alignment
stretch
You get
Css
.container { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }

Grid mode writes one rule. The repeat(3, minmax(0, 1fr)) part makes three columns that share the free width equally.

Run through the tool’s own code.

A centred Flexbox row

You enter
Kind
flex
Columns
3
Gap
16
Alignment
center
You get
Css
.container { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; } .container > * { flex: 1 1 33.33%; }

Flexbox mode adds a second rule for the children. Each child gets a basis of 100 divided by 3, rounded to 33.33%.

Run through the tool’s own code.

Seven items, no gap

You enter
Kind
flex
Columns
7
Gap
0
Alignment
start
You get
Css
.container { display: flex; flex-wrap: wrap; gap: 0px; align-items: start; } .container > * { flex: 1 1 14.29%; }

100 divided by 7 is 14.2857 and so on, written as 14.29%. A gap of zero is still written out as 0px.

Run through the tool’s own code.

Too many columns

You enter
Kind
grid
Columns
13
Gap
16
Alignment
end
You get
Message
Use 1–12 columns, a 0–200px gap and a supported alignment.

Thirteen columns is above the limit, so the tool shows a message in place of CSS. A decimal such as 2.5 columns is refused the same way.

Run through the tool’s own code.

When it helps

  • Start a card grid with a fixed number of columns without typing the declarations by hand.
  • Show a student how the same column count looks in Grid and in Flexbox.
  • Make a quick snippet for a prototype or a bug report, then rename the class.
  • Check what a chosen gap and alignment look like in code before editing a real stylesheet.

Limits to keep in mind

  • It writes one rule for a class called .container. There are no rows, named areas, spanning items, breakpoints or media queries, and you must change the selector yourself.
  • Columns must be a whole number from 1 to 12, the gap must be from 0 to 200 pixels and the alignment must be one of four words. Anything else gives a message instead of CSS.
  • In Flexbox mode each item gets a basis of 100 divided by the column count and the gap is not subtracted. With a gap above zero the last item of a row can wrap to the next line, so test it in a browser.
  • The tool shows no preview and does not check browser support, so test the snippet with your real content and screen sizes.

Tips

  • Pick Grid when you want a strict number of equal columns, and Flexbox when the number of items varies and they should wrap.
  • Paste the snippet into your stylesheet, rename .container to a class that fits your page, then add your own rules for small screens.
  • If a Flexbox row wraps sooner than you expect, lower the flex basis in your own file or set the gap to 0 in the tool and add spacing another way.

Sources

Common questions

About CSS Grid and Flexbox Generator.

How do I make a three-column layout with CSS Grid?

Choose CSS Grid, type 3 for the columns, set a gap and press Calculate. The result has display: grid and grid-template-columns: repeat(3, minmax(0, 1fr)). Copy it, rename .container to your own class and the children of that element fall into three equal columns.

What does minmax(0, 1fr) mean in the Grid result?

Each column takes an equal share of the free space, and the minimum of 0 lets a column shrink below the width of its content instead of pushing the grid wider than its box. The repeat() function writes that column rule once per column.

What is the difference between the Grid and the Flexbox output?

Grid output defines the columns on the container itself and lays every child into them. Flexbox output lets the children wrap and gives each one a width share through a second rule, so a row is built from item widths rather than from fixed columns.

What does the Alignment option change?

It sets the align-items property. In Grid it places each item inside its row area, and in Flexbox it places items inside their line. Stretch fills the height, while Start, Center and End position items at the top, middle or bottom.

Why does the last Flexbox item drop to the next line?

Each item is given a width of 100 divided by the column count, and the gap is added on top. Three items at 33.33% plus two gaps are wider than the container, so the third wraps. Reduce the basis in your own CSS or set the gap to zero.

Can this tool make rows, areas or responsive breakpoints?

No. It makes only equal columns with a gap and an alignment value. For named areas, spanning cells or media queries, write those parts by hand after you copy the snippet, and test the result in the browsers you care about.

Is my input uploaded anywhere?

No. The snippet is built in your browser from the four settings you choose, and nothing is sent to a server. The page does not store the values either, so refreshing it starts from the defaults.

How do I use CSS layout generator?

Choose Grid or Flexbox and set the layout properties to create copyable CSS.

Is my data uploaded to a server?

No. This tool runs locally in your browser. Your input is not uploaded.