Short answer
CSS Grid is the layout used when rows and columns must line up together. MDN describes a grid as intersecting horizontal and vertical lines for page areas or small interface pieces. CSS Grid Level 2 says a grid container's children can sit in fixed or flexible slots. Flexbox remains a one-axis tool. Span, named areas, and the fr unit are the placement controls.
Last verified against the sources listed below.
Key takeaways
- MDN defines a grid as intersecting horizontal and vertical lines that form rows and columns.
- display: grid or display: inline-grid makes the element's direct children into grid items.
- The fr unit is a fraction of free space in the grid container, after fixed tracks are accounted for.
- span N on a placement property covers that many tracks from the start or end line.
- Flexbox lays out one axis. Grid lays out rows and columns at the same time.
- Level 2 adds subgrid, so a nested grid can use its parent's track sizes.
What is CSS grid used for is a two-dimensional layout: rows and columns at the same time. MDN’s basic concepts guide calls a grid a set of intersecting horizontal and vertical lines, and says it can lay out major page areas or small interface pieces.
CSS Grid Layout Module Level 2, a W3C Candidate Recommendation Draft dated 26 March 2025, says the children of a grid container can be positioned into slots in a fixed or flexible grid. Level 2 adds subgrid so a nested grid can share its parent’s track sizes.
That sits inside the wider job of what CSS is used for. Grid does not replace color, type, or the cascade. It replaces guessing at column edges with lines the browser can count.
What is CSS grid layout?
A grid layout starts when an element becomes a grid container. MDN says display: grid or display: inline-grid does that, and every direct child becomes a grid item.
Rows and columns are tracks. A track is the space between two adjacent lines. You size the explicit tracks with grid-template-columns and grid-template-rows. MDN’s example 200px 200px 200px is three fixed column tracks.
The fr unit is a fraction of the free space in the container. 1fr 1fr 1fr is three equal columns. 2fr 1fr 1fr gives the first column twice the free space of each of the others.
Fixed lengths are subtracted first. MDN notes that a large item inside a track leaves less free space to share.
The specification’s own illustration is blunt. A grid with a 150px first column and a flexible second column is 50px in the second column when the container is 200px wide, and 0px when the container is 100px wide. Content in that second column then overflows.
How CSS grid works
The specification walks the layout in a set order. You declare the grid, place the items, size the tracks, align the grid in the container, then align each item in its area.
Placement can be explicit or automatic. Explicit placement uses line numbers, named lines, or named areas. Automatic placement fills empty cells. MDN says items that were not given a position still get a cell from that algorithm.
More than one item may occupy one cell, and they can overlap. MDN says z-index controls that layering. Float and clear do not move a grid item. The specification says a grid container’s margins do not collapse with the margins of its contents.
| Piece | Property the spec or MDN names | What it controls |
|---|---|---|
| Container | display: grid | Turns direct children into grid items |
| Tracks | grid-template-columns, grid-template-rows | Sizes the explicit rows and columns |
| Free space | fr | Shares leftover space after fixed tracks |
| Cell | grid-column, grid-row, or grid-area | Puts an item between lines or into a name |
| Extra tracks | implicit grid | Adds rows or columns when an item lands outside |
| Alignment | align-items, justify-content | Moves items or the whole grid in its space |
The editor’s draft is the living copy the specification links. The published Candidate Recommendation is the text quoted here.
What is span in CSS grid?
Line numbers count the lines, not the tracks. A three-column grid has four column lines. An item from line 1 to line 2 occupies the first track only.
MDN’s line-based placement guide shows the span keyword when you know the start and the count, not the end number. grid-row-start: 1 with grid-row-end: span 3 covers three tracks and ends at line 4.
You can reverse it: set the end line to 4 and the start to span 3, and the area still runs from line 1 to line 4. Span works on columns the same way. It does not change the track size. It only chooses how many tracks the item covers.
What is CSS grid and flexbox?
MDN’s comparison is the one to keep. Flexbox was designed for one dimension, either a row or a column. Grid was designed for two dimensions at once. Both use CSS box alignment.
A wrapped flex row is a new flex line. Items on that line share space with each other, not with the row above, so the columns do not have to line up. The same five items in repeat(3, 1fr) stay in three columns, with an empty cell at the end of the second row.
MDN adds a second test. Flexbox works from the content out: the item’s size helps decide the space. Grid works from the layout in: you define tracks, then items fall into them. If you are setting a width on a flex item only so it lines up with the row above, MDN says a grid is likely the better choice.
| Question | Flexbox, per MDN | Grid, per MDN and the spec |
|---|---|---|
| Axes | One, a row or a column | Rows and columns together |
| Wrapped lines | Each line shares space on its own | Tracks stay aligned down the grid |
| Starting point | Content out | Layout in |
| Flexible size | flex-grow, flex-shrink, flex-basis | fr, often with minmax() |
| Nested alignment | Not shared with a parent line | subgrid can share the parent tracks |
The specification also says media queries can change the grid when the device or the space changes, without a new HTML structure. That is the layout half of responsive web design.
What is a CSS grid system?
A grid system, in this module, is the set of tracks you name and reuse. grid-template-areas draws the map with strings, and each string is a row. Repeated names merge cells. A period is an empty cell.
.page {
display: grid;
grid-template-columns: 12rem 1fr 16rem;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
}
.main { grid-area: main; }
The header area spans three columns because the name is repeated. The main item only needs grid-area: main. MDN says an area has to be a rectangle, so you cannot notch one cell out of the middle and call it one area.
A CSS grid generator is a way to sketch those tracks and read the declarations back. The generator does not change the specification. It only prints the properties this guide names.
repeat(auto-fit, minmax(200px, 1fr)) is the responsive form MDN shows. The browser fits as many columns as it can at a minimum of 200px, then gives the leftover space to the 1fr maximum. The count of columns changes with the container. The items still share rows.
What is advanced CSS grid?
Subgrid is the Level 2 feature. The specification says a subgridded axis matches its lines to the parent grid and derives its track sizes from that parent. The nested items then participate in the parent’s intrinsic sizing.
You opt in with the keyword. The spec’s pattern is grid-template-columns: subgrid on a grid item that is itself a grid container. One axis or both axes can be subgridded. A grid with no subgridded axis is a standalone grid.
That is how a list of form rows can keep labels in one column and inputs in the next, even though each row is its own element with its own border. A normal nested grid would size its columns alone, and the labels would not share a line.
If the box has no parent grid, or it is forced into an independent formatting context, the used value is none. Absolute positioning is one of the cases the specification names. The item is then not a subgrid.
The Candidate Recommendation points at a subgrid test report. This guide does not quote a pass rate from that report.
What people get wrong
These are mismatches with the pages above, not a style preference.
- Treating flex wrap as a grid. MDN says each wrapped flex line is independent, so the second row will not line up unless you switch to grid.
- Counting tracks when the property wants lines. Span 3 from line 1 ends at line 4, not line 3.
- Expecting an L-shaped area. MDN says grid areas are rectangles.
- Assuming a nested grid shares the parent’s columns. It does not, unless that axis is a subgrid.
- Putting
fron an item. Thefrunit sizes tracks on the container. The item is placed into the tracks. - Setting a width on every flex item only to fake columns. MDN says that is a sign you wanted grid.
Frequently asked questions
What is CSS grid layout in one sentence?
CSS grid layout is a two-dimensional system for placing an element's children into rows and columns. MDN says you start it with display grid or display inline-grid, and every direct child becomes a grid item. The CSS Grid Level 2 specification says those children can be positioned into slots in a fixed or flexible grid. The lines that bound the slots are the grid lines, and the space between two adjacent lines is a track.
What is the CSS grid and flexbox difference?
MDN says flexbox was designed for one dimension, a row or a column, and grid was designed for rows and columns at the same time. Wrapped flex lines do not have to line up with the line above them, because each flex line distributes space on its own. A grid with three equal columns keeps items in those columns. MDN also says flexbox works from the content out, while grid works from the layout in.
What is span in CSS grid?
Span is a keyword on the placement properties, not a track size. MDN shows grid-row-end set to span 3, which means the area covers three tracks from the start line. If the item starts at row line 1, span 3 ends it at row line 4. You can put span on the start instead, and the area grows backward from the end line. The same keyword works on columns. The area still has to be a rectangle.
How does CSS grid work with a named area?
The CSS Grid specification says a grid area is the space used to lay out one or more items, bound by four grid lines. You can name that rectangle with grid-template-areas on the container, then assign an item with grid-area. Items in the same area do not size each other directly, though an item with an intrinsic track size can change the track and therefore the other item. Areas must be rectangular. MDN notes that an L shape is not a valid grid area.
What is advanced CSS grid?
Level 2 adds subgrid. The specification says a subgridded axis matches its grid lines to the parent grid and takes its track sizes from that parent. You establish it with the subgrid keyword on grid-template-rows or grid-template-columns, on one axis or both. The subgrid's items then participate in the parent's sizing, so nested labels can share one set of columns. If there is no parent grid, the used value is none and the box is not a subgrid.
Sources
- Basic concepts of grid layout · MDN, 2026
- Relationship of grid layout to other layout methods · MDN, 2026
- Grid layout using line-based placement · MDN, 2026
- CSS Grid Layout Module Level 2 · W3C, 2025
- CSS Grid Layout Module Level 2, editor's draft · CSS Working Group, 2026
- CSS Grid subgrid tests · web-platform-tests, 2026