Free tools • Fresh ideas

CSS Grid Generator

Build equal-width tracks and adjust the space between them.

Processing takes place in your browser.

How to use the CSS Grid Generator

Each track uses minmax(0, 1fr), which lets the track shrink below the intrinsic width of its content. Use responsive breakpoints or auto-fit if this fixed column count crowds narrow screens.

Start with the elements that should share a row

CSS Grid places the direct children of a container into rows and columns. A product listing is a good example. The list is the grid container, each product is a grid item, and a product’s title stays inside its own item. Apply the generated declarations to the list or its wrapper. Applying them to each product would make the title and description the grid items instead, changing the arrangement inside a product rather than the arrangement across the catalogue.

The preview uses three short labels so you can see how the tracks change. Begin with two columns and a small gap, then increase the width of the browser and try three. In your project, replace the labels with examples of real content. A short word can hide a problem that only appears when a title is translated or when a card contains a long web address.

What the generated track rule means

The repeat function tells the browser to create the number of tracks you chose. Each track has a minimum of zero and a maximum of one fraction of the available space. Fractions divide the leftover space after gaps and other fixed dimensions have been accounted for. For three equal tracks at a usable width of 600 pixels with a 15-pixel gap, subtract the two gaps first. The remaining 570 pixels are shared as three 190-pixel tracks.

The zero in the minimum is deliberate. A plain fractional track can use an automatic minimum influenced by the content. A very long word or an intrinsically wide image can then make one track larger than its neighbours. Using a zero minimum lets the tracks shrink evenly. Your content still needs to fit inside them. Set a maximum width on images, and allow unusually long text to wrap where breaking a word is acceptable.

Turn a fixed example into a responsive layout

This generator creates a fixed number of columns. At a very narrow width, a three-column rule still creates three columns. In an actual site, consider using one column as the default and increasing to two or three when the cards have enough room. Choose the change point by narrowing the viewport until the content starts to look crowded. A breakpoint selected from the content is often more durable than one named after a particular phone.

An alternative is to let the browser fit as many tracks as it can. A repeat rule using auto-fit and a suitable minimum card width can make a directory adapt without several media queries. That choice has a trade-off. The number of visible columns becomes a consequence of the space, so aligning with another section that expects a fixed count can be harder. Keep a fixed count when cross-section alignment is important, and switch it deliberately at the appropriate width.

Test at a narrow viewport, a comfortable desktop width, and a width just below a layout change. Zooming adds another useful check because text and controls may need more space. Try with one item, an incomplete final row, and an unusually long title. These small examples reveal how the grid handles real data more effectively than inspecting one perfectly filled row.

Common placement and spacing problems

If nothing moves, inspect whether the declaration landed on the parent of the items you want to arrange. Extra wrappers added by a framework or content system can change which elements are direct children. If the columns work but the space looks too large, inspect the gap and the margins on the children. The gap creates space between tracks. An outer gutter belongs to the container’s padding or to the enclosing layout.

A grid controls visual placement, while the document order still matters when visitors navigate by keyboard or read the page with assistive technology. Keep the HTML in a meaningful order before applying CSS. If a visual rearrangement makes the focus jump unpredictably, reconsider the layout instead of trying to patch the tab order. Once the layout works with real content, copy the generated declarations into your stylesheet and keep the tool example as a starting point for future changes.

Related tools

Related guides

Browse learning guides