Grid lines are numbered from 1 at the start edge. Negative numbers count back from the end of the explicit grid, so -1 is its last line. Four properties (grid-row-start, grid-column-end, …) and the shorthands grid-row, grid-column and grid-area say where an item starts and ends:
- Lines:
grid-column: 2 / 4, or1 / -1for the full explicit width. - Spans:
grid-column: span 2(start wherever auto-placement puts it), or2 / span 2. - Named lines:
grid-template-columns: [content-start] 1fr [content-end]lets you writegrid-column: content-start / content-end. Afoo-start/foo-endpair also creates an implicit area, sogrid-column: contentworks. - Named areas:
grid-template-areasdraws the layout as strings; each name must form one rectangle, and.marks an empty cell. Each area createsname-startandname-endlines, andgrid-area: mainplaces an item there.
Items placed outside the explicit grid create implicit tracks, sized by grid-auto-rows / grid-auto-columns (auto by default).
Auto-placement handles everything else. The algorithm first places items with a definite position, then items locked to a row, then the rest in order-modified document order. With the default grid-auto-flow: row, a cursor moves across each row and down, adding rows as needed; column fills columns instead. The default is sparse: the cursor never moves backwards, so items keep their order and holes can remain. dense restarts the search from the top for each item and fills holes with later, smaller items.
Visual placement never changes reading or tab order. The spec requires the DOM order to stay the logical one, so use dense or reordering placement only where order doesn't carry meaning (more in accessibility).
Items can overlap when placed in the same cells; later items in order-modified DOM order paint on top, and z-index works without position.