Skip to content

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

WebKit 3 min read How-to mediumAdept

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

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.

Related posts

  • 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.

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

    WebKit mediumAdept

    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.

  • 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.

  • 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.

  • Help us choose the final syntax for Masonry in CSS

    WebKit mediumAdept

    WebKit argues that masonry-style packed layout should be specified as part of CSS Grid ("Just Use Grid", e.g. grid-template-rows: collapse) rather than as a separate display: masonry mode with its own masonry-* properties, as the Chrome team and Rachel Andrew propose. Performance concerns about combining masonry with full Grid track sizing have been resolved, and the CSSWG has adopted mixed track sizing in the Grid Level 3 First Public Working Draft. The remaining dispute is purely syntactic. WebKit cites Bert Bos's design principles (learnability, minimum redundancy, repurposing) and shows side-by-side code where a separate syntax duplicates nearly every grid property and forces developers to switch mental models at breakpoints. The debate was later settled under the name CSS Grid Lanes.

The quest for software engineering knowledge.

Look:
Layout: