CKTIS / CSS
Grid and subgrid
CSS Grid arranges items in rows and columns. Subgrid lets a nested grid share its parent grid’s tracks in one or both axes, allowing content inside different elements to align.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
.grid { display: grid; grid-template-columns: 100px 200px; gap: 10px; }
.subgrid { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; }display: grid creates a two-dimensional grid. Its in-flow children become grid items. A track is the space between adjacent grid lines: a row or column. grid-template-columns and grid-template-rows define explicit tracks; automatic placement can create additional implicit tracks.
An ordinary nested grid has independent tracks. Setting grid-template-columns, grid-template-rows, or both to subgrid shares the corresponding parent tracks across the area occupied by the item. Content can contribute to the sizing of shared content-sized tracks. No implicit tracks are created in a subgridded axis.
In the example, .row spans all explicit columns through grid-column: 1 / -1. Its children use the parent’s 100px and 200px columns; the shared axis also uses the parent’s 10px gap by default. The rows inside .row remain independent.
Do not use visual placement to repair an incorrect document content order: it does not replace a logical reading and navigation order.
Examples
<!doctype html>
<meta charset="utf-8">
<title>Grid and subgrid</title>
<style>
.grid {
display: grid;
width: 310px;
grid-template-columns: 100px 200px;
gap: 10px;
}
.row {
display: grid;
grid-column: 1 / -1;
grid-template-columns: subgrid;
}
.row > span {
min-width: 0;
background: #ddd;
}
</style>
<div class="grid">
<div class="row"><span>A</span><span>B</span></div>
<div class="row"><span>C</span><span>D</span></div>
</div>Result
A | B C | D Column widths: 100px, 200px. Column gap: 10px.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.