CSS Grid Generator
Build responsive or fixed CSS Grid rules with auto-fit and auto-fill options, fit estimates, plus narrow-container safeguards and starter HTML.{{ summaryHeading }}
{{ summaryLine }}
{{ codeExportStatus }}
{{ values.css_text }}
Layout Preview
The chart renderer is unavailable. Exact fit estimates remain available in Property Ledger exports.
| Scope | Property | Value | Layout role | Implementation note | Copy |
|---|---|---|---|---|---|
| {{ row.scope }} | {{ row.property }} | {{ row.value }} | {{ row.role }} | {{ row.note }} |
{{ codeExportStatus }}
{{ values.html_text }}
A grid track is a promise about how much room a row or column may use. Fixed tracks make the count predictable. Responsive tracks protect a useful minimum and let the browser change the count as the container grows or shrinks. That choice shapes card galleries, dashboards, feature lists, image collections, and form layouts long before individual items are styled.
CSS Grid lays direct children into rows and columns. Explicit tracks come from properties such as grid-template-columns; implicit tracks are created when auto placement needs more room. Gaps sit between tracks, so increasing a column gap can reduce the number of responsive columns that fit.
| Strategy | Track behavior | Best fit |
|---|---|---|
auto-fit | Creates as many tracks as fit, then collapses empty repeated tracks. | Cards should stretch when there are fewer items than available slots. |
auto-fill | Creates as many tracks as fit and keeps empty repeated tracks reserved. | Slot-like layouts should preserve the empty track rhythm. |
| Fixed count | Creates an exact number of equal minmax(0, 1fr) tracks. | The design owns the column count and handles responsive changes elsewhere. |
A responsive pattern commonly combines repeat(), auto-fit or auto-fill, and minmax(). The minimum protects card readability; 1fr lets surviving tracks share leftover space. Wrapping the minimum as min(100%, value) prevents a chosen minimum from forcing overflow when the entire container becomes narrower than one track.
Auto placement fills available cells according to grid-auto-flow. Dense placement may backfill an earlier empty cell with a later item, improving visual packing without changing document order. That can make the visual sequence differ from keyboard focus and screen-reader reading, so dense layouts require an explicit order review.
- Choose minimum track width from real content, not from a device label.
- Test long words, images, form controls, and nested components that may have intrinsic minimum sizes.
- Use fixed columns only when another responsive rule will reduce the count before tracks become unusably narrow.
A projected column count is planning evidence, not the browser's full track-sizing result. Fonts, writing mode, item minimums, percentage resolution, surrounding CSS, scrollbars, and container constraints can change the rendered grid.
How to Use This Tool:
Choose the track strategy before spacing or alignment because it determines whether the browser or the stylesheet owns the column count.
- Enter the Container selector. Braces, semicolons, control characters, and selectors longer than 120 characters are rejected.
- Select Responsive auto-fit, Responsive auto-fill, or Fixed columns. Set a minimum track from 1 to 1600 in responsive modes, or a whole column count from 1 to 12 in fixed mode.
- Set row and column gaps from 0 to 999 and choose their shared unit. Equal values become one
gapvalue; unequal values are emitted as row gap followed by column gap. - Choose item alignment and set Preview items from 1 to 24. The item count changes the preview, fit estimate, and starter HTML, not the core track rule.
- Open Advanced to guard narrow responsive containers, size implicit rows, change auto-placement direction, align the whole grid, or add a two-column featured-item rule.
- Compare Grid CSS, Layout Preview, and Fit Profile. Treat the profile as an estimate, then test the copied CSS with real content at the smallest and largest expected container widths.
Interpreting Results:
The generated grid-template-columns value carries the central layout decision. In responsive mode, verify the minimum track and whether empty tracks should collapse. In fixed mode, verify that the chosen count remains readable at every width where the rule applies.
Fit Profile estimates columns and rows at 320, 480, 640, 768, 1024, and 1280 pixels. It assumes simplified unit conversions and does not measure actual child content. A favorable estimate can still overflow when a grid item has an unbreakable minimum width.
Warnings identify the estimate's assumptions and order risks. Test ch, em, rem, and percentage choices in the target typography; review dense placement against source and focus order; and check that a featured two-column span does not land in a one-column fixed grid.
Technical Details:
The generated grid always establishes a grid formatting context, emits a column track list, and emits spacing. Non-default implicit-row sizing, auto flow, item alignment, whole-grid alignment, and the featured child span appear only when selected.
Transformation Core:
| Choice | Generated track expression |
|---|---|
| Fixed count C | repeat(C, minmax(0, 1fr)) |
| Responsive K with minimum M | repeat(K, minmax(M, 1fr)) |
| Responsive with narrow guard | repeat(K, minmax(min(100%, M), 1fr)) |
| Equal row and column gaps | gap: value; |
| Unequal gaps | gap: row column; |
Here, K is auto-fit or auto-fill. The responsive minimum accepts pixels, root or element ems, character units, or percentages. A fixed grid uses a zero floor inside each fractional track so content-based minimums are less likely to force unequal columns.
Formula Core:
The fit estimate converts the minimum track and column gap to pixels for each sample width, then counts how many minimum tracks fit with their intervening gaps.
W is sample container width, G is column gap in pixels, M is minimum track width in pixels, N is preview item count, C is projected columns, and R is projected rows. auto-fit caps C at N because empty tracks collapse; auto-fill keeps C at the possible track count. Fixed mode uses the selected column count directly.
For the estimate, rem and em use 16 pixels per unit, ch uses 8 pixels, and percentages use the sample container width. For example, at 768px with a 220px minimum and 24px gap, floor((768 + 24) ÷ (220 + 24)) gives 3 possible columns. Eight items then project to ceil(8 ÷ 3) = 3 rows.
These conversions are deliberately simpler than browser layout. The active font can change em and ch; intrinsic item sizing can enlarge tracks; and percentage gaps participate in layout according to CSS sizing rules. The preview and fit estimate therefore support comparison, not final acceptance.
References:
- CSS Grid Layout Module Level 2, W3C.
- How to create an auto-fit CSS grid layout, Simplified Guide.
- How to create a two-column CSS grid layout, Simplified Guide.