CSS Grid Generator
Generate CSS Grid layouts visually. Build CSS grid code with custom columns, rows, and gaps using a visual editor.
Other Text Cleaner Tools
Claude Humanizer
Humanize Claude text to make it sound more natural and human-written.
Open Tool →Grok Research Paper Checker
Check research papers generated by Grok for academic standards.
Open Tool →DeepSeek Copyleaks Checker
Check if DeepSeek content will be detected by Copyleaks AI detection.
Open Tool →CSS Flexbox Generator
Generate CSS Flexbox layout code visually. Set flex direction, wrap, align, justify, and get the CSS instantly.
Open Tool →Perplexity Research Paper Checker
Check research papers generated by Perplexity for academic standards.
Open Tool →Sort Lines Online
Sort lines of text alphabetically, by length, or in reverse order online. Free line sorter tool.
Open Tool →LLaMA (Meta AI) Grammar Checker
Check and correct grammar errors in LLaMA (Meta AI)-generated text.
Open Tool →Robots.txt Generator
Generate robots.txt files for your website. Build SEO-friendly robots.txt with custom rules for search engine crawlers.
Open Tool →CSS Grid Generator: Build Powerful Two-Dimensional Layouts with Precision
CSS Grid Layout is the most powerful layout system available in CSS. Unlike any layout method that preceded it, CSS Grid is explicitly two-dimensional "” it can handle both columns and rows simultaneously, giving you precise control over how elements are placed, sized, and aligned across a complete layout surface. Our CSS Grid Generator provides a visual interface for defining grid templates, placing items, and copying production-ready CSS instantly.
Before CSS Grid achieved stable cross-browser support around 2017, building page-level layouts required float-based frameworks (Bootstrap, Foundation), table-based hacks, or painful combinations of positioning and negative margins. These approaches required rigid HTML structure and often made responsive design needlessly complex. CSS Grid changed everything: with a few declarations on a container, the browser handles complex placement that would have previously required JavaScript measurement.
The Grid Model: Containers, Lines, Tracks, and Cells
Understanding CSS Grid requires familiarity with its core vocabulary:
- Grid container: the element with
display: gridordisplay: inline-grid. Its immediate children become grid items. - Grid lines: the dividing lines that make up the structure of the grid. Horizontal lines divide rows; vertical lines divide columns. Grid lines are numbered from 1 to n+1 where n is the number of tracks. They can also be named.
- Grid tracks: the space between two adjacent grid lines "” essentially a row or column. Tracks are defined by
grid-template-columnsandgrid-template-rows. - Grid cell: the smallest unit of a grid "” the intersection of one row track and one column track. A grid item placed in a single cell occupies one cell.
- Grid area: a rectangular region of the grid defined by four grid lines. A grid item can span multiple cells to occupy a larger area.
Defining the Grid Template
grid-template-columns and grid-template-rows
These two properties define the track sizes for columns and rows respectively. Each value in the space-separated list defines one track:
.container {
display: grid;
grid-template-columns: 200px 1fr 1fr;
grid-template-rows: auto 200px auto;
}This creates a three-column grid where the first column is a fixed 200px, and the remaining two columns share the remaining space equally using the fr unit. Rows are defined with an auto-height first and last row (sized to content) and a fixed 200px middle row.
The fr Unit
The fr (fraction) unit is unique to CSS Grid and represents a fraction of the available free space in the grid container. It is calculated after all fixed-size tracks (pixels, percentages, auto) have been given their space. A column with 2fr receives twice as much free space as a column with 1fr.
grid-template-columns: 1fr 2fr 1fr;
/* First column: 25% of free space
Second column: 50% of free space
Third column: 25% of free space */The fr unit is superior to percentages for track sizing because it respects gap spacing "” percentages would include the gap widths in their calculation, causing overflow.
The repeat() Function
The repeat() function prevents repetitive track definitions:
/* Without repeat */
grid-template-columns: 1fr 1fr 1fr 1fr;
/* With repeat */
grid-template-columns: repeat(4, 1fr);
/* Mixed */
grid-template-columns: 200px repeat(3, 1fr) 200px;auto-fill and auto-fit: Intrinsically Responsive Grids
The most powerful use of repeat() combines it with auto-fill or auto-fit and the minmax() function to create grids that automatically add or remove columns based on available space:
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));This creates as many 280px-minimum columns as fit in the container, with each column growing to fill remaining space. When the container shrinks, columns wrap automatically. The result is a fully responsive grid with no media queries.
The difference between auto-fill and auto-fit:
- auto-fill: creates as many columns as possible, even if some are empty. Empty column tracks are preserved in the grid structure, preventing existing items from growing into them.
- auto-fit: collapses empty column tracks to zero width. Existing items can then grow (via
1fr) to fill the entire container. For most responsive card grids,auto-fitis preferred because items stretch to fill the row on partially-filled rows.
minmax(): Flexible Track Sizing with Constraints
minmax(min, max) defines a track's size as a range. The track is at least min wide and at most max wide:
grid-template-columns: minmax(200px, 1fr) minmax(400px, 3fr);
/* Column 1: between 200px and 1fr
Column 2: between 400px and 3fr */You can use min-content, max-content, auto, and fit-content(value) as min or max values for intrinsic sizing. auto as a max behaves like max-content but participates in fr distribution.
Placing Grid Items
Auto Placement
By default, grid items are auto-placed into the grid following the auto-placement algorithm: items fill cells in row order (left to right, top to bottom) unless explicitly placed. Thegrid-auto-flow property controls this algorithm:
- row (default): fills rows first, adding new rows as needed.
- column: fills columns first, adding new columns as needed.
- dense: can be combined with
roworcolumn"” the algorithm backtracks to fill holes left by large items. Useful for image galleries where items have different sizes but you want a compact layout.
grid-column and grid-row: Explicit Placement
Grid items can be explicitly placed using grid line numbers:
.item {
grid-column: 1 / 3; /* from line 1 to line 3 (spans 2 columns) */
grid-row: 2 / 4; /* from line 2 to line 4 (spans 2 rows) */
}
/* Span keyword */
.item {
grid-column: 1 / span 2; /* start at line 1, span 2 columns */
grid-row: 2 / span 2; /* start at line 2, span 2 rows */
}
/* Negative line numbers count from the end */
.full-width {
grid-column: 1 / -1; /* spans all columns */
}Named Grid Lines
Grid lines can be given names in square brackets for more readable placement:
.container {
grid-template-columns:
[sidebar-start] 250px
[sidebar-end content-start] 1fr
[content-end];
}
.sidebar { grid-column: sidebar-start / sidebar-end; }
.main { grid-column: content-start / content-end; }grid-template-areas: Named Regions for Visual Layout
One of CSS Grid's most impressive features is grid-template-areas, which lets you define the layout visually as an ASCII map of named regions:
.container {
display: grid;
grid-template-columns: 250px 1fr;
grid-template-rows: 60px 1fr 40px;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
height: 100vh;
}
header { grid-area: header; }
.sidebar { grid-area: sidebar; }
main { grid-area: main; }
footer { grid-area: footer; }Each quoted string represents a row. Each word in the string represents a column cell. Repeating a name causes the item to span those cells. Use a period (.) for empty cells. This technique makes complex page layouts self-documenting "” you can read the structure directly from the CSS.
Alignment in CSS Grid
CSS Grid has two sets of alignment properties: those that align the grid tracks within the container, and those that align items within their grid areas.
align-content and justify-content
These properties align the entire grid within the container when the grid is smaller than the container (i.e., when there is free space in the grid container):
justify-content: aligns grid tracks along the inline (horizontal) axis.align-content: aligns grid tracks along the block (vertical) axis.
Both accept start, end, center, space-between, space-around, space-evenly, and stretch.
align-items and justify-items
These properties set the default alignment for all grid items within their respective grid areas:
justify-items: aligns items along the inline (horizontal) axis within their cell.align-items: aligns items along the block (vertical) axis within their cell.
The default value for both is stretch, causing items to fill their grid area. Setting justify-items: center centers all items horizontally within their cells.
align-self and justify-self: Per-Item Overrides
Individual items can override the container's alignment with align-self and justify-self. The place-self shorthand combines both: place-self: center end means align-self: center; justify-self: end.
place-content and place-items Shorthands
place-content shorthand: place-content: center space-between is equivalent to align-content: center; justify-content: space-between. place-items shorthand: place-items: center sets both align-items and justify-items to center.
Implicit Grid: grid-auto-rows and grid-auto-columns
When grid items are placed outside the explicitly defined grid "” either by auto-placement running out of explicit tracks, or by explicit placement beyond the defined lines "” the browser creates implicit tracks. The size of these implicit tracks is controlled by grid-auto-rowsand grid-auto-columns:
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: minmax(100px, auto);
}This ensures that all auto-generated rows are at least 100px tall but expand to fit content. Without this, implicit rows would be sized by the auto keyword (which sizes to content), potentially creating very short rows for small items.
gap, row-gap, column-gap in CSS Grid
The gap property (originally grid-gap) adds gutters between grid tracks:
.container {
gap: 24px; /* equal row and column gap */
gap: 16px 24px; /* row-gap column-gap */
row-gap: 16px;
column-gap: 24px;
}Like Flexbox, gap only applies between tracks "” not at the outer edges of the grid. This makes it superior to padding on items for consistent gutters. The fr unit respects gap in its calculations, so repeat(3, 1fr) with gap: 24px correctly distributes the remaining space after gaps are accounted for.
Subgrid: Nested Grids Aligned to the Parent
CSS Subgrid, now supported in all major browsers (Chrome 117+, Firefox 71+, Safari 16+), allows a grid item that is itself a grid container to use the parent grid's tracks rather than defining its own. This solves the classic problem of nested grid items not aligning to the outer grid:
.card {
display: grid;
grid-template-rows: subgrid;
grid-row: span 3;
}With subgrid, all cards in a row of cards can share the same row tracks from the parent grid, ensuring that card titles, body text, and CTAs align perfectly across all cards regardless of content length "” without any JavaScript height equalization.
Common CSS Grid Layout Patterns
Classic Page Layout
body {
display: grid;
grid-template-areas:
"header"
"main"
"footer";
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}Holy Grail Layout (Header, Footer, Two Sidebars, Main Content)
.app {
display: grid;
grid-template-areas:
"header header header"
"left main right"
"footer footer footer";
grid-template-columns: 220px 1fr 220px;
grid-template-rows: 60px 1fr 40px;
min-height: 100vh;
}Responsive Image Gallery
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-auto-rows: 200px;
gap: 8px;
}
.featured {
grid-column: span 2;
grid-row: span 2;
}Dashboard Layout
.dashboard {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 16px;
}
.widget-wide { grid-column: span 8; }
.widget-narrow { grid-column: span 4; }
.widget-full { grid-column: span 12; }CSS Grid in Practice: Media Queries and Responsive Design
CSS Grid excels at responsive design. Layout changes that required complete HTML restructuring and complex float-based overrides can now be expressed as simple media query changes to the grid template:
.layout {
display: grid;
grid-template-areas:
"sidebar"
"main"
"aside";
grid-template-columns: 1fr;
}
@media (min-width: 768px) {
.layout {
grid-template-areas: "sidebar main aside";
grid-template-columns: 220px 1fr 180px;
}
}The same HTML structure works across all screen sizes "” the layout adapts entirely through CSS.
CSS Grid vs Flexbox: Detailed Comparison
The decision between Grid and Flexbox is fundamental to CSS architecture:
- Dimensionality: Flexbox works in one dimension (a row or a column). Grid works in two dimensions (rows and columns simultaneously). If items must align across both axes, use Grid.
- Content-first vs layout-first: Flexbox is content-first "” the layout is driven by the items' sizes. Grid is layout-first "” the tracks are defined independently of item sizes, and items are placed within them.
- Explicit structure: Grid requires defining the structure upfront (grid lines, areas). Flexbox is more ad hoc and adapts to content. Grid is better when you have a known design structure; Flexbox is better when content is dynamic.
- Spanning: Grid items can span multiple rows and columns easily. In Flexbox, spanning multiple columns in a wrap scenario is not possible without changing the markup.
The best practice is to use both: Grid for the overall page and component layout structure, Flexbox for the internal layout of those components.
Accessibility and CSS Grid
CSS Grid's placement capabilities introduce the same accessibility concern as Flexbox ordering: visual order can diverge from DOM order. When using grid-column, grid-row,order, or grid-template-areas to visually reorder elements, verify that keyboard navigation (Tab key) and screen reader reading order (DOM order) still make logical sense. WCAG 2.1 Success Criteria 1.3.2 and 2.4.3 require meaningful and logical sequence.
Tailwind CSS Grid Utilities
Tailwind CSS provides comprehensive Grid utilities:
<!-- 3-column grid -->
<div class="grid grid-cols-3 gap-4">
<!-- Responsive: 1 col mobile, 3 cols desktop -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- Item spanning 2 columns -->
<div class="col-span-2">
<!-- Auto-fill responsive -->
<div class="grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-4">Key Tailwind Grid classes: grid, grid-cols-{n}, grid-rows-{n}, col-span-{n}, row-span-{n}, col-start-{n}, col-end-{n}, gap-{n}, place-items-center, auto-cols-fr, auto-rows-fr.
Browser Support for CSS Grid
CSS Grid Level 1 is supported in all modern browsers and has been since 2017 (Chrome 57, Firefox 52, Safari 10.1, Edge 16). Global support exceeds 97%. The newer features "” subgrid, masonry layout, container queries integration "” have varying support timelines: subgrid reached all major browsers by 2023 (Chrome 117).
Internet Explorer 11 had an early, prefixed implementation of Grid that was not spec-compliant. IE grid syntax required -ms-grid-column, -ms-grid-row, and other prefixed properties. Autoprefixer can add these automatically for teams that still target IE11.
Using This CSS Grid Generator
Our tool provides a fully visual interface for building CSS Grid layouts. You can define column and row tracks using any valid CSS unit including fr, px, %,auto, minmax(), and repeat(). Place items by dragging them to specific grid areas, set spans, name areas, and configure alignment and gap settings. The generated CSS is clean and production-ready, with Tailwind class equivalents provided alongside. Whether you are prototyping a new page layout or fine-tuning a component's internal structure, the grid generator eliminates the write-refresh-inspect cycle and makes CSS Grid's full power immediately accessible.
Frequently Asked Questions
Common questions about the CSS Grid Generator.
FAQ
Basics
1.What is CSS Grid and what problems does it solve?
CSS Grid Layout is a two-dimensional layout system that lets you define explicit row and column tracks and place items precisely within them. It solves the long-standing problem of building page-level layouts in CSS without hacks: equal-height columns, spanning items across multiple tracks, and aligning items in two directions simultaneously were all difficult or impossible before Grid.
2.How do I create a CSS Grid container?
Apply display: grid (block-level) or display: inline-grid (inline-level) to the parent element. Its immediate children automatically become grid items. Define the grid structure with grid-template-columns and grid-template-rows. Without these, items will be placed in a single-column grid with auto-sized rows.
Tracks
3.What is the fr unit and how does it differ from percentages?
The fr (fraction) unit represents a share of the remaining free space after fixed-size tracks and gaps are accounted for. Unlike percentages, fr units automatically adjust for gaps: repeat(3, 1fr) with gap: 20px gives three equal columns that together fill the container minus the two 20px gaps. Percentages would overflow because they are calculated from the total container width before gaps.
4.How does repeat(auto-fill, minmax(280px, 1fr)) work?
auto-fill tells the browser to create as many column tracks as fit in the container without overflow. minmax(280px, 1fr) sets each track to be at least 280px wide and at most 1fr (sharing available space). The result: as many columns as fit at ≥280px each, with columns growing to fill the row. This creates a fully responsive grid without media queries.
5.What is the difference between auto-fill and auto-fit?
Both create as many columns as fit, but auto-fill preserves empty column tracks (their space is reserved but unused), while auto-fit collapses empty tracks to zero width. With auto-fit and 1fr, items grow to fill the entire row even when there are fewer items than maximum columns. auto-fit is usually preferred for card grids where you want items to stretch; auto-fill is better when you want to maintain fixed column positions for future items.
Placement
6.How do I span a grid item across multiple columns?
Use grid-column: start / end (line numbers) or grid-column: span n (span keyword). For example, grid-column: 1 / 3 spans from line 1 to line 3 (2 columns), and grid-column: span 2 spans 2 columns starting from the auto-placed position. grid-column: 1 / -1 spans all columns (negative numbers count from the end).
7.How does grid-template-areas work?
grid-template-areas lets you define named regions as a visual ASCII map. Each quoted string is a row; each word in the string is a column cell. Repeat a name to span that region across multiple cells. Use a period for empty cells. Assign items to regions with grid-area: name. This makes complex layouts visually readable directly in the CSS.
8.What is the auto-placement algorithm?
When grid items are not explicitly placed, the auto-placement algorithm places them into the grid in document order, filling each row left-to-right before moving to the next row (grid-auto-flow: row). You can change the direction to column, or add the dense keyword to backfill holes left by large items. Items that are explicitly placed can leave gaps that auto-placed items skip over by default.
Alignment
9.What is the difference between justify-items and justify-content in Grid?
justify-items aligns each grid item within its own grid area (cell). justify-content aligns the entire grid (all the tracks together) within the grid container when there is free space in the container. Similarly, align-items aligns items within their cells vertically, while align-content aligns the rows within the container. The place-items and place-content shorthands combine these pairs.
10.How do I center a grid item both horizontally and vertically within its cell?
On the item: place-self: center (shorthand for align-self: center; justify-self: center). Or on the container: place-items: center to center all items in their cells. For centering one item in the entire container, use the container as a single-cell grid: display: grid; place-items: center.
Sizing
11.How do implicit grid tracks differ from explicit grid tracks?
Explicit tracks are those you define in grid-template-columns and grid-template-rows. When items are placed or auto-placed beyond the explicit grid, the browser creates implicit tracks. Their size is controlled by grid-auto-columns and grid-auto-rows, which default to auto (sized to content). Setting grid-auto-rows: minmax(100px, auto) ensures all implicit rows are at least 100px tall.
12.What does minmax() do and when should I use it?
minmax(min, max) defines a size range for a track. The track is at least min and at most max. minmax(200px, 1fr) means the track is at least 200px but can grow to fill available space. minmax(0, 1fr) is equivalent to 1fr. minmax(auto, 1fr) allows the track to shrink to its min-content size but grow beyond that. It is especially useful for grid-auto-rows to create rows that are tall enough for content.
Advanced
13.What is CSS Subgrid and why is it useful?
Subgrid lets a nested grid item inherit its parent grid's tracks rather than defining new tracks. This solves the alignment problem in nested grids: without subgrid, items inside a grid item cannot align to the outer grid. With subgrid, items in cards, list items, or nested components can all align to the same outer grid lines. Subgrid is supported in Chrome 117+, Firefox 71+, and Safari 16+.
14.How do I name grid lines and why is it useful?
Add names in square brackets in the track definition: grid-template-columns: [sidebar-start] 250px [sidebar-end content-start] 1fr [content-end]. Items can then use these names for placement: grid-column: sidebar-start / sidebar-end. Named lines make layout code more readable and maintainable, especially in large projects where column numbers are hard to remember.
Responsive
15.How do I change a grid layout at different screen sizes?
Use media queries to change grid-template-columns, grid-template-areas, or any other grid property. For example, switch from a single-column stacked layout to a multi-column layout at a breakpoint. The same HTML works across all sizes. For automatic responsiveness without media queries, use repeat(auto-fill, minmax(min-width, 1fr)) which adjusts column count based on available space.
16.Can I combine CSS Grid with CSS Container Queries?
Yes. Container queries let you change the grid layout based on the size of the container rather than the viewport, enabling fully encapsulated responsive components. A card component can switch from a stacked to a side-by-side layout when its container is wide enough, regardless of where it is placed on the page. Define @container on the parent and use @container (min-width: 400px) to change the grid inside.
Gaps
17.How does gap work in CSS Grid?
gap (shorthand for row-gap and column-gap) adds gutters between grid tracks "” both row and column tracks. It does not add space at the outer edges of the grid container. The fr unit respects gaps in its calculations. gap: 20px on a grid with repeat(3, 1fr) columns divides the space minus 2 × 20px (the two gaps) among three equal columns.
Frameworks
18.How do I use Tailwind CSS for Grid layouts?
Tailwind provides grid, grid-cols-{n}, grid-rows-{n}, col-span-{n}, row-span-{n}, gap-{n}, and alignment utilities like place-items-center. For auto-responsive grids, use arbitrary value syntax: grid-cols-[repeat(auto-fill,minmax(280px,1fr))]. Responsive prefixes (sm:, md:, lg:) apply to all grid utilities for breakpoint-based layout changes.
Grid vs Flexbox
19.When should I use CSS Grid instead of Flexbox?
Use Grid when: (1) layout requires alignment in two dimensions (rows and columns); (2) items must span multiple rows or columns; (3) you have a defined layout structure that items must fit into; (4) you need grid-template-areas for named, readable layout zones; (5) you are building a page-level or component-level template. Use Flexbox for one-dimensional flows "” navigation bars, button groups, card lists.
Debugging
20.How do I debug CSS Grid layouts in browser DevTools?
Both Chrome DevTools and Firefox DevTools have dedicated Grid inspectors. Click the "grid" badge next to a grid container in the Elements panel (Chrome) or Layout tab (Firefox) to overlay grid lines, track sizes, and area names on the page. Firefox's Grid inspector is particularly powerful, showing numbered lines, named lines, and area names simultaneously. You can also inspect grid-template-columns and grid-template-rows computed values.
Accessibility
21.What accessibility issues should I be aware of when using CSS Grid?
Visual order diverging from DOM order is the primary concern. When grid-column/row placement, grid-template-areas, or the order property creates a visual order different from the DOM, screen readers and keyboard navigation follow DOM order. Verify that Tab order and screen reader reading order still make sense. WCAG 2.1 Success Criteria 1.3.2 (Meaningful Sequence) and 2.4.3 (Focus Order) require logical, predictable navigation.
Browser Support
22.What is CSS Grid browser support in 2025?
CSS Grid Level 1 has full support in all modern browsers since 2017 (Chrome 57, Firefox 52, Safari 10.1, Edge 16) "” global coverage exceeds 97%. The gap property has been universally supported since 2020. Subgrid reached all major browsers by late 2023. Internet Explorer 11 has a non-standard prefixed implementation; IE is below 0.5% market share and most teams no longer target it.
Performance
23.Does CSS Grid have any performance implications?
CSS Grid layout is handled entirely by native browser code and is extremely fast for the vast majority of layouts. Using intrinsic sizing (auto, min-content, max-content) on many tracks can require multiple browser measurement passes; prefer explicit sizes or fr units when track counts are large. Subgrid adds a cross-tree layout dependency but is still managed natively without JS overhead.
Patterns
24.What is the "Holy Grail" layout and how do I implement it with CSS Grid?
The Holy Grail layout has a header, footer, main content, and two sidebars "” all full-height, with the main content between the sidebars. With CSS Grid: .app { display: grid; grid-template-areas: "header header header" "left main right" "footer footer footer"; grid-template-columns: 220px 1fr 220px; grid-template-rows: 60px 1fr 40px; min-height: 100vh; }. This was notoriously difficult to implement with floats or older techniques.