A CSS Grid Generator example builds an explicit grid with repeat(n, minmax(0, 1fr)) equal tracks, one shared gap, and separate inline- and block-axis item alignment.

That makes the generated output easy to audit: the selector is .grid, the row and column counts are explicit, and every declaration comes from a bounded set of controls. Open the CSS Grid Generator to configure those values and inspect the result in its always-visible preview.

The example below shows a complete configuration and the CSS you can paste into a stylesheet. It is a starting point for a bounded two-dimensional layout, not an automatic production-page framework.

css grid generator example
CSS Grid Generator Example: Equal Tracks and Gaps

A Complete CSS Grid Generator Example

Choose 3 columns, 2 rows, a 16px gap, justify-items: center, and align-items: stretch. The generated rule is equivalent to:

.grid {

display: grid;

grid-template-columns: repeat(3, minmax(0, 1fr));

grid-template-rows: repeat(2, minmax(0, 1fr));

gap: 16px;

justify-items: center;

align-items: stretch;

}

The display: grid declaration establishes the grid formatting context. The column and row templates then create three equal column tracks and two equal row tracks. Each 1fr track receives one fraction of the available space, while minmax(0, 1fr) gives that flexible track a zero minimum instead of allowing a long min-content contribution to force it beyond the container.

The single gap: 16px declaration applies 16 pixels between adjacent rows and columns. The two alignment properties affect the items inside their assigned grid areas: justify-items controls the inline axis, while align-items controls the block axis.

Configure and Generate a Valid Grid

  1. Open the generator. The preview remains visible while you work, so you can compare each setting with the resulting grid structure.
  2. Enter the track counts and gap. Columns and rows must each be whole numbers from 1 through 12. The gap must be a whole number from 0 through 100 pixels. For this example, enter 3 columns, 2 rows, and 16 for the gap; enter the gap as a bare number rather than adding a unit.
  3. Choose the item alignments. Set justify-items to center and align-items to stretch. Each control offers the same four closed choices: stretch, start, center, and end.
  4. Inspect the live preview. The numbered sample items make the cell boundaries and alignment visible. Their fixed dimensions are part of the demonstration only and are not included in the copied CSS.
  5. Generate and copy the rule. Select Generate CSS after the fields are valid. Copy the resulting .grid rule into your stylesheet. If clipboard permission is blocked, select the displayed code and copy it manually.

Choose the Right Item Alignment

Item alignment and track alignment solve different problems. The generator controls how each grid item is aligned inside its own grid area; it does not control how the collection of tracks is distributed inside a larger container.

Value justify-items: inline axis align-items: block axis
stretch Fills the grid area along the inline axis when the item's sizing permits it. Fills the grid area along the block axis when the item's sizing permits it.
start Positions the item toward the inline-start edge. Positions the item toward the block-start edge.
center Positions the item between the inline-axis edges. Positions the item between the block-axis edges.
end Positions the item toward the inline-end edge. Positions the item toward the block-end edge.

These are item-level defaults, not justify-content or align-content. The latter properties distribute the grid tracks as a group inside the grid container. The distinction is also covered in MDN's align-items property reference. Although the generated rule can establish a default for every item, the tool does not provide controls for placing individual items, assigning spans, or changing one item's alignment separately.

Why repeat() and minmax() Are Used

The generated repeat() notation avoids a long list of identical track functions. With a count of three, for example, repeat(3, minmax(0, 1fr)) expresses three equal flexible column tracks in a compact form. The same serializer is used for rows, so both axes follow the same predictable pattern.

The zero minimum in minmax(0, 1fr) helps prevent lengthy content from forcing a track wider than its container. It does not guarantee that every piece of content will fit: long words, unbreakable strings, fixed-width children, and other content constraints can still require suitable overflow handling. For a deeper explanation of the relationship between these track functions, see How to Make a CSS Grid Flexible Using fr and minmax.

The gap uses one pixel length for both axes, as described in MDN's gap property reference. A gap of zero is valid and removes the gutter; 100 pixels is the maximum accepted value. The tool is intentionally a bounded visual builder rather than an arbitrary CSS editor, so it does not silently convert an out-of-range value such as 101 into 100.

Validation, Limits, and Copying

The numeric fields use strict whole-number validation. Out-of-range values, signs, decimals, whitespace-padded numbers, unit suffixes, empty fields, and excessively long numeric text produce an explicit error and no generated CSS. Numeric input longer than 32 UTF-16 code units is also rejected. Alignment values must exactly match one of the four supported options.

When any live field is invalid, the preview resets to the documented safe default of three columns and two rows instead of displaying stale or partially interpreted input. Editing a control also removes the previous generated code, old error, and old copy status. Generated code appears only after Generate CSS succeeds.

Large gaps or a twelve-by-twelve grid can make preview cells very small or require scrolling. The generated declarations still preserve the exact valid values entered. All generation and preview work happens locally in the browser, and the generated snippet is neither sent to Lizely nor stored by the tool.

Copying uses the browser's Clipboard API. If permission is denied, the interface leaves the code selectable and displays a manual-copy message instead of claiming that the copy succeeded.

Apply the Grid to Semantic HTML

The generator produces CSS, not an HTML document. Apply the .grid class to a suitable container and place the actual content inside it:

<div class="grid">

  <article>First item</article>

  <article>Second item</article>

  <article>Third item</article>

  <article>Fourth item</article>

  <article>Fifth item</article>

  <article>Sixth item</article>

</div>

Start with meaningful semantic elements and a logical source order. The generator does not create named areas, implicit-track controls, spans, per-item placement, subgrid, masonry, source-order changes, or responsive breakpoints. Visual reordering should not replace meaningful document order because keyboard navigation and assistive technology continue to rely on the underlying structure.

Turn the Generated Grid into a Production Layout

The generated rule describes one explicit grid and does not automatically adapt when the available space changes. If the track count should vary by viewport or container size, add media queries, container queries, an auto-fit pattern, or another template manually. For a fixed dashboard or compact card layout, the explicit result may already match the intended behavior.

Before shipping the layout, review the generated CSS against the actual project:

  • Confirm that the number of tracks still makes sense at narrow and wide widths.
  • Check long content and add appropriate wrapping or overflow rules where needed.
  • Add named areas, spans, or individual placements only when the content requires them.
  • Keep the DOM order logical even if visual positioning becomes more complex.
  • Test the result with keyboard navigation and assistive technology.
  • Retain only the declarations the final design actually needs.

The value of this CSS Grid Generator example is its bounded, inspectable output: fixed choices produce predictable declarations, the live preview exposes the result, and invalid values are rejected instead of being guessed. Use that clarity as the foundation, then adapt the CSS responsibly for responsive behavior, content constraints, and semantics.

Related reading: CSS Loader Generator for Beginners: Settings to Status.