Skip to content

CSS Grid Generator

Build a grid container with equal columns. 3 columns and a gap of 16 becomes repeat(3, 1fr) and gap 16px. The page does not write a stylesheet.

Result

Enter columns and a gap

How to Use

  1. 1 Enter a column count from 1 to 12.
  2. 2 Enter a gap from 0 to 100.
  3. 3 Copy the CSS. 3 and 16 is the sample.

Example Output

  • 3 columns and a gap of 16 is repeat(3, 1fr).

About This Tool

Every column is 1fr. The gap uses the same number for rows and columns.

Using the CSS Grid Generator

The CSS Grid Generator writes a grid container with equal columns. Columns start at 3. Gap starts at 16. Choose Build the CSS. The headline is repeat(3, 1fr), and the label above it reads Columns. The text under the headline is three lines. They set display to grid, grid-template-columns to repeat(3, 1fr), and gap to 16px. Each property sits on its own line, with a space after the colon and a semicolon at the end. The headline matches the value inside the second line, without the property name. Read the headline and the second line together. For the sample both say repeat(3, 1fr). If they disagree, build again before you copy.

The detail lines name Columns as 3 and Gap as 16px. The steps say display is set to grid, 1fr is repeated once for each column, and the gap is set in pixels. Copy result copies the three-line declaration, not the headline alone. Reset returns the fields to 3 and 16 and the headline to Enter columns and a gap. The declaration is cleared, so copy it before you reset. The page does not write a stylesheet, a selector, or a rule for the items inside the grid. Paste the three lines into a rule you already have when you want them attached to a selector. The generator stops at the declaration.

Columns are a whole number from 1 to 12. Gap is a whole number from 0 to 100. Every column is 1fr. The page does not ask for a different track size, and it does not write a grid-template-rows line. The gap number is one value, so the same pixel gap is written for both directions. A column count outside 1 to 12, or a gap outside 0 to 100, is rejected and the declaration is cleared. A decimal is rejected in either field because both values must be whole numbers. The column check runs first, so a bad column hides a bad gap until the column count is legal.

The same two accepted numbers always rebuild the same three lines. Change the column count and the headline changes with it, because the headline is repeat with that count and 1fr. Change only the gap and the headline stays on the same repeat, while the third line shows the new pixel value. An error headline means neither line was written. There is no partial grid that keeps display and drops the repeat. Fix the field the message names, build again, and read all three lines before you paste.

What repeat of 1fr Means Here

repeat(3, 1fr) means three columns, and each of those columns is 1fr. The 3 is the number you typed. The 1fr is fixed. The page does not offer 2fr for one column and 1fr for another. If you need unequal tracks, this declaration is not that layout. It is equal fractions, one per column, from 1 column through 12. The headline shows that repeat value so you can read the column pattern without scanning the whole block.

The first line is always display set to grid on a successful build. The second line is grid-template-columns set to the repeat value. The third line is gap set to the whole number and px. For the start values, that third line is gap set to 16px. There is no fourth line. Rows, areas, and item placement are outside the template the page fills. If you need those, add them after you paste. Changing the column count or the gap will never cause them to appear.

How Columns and Gap Become CSS

The page reads columns first. The value must be digits only, and the integer must be from 1 through 12. It then reads gap. The value must be digits only, and the integer must be from 0 through 100. Those two numbers are placed into a three-line template. A space follows each colon. A semicolon ends each line. The repeat list is written as repeat, an opening parenthesis, the column count, a comma, a space, 1fr, and a closing parenthesis. Gap is written as the number plus px.

A flex container uses different properties. The CSS Flexbox Generator writes display flex, a direction of row or column, a justify value, an align value, and a gap. Row, flex-start, stretch, and a gap of 16 are its sample. Use that page when the container should be flex. Use this page when the container should be grid and every column should be 1fr.

What the Generator Does Not Lay Out

The page does not write a stylesheet. It does not invent a class name or attach the declaration to an element. Paste the three lines into a rule you already have if you want them on a selector. The page also skips grid-template-rows, grid-auto-flow, justify-items, align-items, and any placement on the children. Those stay in your own rule if you need them. They will not appear when you change the column count or the gap.

