Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

WebKit 4 min read How-to mediumAdept

Subgrid: how to line up elements to your heart’s content

CSS subgrid lets nested grid items adopt the row or column tracks defined on a parent grid, so content inside sibling cards stays aligned even when one card has longer text. A pricing-page walkthrough shows the three steps: make each card a grid, set grid-template-rows: subgrid, define matching rows on the parent (grid-template-rows: repeat(4, auto)), and have each card span them with grid-row: span 4. Skipping the span collapses all card content onto one row. Subgrid is supported across major browsers and safe to use.

Related posts

  • Help us invent CSS Grid Level 3, aka “Masonry” layout

    WebKit mediumAdept

    CSS Grid Level 3, often called masonry or waterfall layout, adds `grid-template-rows: masonry` so content packs into columns without rows, with no JavaScript and no cropping. Building it into Grid rather than a separate `display: masonry` keeps Grid's full column-sizing power: mixed fixed and flexible tracks, fr ratios, max-content, minmax and auto-fill. It also keeps spanning, subgrid and explicit placement, which enable layouts like asymmetric photo galleries, mega menus and lively article listings. The WebKit team demonstrates these with live demos and asks developers to weigh in on the CSS Working Group debate. An update notes that a W3C Working Draft now includes these abilities, while the syntax is still unsettled.

  • CSS Grid: A helpful mental model and the power of grid lines

    WebKit mediumAdept

    CSS Grid becomes easier to reason about when a layout starts from the container, treated like a spreadsheet whose columns and rows are defined before content is placed. Template properties (grid-template-columns/rows) set the container's blueprint, grid-row/grid-column place individual children, and grid-auto-rows/columns size tracks for unplanned content. The key idea is positioning by numbered grid lines rather than by row or column, using the start/end slash syntax (e.g. grid-row: 1/3). A worked example also shows that auto-placement gives explicitly positioned items priority, so a spanning item may need an explicit column to stay where it belongs.

  • Grid: how grid-template-areas offer a visual solution for your code

    WebKit mediumAdept

    CSS Grid's grid-template-areas lets you place elements by naming them with the grid-area property and then drawing the layout as rows of quoted strings, where repeating a name across cells makes an element span rows or columns. A product-card page shows the technique: an add-ons card spans two rows and a testimonial spans two columns in a three-column grid. The upfront cost is naming each element. In return, all placement decisions live in one readable property, and you change the layout by moving names between cells.

  • When will CSS Grid Lanes arrive? How long until we can use it?

    WebKit mediumAdept

    CSS Grid Lanes, the masonry-style layout from CSS Grid Level 3, ships with its finalized `display: grid-lanes` syntax in Safari Technology Preview. Firefox has an older flagged implementation using `grid-template-*: masonry`, and Chromium is updating its alternative implementation to the agreed syntax. Developers can adopt it now with progressive enhancement in one of three ways: feature-query and conditionally load Masonry.js only where `CSS.supports('display','grid-lanes')` fails, fall back to Multicolumn (which flows content in a different order and changes tab order), or declare `display: grid` then `display: grid-lanes` so unsupported browsers keep a Grid Level 1 layout. In the Grid fallback, `aspect-ratio`, `object-fit` and `-webkit-line-clamp` force the cards to equal sizes.

  • Introducing CSS Grid Lanes

    WebKit mediumAdept

    CSS Grid Lanes (`display: grid-lanes`) brings native masonry layouts to the web, available in Safari Technology Preview 234. Lanes are defined with standard `grid-template-columns` or `grid-template-rows`. Each item goes into whichever lane leaves it closest to the start, so tab order follows visible content and infinite scroll needs no JavaScript layout. Grid features such as spanning, explicit placement and varied lane sizes all work, and flow direction (waterfall vs. brick) is inferred from which template is defined. A new `fit-tolerance` property (default 1em, formerly `item-tolerance`/`flow-tolerance`) treats near-equal lane heights as ties to reduce reordering that confuses keyboard and screen reader users.

The quest for software engineering knowledge.

Look:
Layout: