Web from the future

@webfromfuture · RSS · Newsletter

Subgrid

117
16.0
71
No

One thing that visually separates human-made designs from nature is alignment. In nature, things aren’t aligned. Humans like to align things. It makes it easier for us to understand.

Alignment has been a big topic in CSS since its inception. From the old meme of “how to vertically center in CSS” to display: flex and display: grid we made a lot of progress. Now it’s time for the next step: subgrid.

If you give display: grid to a parent element, the children will become grid items. But the children’s children will not be part of the main grid. This can sometimes lead to alignment issues.

See this example:

Three cards with text and pictures aligned one next to the other. The internal parts are not aligned among them.

The three cards are aligned next to each other in a grid, but the titles are not aligned. The first picture’s top is lower than the other two. The text blocks at the bottom are all misaligned.

Compare this to the same example but using subgrids:

Three cards with text and pictures aligned one next to the other. The internal parts are aligned among them.

You can see this live if your browser supports subgrid:

Learn more about subgrid following the links below.


Scroll driven animations
See all 🔮
CSS nesting