The column count changes how many 1fr tracks are repeated. It does not change the fraction. Twelve columns are still twelve tracks of 1fr, written as repeat(12, 1fr). One column is repeat(1, 1fr). Gap 0 is written as 0px. Gap 100 is written as 100px. Nothing in those lines measures the container's actual pixel width. 1fr is a share of the free space, and the page does not compute that share in pixels. A container that is 900 pixels wide is still written as 1fr here. The pixel width stays in your layout, not in this result.

Three Columns and a Gap of 16

Leave columns at 3 and gap at 16. Choose Build the CSS. The headline is repeat(3, 1fr). The declaration sets display to grid, grid-template-columns to repeat(3, 1fr), and gap to 16px. The Columns line reads 3. The Gap line reads 16px. Build again. The three lines match. Change columns to 1 and build. The headline is repeat(1, 1fr), and the gap line is still 16px if you left the gap alone. Change columns to 12 and build. The headline is repeat(12, 1fr).

Put columns back to 3 and set the gap to 0. The headline returns to repeat(3, 1fr), and the third line is gap set to 0px. A shadow on a box is a different declaration. The CSS Box Shadow Generator writes one box-shadow from offsets, a blur, a spread, and a color. 4, 8, 16, 0, and #000000 become box-shadow with those values in pixels and that color. Use that page when you are adding a shadow. Use this page when you are writing equal grid columns.

Column Counts and Gap Bounds

Columns must be a whole number from 1 to 12. Column 0 is rejected. Column 13 is rejected. A decimal, a blank, a minus sign, and a word are rejected with Columns must be a whole number from 1 to 12. Gap must be a whole number from 0 to 100. Gap 0 is accepted. Gap 100 is accepted. Gap 101 is rejected. A decimal gap is rejected with Gap must be a whole number from 0 to 100. The page does not drop the bad field and still emit display grid.

One failure clears the declaration. The headline becomes the message for the field that failed. If both fields are bad, the column check runs first, so you see the column message until the column count is inside 1 to 12. Then a bad gap shows the gap message. Fix both, then build. The sample pair, 3 and 16, must show repeat(3, 1fr) and a third line of 16px before you treat a later pair as ready. If the third line shows a different pixel value, the gap field is no longer 16. Restore it and build again.

Tracks People Expect and Do Not Get

A common miss is to expect a mix of fr units, such as 2fr and 1fr in the same template. Every column is 1fr. The only number that changes inside the repeat is how many times 1fr is repeated. Another miss is to type 3px or 16px into the fields. The fields want the digits. The page adds px on the gap line and adds 1fr inside the repeat. Another miss is to look for a row template in the result. There is no grid-template-rows line. Another miss is to read the headline as the full declaration. The headline is repeat(3, 1fr) for the sample. The pasteable text is the three-line block, which also sets display and gap.

Compacting a JSON value is a different rewrite. The JSON Minifier parses one JSON value and writes it again without insignificant space. {"a": 1} becomes {"a":1}. Use that page when the text is JSON. Use this page when the text you want is a grid declaration of equal 1fr columns.

One Column, Twelve Columns, and a Zero Gap

Set columns to 1 and gap to 16. Build. The headline is repeat(1, 1fr). The third line is gap set to 16px. Set columns to 12 and gap to 0. Build. The headline is repeat(12, 1fr). The third line is gap set to 0px. Set columns to 0 and build. The headline reads Columns must be a whole number from 1 to 12, and the declaration is cleared. Set columns to 13. The same column message appears. Set columns to 3 and gap to 101. The headline reads Gap must be a whole number from 0 to 100.

Set gap back to 16 and build. The headline is repeat(3, 1fr) and the third line is 16px again. Type 3.5 in columns and build. The column message returns, because a decimal is not a whole number. Type 3 again. The sample declaration is the check that both fields are whole numbers inside their ranges and that every column in the repeat is still 1fr.

Copying the Headline With the Declaration

Copy result copies the three lines. The headline is a shorter reminder of the column pattern. For the sample, file both: repeat(3, 1fr) and the three-line block that also says display grid and gap 16px. A note that keeps only the headline loses the gap. A note that keeps only display grid loses the column count. The three-line copy holds both. Add the two field values beside it if you want the inputs spelled as numbers, 3 and 16.

The page does not store earlier grids after the next build or after a reset. A simulated color is a different kind of result to file next to a layout note. The Color Blindness Simulator recolors one #RGB or #RRGGBB value with a Machado 2009 severity-1 matrix. #FF0000 through the protanopia matrix is #6d5f00, and that hex is an approximation of the typed color. Use that page when you are simulating one color. Use this page when you are writing equal grid columns.

Equal Columns Only

Every successful declaration is three lines, and every column in it is 1fr. Three columns and a gap of 16 produce display grid, repeat(3, 1fr), and gap 16px. The headline is that repeat value. One column and twelve columns use the same shape with a different count. Gap 0 and gap 100 change only the third line. The page does not write a stylesheet around those lines, and it does not compute a pixel width for 1fr.

Use the column field for how many equal tracks you want, from 1 to 12. Use the gap field for the shared pixel gap, from 0 to 100. Read the second line against the headline. They should name the same repeat. Read the third line against the gap you typed. When those agree, the block is the grid container this page builds. Copy the three lines, not only the headline, so the gap travels with the repeat. The headline does not include the pixel gap.

Counting the Columns in the Repeat

Read the number inside repeat and confirm it is the column count you typed. Read 1fr and confirm you wanted equal tracks. If you wanted a different fraction, this page will not write it. Read the gap line and confirm the digits match the field and that px was added by the page, not typed by you twice. For the sample, the headline and the second line both say repeat(3, 1fr), and the third line says 16px. An error headline means there is nothing to paste. Correct the field the message names and build again.

A three-digit permission is a different short code. The chmod Calculator turns a mode from 000 to 777 into the symbolic form. 755 is rwxr-xr-x. It does not emit grid properties. Use that page when you are writing a permission mode. Use this page when you are writing display grid with equal 1fr columns and a gap.

Frequently Asked Questions

What do 3 columns and gap 16 produce?

Three lines: display grid, grid-template-columns set to repeat(3, 1fr), and gap 16px. The headline is repeat(3, 1fr). Each line has a space after the colon and a semicolon at the end. Copy result copies the three lines, not the headline by itself. The Columns line reads 3 and the Gap line reads 16px.

Are the columns equal?

Yes. Every column is 1fr. The column field only changes how many times 1fr is repeated, from 1 to 12. The page will not write 2fr beside 1fr. Twelve columns are repeat(12, 1fr). One column is repeat(1, 1fr). The fraction stays 1fr in every successful repeat.

What column counts work?

A whole number from 1 to 12. Zero, 13, a decimal, a minus sign, and a blank are rejected with Columns must be a whole number from 1 to 12. The declaration is cleared. A bad column is reported before a bad gap, so fix the column count first when both fields fail.

What gap numbers work?

A whole number from 0 to 100. The page writes that number with px, so 16 becomes 16px and 0 becomes 0px. Type the digits only. A number over 100, a decimal, and a blank are rejected with Gap must be a whole number from 0 to 100.

Does the page write rows?

No. The declaration sets display, grid-template-columns, and gap. It does not write grid-template-rows, grid-auto-flow, or placement for the items. The gap value is one number, so the same pixel gap is written for both directions. Add row rules yourself after you paste if you need them.

Does the page write a stylesheet?

No. It writes the three-line container declaration. It does not add a selector, create a file, or attach the rule to an element. Paste the lines into a rule you already have. The page also does not turn 1fr into a pixel width.

What does reset restore?

Columns return to 3 and gap returns to 16. The headline returns to Enter columns and a gap, and the declaration is cleared. Reset does not build the sample for you. Choose Build the CSS again when you want repeat(3, 1fr) and gap 16px back on the page. Copy before you reset if you still need the lines.

Will two builds with 3 and 16 match?

Yes. The page copies those numbers into a fixed template, so the headline is repeat(3, 1fr) and the gap line is 16px. Change only the gap and the headline stays on the same repeat while the third line shows the new pixel value. Change the column count and the headline changes with it.