#1003: CSS Masonry Layout
Discussions
Log in to see TAG-private discussions.
Discussed
Oct 1, 2024 (See Github)
Tess: we're going to get a design review request for "masonry" - it's not a dispute escalation. They are not asking us to solve their problem. The chairs of the css-wg want the Tag to weigh in on this before they make the decision. We should not treat it like a dispute ...
Martin: we should call a spade a spade
Tess: they want our input by mid-November...
Jeffrey: asked them to talk to each other - Elika and Rachel will do that in the next week.
Tess: masonry layout is (like pinterest) - is it a new kind of thing or is it a flavour of grid? Good arguments on both sides... Not a clear right answer. There is 2 and a half implementations... mozilla, webkit, chrome in progress...
Peter: I'm aware of the issue ... at the end of the day are their behavioural changes?
Tess: basic functionality, use cases, are the same ; all addressable by either. It's not just bikeshedding. It's about extensibility of css over time... That architectural question is non-obvious.
Dan: clear developer complexity thing?
Tess: one of the arguments that's being made - you're doing a responsive layout - if you want to sometimes be doing grid and sometimes be doing masonry then that makes an argument one way... But do people actually want to do that? Don't know because they're not doing it now...
Peter: you could still switch display types - but it might have extra complexity.
Tess: some scenarios might be more complex than the other...
Peter: is there a fundamental arch principle?
Jeffrey: both sides are claiming arch principles support their side.
Tess: they're both right. I don't want to push CSS wg one way or the other...
Martin: only thing we can contribute is being the detached [view]
Comment by @jyasskin Oct 14, 2024 (See Github)
This comment is just from me, without having consulted the rest of the TAG yet.
I see that we have a compelling description of the use case (Yay for solving this problem!) and a pair of documents advocating for the alternative syntaxes. It's not clear whether both sides agree with the claims in each document and just weigh them differently, or also disagree about some of the factual claims. I'm not confident that the TAG will know enough about the design space to figure out what facts are true, although we may be able to help weigh tradeoffs.
Would it be possible for the two sides to get together and produce a consensus document that describes the disagreement and points out the different values that the TAG should be weighing?
Comment by @rachelandrew Oct 15, 2024 (See Github)
As the author of the two Chrome posts on the subject, I'd be happy to help create a consensus document. I also have collected developer feedback on the issue.
Comment by @fantasai Oct 31, 2024 (See Github)
I'm happy to work with @rachelandrew on this.
Discussed
Nov 1, 2024 (See Github)
Lea: The spec's intro is great but isn't an explainer. I agree with Webkit's argument to re-use syntax. I'm reasonably familiar with authoring grid and flexbox. Masonry examples were hard to understand with separate syntax. They're trying to be similar to flexbox, but having to comprehend an entirely new model was difficult. It's optimized to change one property to go from vertical to horizontal, but I've never needed that. With grid, I already understood how to make a template, and could port that understanding to masonry. But I'm still not sure how to do my top use case. I needed to apply a layout multiple times: gallery of images. Dont' want to apply a grid, so images almost always want some kind of masonry. Horizonally, with tracks between a min and max, and fill rows completely. Or vertically, and set a range of column widths. Some ideas of what to try with the grid-integrated syntax, but I'm not 100% sure. But I'm not confident they would work. One Chrome argument is you coudl have better default behavior w/ separate display mode. You could have smart defaults. If a part of the template is masonry, use that default. Also, Chrome's argument about re-using patterns instead of properties: I sympathize in general, but if we go that route, we should re-use more.
Jeffrey: What do you think about my review?
Lea: Don't disagree with much, but a lot is lower-level. Big picture dilemma about whether to re-use or not. There are warts either way. Slightly prefer to live with the integrated grid warts.
Tess: I mind ishadeed's examples compelling: https://ishadeed.com/article/css-grid-masonry/. Brevity of grid-integrated approach is compelling.
Jeffrey: I wasn't sure that it's likely to need to switch between the two layouts at a breakpoint. WebKit's argument shows that switching is easier with grid-integrated, but is that really going to be a common need?
Peter: Masonry isn't a grid, in the abstract sense. Grid is great because it replicates a hundreds-of-years-old layout system. Don't want to massage it into doing everything, instead of just making it do grid well.
Lea: Looking at ishadeed's article, I don't think it shows switching because it's common, but to show the delta between what's known and what is new. It shows how little you need to learn. Dont' think fallback shoudl guide the decision.
Jeffrey: A good use of the TAG opinion is to help guide which principles probably matter.
Lea: Authors struggle with existing layout modes. "You use flex to use 1-d, grid to use 2-d." Masonry is in between. Adding a third thing adds to the confusion. Maybe make it piggy-back on flex.
Jeffrey: Since I don't know grid, I find that I bounce off of it because it's complicated. I learned flexbox fairly easily, and masonry seems similarly simple, but making people learn grid before masonry may be an obstacle to learning masonry.
Lea: Wrapping flexbox, comes close to a horizontal masonry. But designers don't like that idea.
Tess: Trying to reason about what we think is intuitive, isn't great. 1) The thing you know is intuitive, and the thing you don't know isn't intuitive. Flexbox has been usable for longer than grid. So think the idea of masonry being kinda like flexbox is interesting.
Lea: Think we're thinking of different cases: cases where flexbox is genuinely more intuitive. More control over items themselves. Better for having an arbitrary number of items. Grid is more specific, aside from autofill. Some weird semantics.
Jeffrey: We should try to approach feedback.
Lea: We're the wrong people to figure out what's intuitive. User research! Give authors a prototype of each syntax, and see what they do.
Jeffrey: Let's include that in our comment.
Jeffrey and Lea to collaborate in a Google doc.
Tess: Consider not giving feedback, since the experts are already arguing.
Jeffrey: I want to point out the "bad" argument from both sides.
Tess: And the good arguments!
Peter: Maybe help give them a framework to make the decision.
...
Tess: There are probably some properties here that shouldn't include either "grid" or "masonry" in their names, but should apply to both, maybe in slightly different ways.
Peter: Useful to have things that define the shape of the grid, and another class of things that sit on top of the grid and snap to grid lines.
Discussed
Nov 1, 2024 (See Github)
See the rough draft and suggested changes in https://docs.google.com/document/d/1hC4l_9PkhMhvd1J_KRpN8WXlvrOeGq53eLESsyYzC38/edit?tab=t.0.
Martin: I liked these comments
tess: Yes. I fed in my comments.
[discussion of edits into the google doc]
Was hoping that Lea could've been here to review. But we should not make them delay another week.
Martin: yeah, this is important enough to give a good anount of feedback to
Hadley: are we set?
Jeffrey: let's go through the comments.
Tess: I'm concerned about lumping this in with multicall. multicall is about fragmentation. I'm concerned it will cause confusion.
Jeffrey: yes, and we don't want to say "deal with fragmentation and all the others stuff".
Tess: wrapping flexbox is sufficient to cover the other things. It's a good one, as part of a non-exhaustive list. Are we trying to be exhaustive? If not, then including multicall causes more trouble than good.
Jeffrey: [makes relevant edits]
Peter: the pdf [?] wasn't necessarily an example, just what we could do back in the 90s
Jeffrey: got it, but it was good to have some example.
Peter: everyone will know where that example came from.
Tess: Could someone explain why the flicker-style grid can't be implemented using masonry?
Jeffrey: it's about hte trailing end for both flexbox and masonry. You stack elements and they end some where
and flicker is not,
Elika thinks we should deal with that with a keyword on the flex property. I largely agree, but this is one of the layouts they should be thinking about.
Martin: how are those layouts achieved?
Jeffrey: they lay them out so it's jagged, and then they scale the whole row so that it's the right width.
Martin. Ah. Wonderful.
[nostalgia for LaTek]
[consensus on the proposed comment]
Jeffrey: I will post to github
Comment by @fantasai Nov 5, 2024 (See Github)
Masonry Syntax Debate Overview
Introduction
The CSSWG has published a consensus FPWD of a masonry layout feature for CSS. See CSS Masonry Layout TAG Review Request for an overview of this specification and the discussions leading up to it. There is fundamental disagreement over the syntax model for this new layout mode, thus the FPWD includes two competing proposals.
The disagreements center around two key concerns: usability for authors, and extensibility into the future. The best way to understand these points would be to read these blog posts advocating for each:
- Chrome Blog: How should we define CSS masonry?
- WebKit Blog: Help us choose the final syntax for Masonry in CSS
- Ahmad Shadeed: Should masonry be part of grid?
- Rachel Andrew: Masonry and good defaults
- Keith J. Grant: Weighing in on CSS masonry [published before the merged FPWD]
We summarize the high-level disagreements below. For examples, please refer to the blog posts.
Usability for Authors
Learnability
-
Chrome argues that a separate display type is easier to learn because a dedicated syntax and mental model can be tailored more closely to the characteristics of the layout, and because segregating layout into separate modules makes them easier to understand. They assert that Grid syntax would be interpreted differently or would otherwise be confusing when re-used for masonry layout.
-
WebKit argues that an integrated display type is easier to learn, because it re-uses exactly an existing syntax and mental model, leaving minimal syntax and concepts to learn, even if there are slight differences in behavior in the two modes—allowing authors to easily switch between them mentally as well as in code.
Defaulting
- Chrome argues that using a separate display type allows for better default behavior, leaving fewer things to configure for common cases.
- WebKit argues that Chrome's proposed default values are not actually usable for most of the common cases; and therefore aren't better defaults. They assert that relying on automatic behavior at the container level just pushes down the need for configuration to the items, which is less understandable/performant/powerful.
Redundancy
- Chrome argues that re-using Grid's 2D properties means nearly every Grid feature has some syntax that is ignored or reinterpreted in Masonry's 1D layout; therefore re-using patterns rather than properties is better.
- WebKit argues that creating a separate display type with its own dedicated properties introduces a lot of slightly divergent duplicated syntax into CSS, where CSS usually re-uses properties across contexts wherever they can reasonably apply, ensuring a consistent and minimal interface to shared concepts.
Extensibility
Masonry layout and Grid layout have some key differences:
- Masonry layout imposes sizing consistency on all items in the same track in one dimension; regular grid layout imposes it in two dimensions.
- Masonry layout requires track sizing before auto-placement can occur (because auto-placement needs to know the sizes of already-placed items to determine where to place the next item), whereas regular grid layout requires placement before track sizing (because track sizes depend on what items were placed into them). We were able to introduce auto-sized tracks into masonry by sizing them with the assumption that all auto-placed item are placed into all tracks.
These differences mean that some layout operations are easier or more reasonable in masonry than in grid and vice versa.
- Chrome argues that by making masonry a separate display type it allows the feature set of masonry and grid layout to diverge, making it easier to introduce a feature in one without entangling it with the other. They cite the example of asking the UA to calculate how many auto-sized columns could fit in a masonry container, which would require heuristics in both but likely have more convoluted behavior in Grid.
- WebKit argues that by integrating masonry and grid, authors are guaranteed a consistent syntax and feature set, and this is worth the extra effort and complication to make a given feature work in both modes. They cite the example of mixing different track size types in a given masonry container, which Chrome had asserted was impossible to do performantly, but which the CSSWG has solved and specced in the FPWD.
Question
The CSSWG is seeking the TAG's input into this question, to help inform the debate.
Comment by @jyasskin Nov 20, 2024 (See Github)
Overall, we think masonry, grid, and wrapping-flexbox should be incorporated into a unified set of properties. Chrome's proposal splits apart property sets too eagerly, but even the WebKit proposal seems to miss a chance to develop more-general properties.
Examining the arguments put forward from either side, we found some compelling and some less so:
- It was argued that a separate set of properties is necessary for sensible defaults. However, there is precedent for using "smart" defaults that are different based on other property values. Perhaps the
masonry
shorthand can be used to set grid-integrated properties. - It was argued that the grid-integrated syntax makes it easier to convert from grid syntax to grid-integrated masonry syntax, however we don't optimize for the transition period unless it's going to derail adoption.
- It was argued that the grid-integrated syntax makes it easier to switch between grid and masonry at a breakpoint or switch between row and column tracks, however we don't expect this to be a common enough use case to be worth optimizing for.
- It was argued that the grid-independent syntax makes things easier if the properties need to diverge in the future. We think that is a drawback of that syntax, not a feature. Even if the WG selects a syntax like the grid-independent one, it should work hard to ensure that the properties diverge as little as possible in the future, even if some masonry properties initially appear not to have an obvious behavior for other display modes. It would be even worse to evolve subtle variations in patterns that otherwise appear to match, for example by forgetting to apply a new grid keyword to the parallel masonry property.
- It was argued that the grid-independent syntax would also push future layout modes towards becoming separate property sets, which would be detrimental for the overall learnability of the language. We do think this has some basis, given the principle of consistency, but there are also enough differences between pillar and masonry to justify different design decisions.
- We appreciated the argument that historically in graphic design grids were actually one-dimensional until relatively recently, although this doesn't prove that such grids fit into
display:grid
. - It was argued that because most masonry use cases are simpler than Grid, developers should be able to learn it without having to first learn Grid. This is an important goal. Can you instead achieve it by simplifying a subset of Grid that works for these types of simple cases? For example, multicol makes it easy to define several equal columns, optionally with constraints about their total number, min/max dimensions, or both. Can you share the track definitions between multicol and masonry? This need also arises fairly often with a 2-d grid: can the WG port this simplicity to Grid layout, and share the required properties across all three layout modes?
We also noticed some larger issues with the space of CSS layout modes:
- CSS currently has 3 layout modes all of which basically generate a 2d arrangement of children, with different rules for which dimensions line up and what order the available layout slots are filled: grid, multicol, and wrapping-flexbox. This is already causing a lot of author confusion, and Masonry attempts to add a 4th mode. As a general principle, having vastly different ways to accomplish slightly different things is a usability antipattern. We urge the WG to explore ways to unify these so that authors can port more knowledge from one to the other (even if they are implemented as separate code paths internally). For example grid-auto-flow, flex-direction, masonry-direction, and masonry-fill all control the same stylistic aspect from an author pov and it seems that they could be more unified to some degree.
- While sometimes inevitable, having properties specify things that get ignored is also an antipattern. It is particularly damaging to DX if from an author perspective it seems that these properties really ought to work together, but they don't. As specified,
grid-auto-flow
in the grid-integrated proposal falls in that category: we should not require authors to specify a flow axis that is then ignored. - There's a wider space of layout patterns, including the Flickr-style grid and layouts derived from magazines and newspapers, which CSS should eventually be able to represent. It's unfortunate to add a whole new layout mode without showing how it contributes toward the rest of the needed layouts. If we think of multicol as being a grid with just one row, many of these patterns, including Masonry and "pillar", seem to involve the ability to instruct the browser to stack the next child into one or more cells with some existing content. These patterns blur the line we've been assuming between 1-d and 2-d layout, and the WG may need to solve the problem by leaning into a continuum between those two options. It would be ideal to find a set of properties that can be used to build all of these layout patterns, instead of potentially overfitting to just masonry layouts.
We recognize that it's important to make incremental progress and that it's impossible to break backward-compatibility with the existing properties. We hope there's a way to imitate the way gap
was backported, but even if there's not, we think the new features' designs would benefit from a sense of what we would have done if we had a time machine.
Comment by @nt1m Nov 21, 2024 (See Github)
It was argued that the grid-integrated syntax makes it easier to convert from grid syntax to grid-integrated masonry syntax, however we don't optimize for the transition period unless it's going to derail adoption.
I disagree this doesn't matter fwiw, I think it's a feature that grid-integrated masonry nicely degrades to a CSS grid. Whereas grid-independent masonry would need to duplicate the set of properties for that degradation to be possible. Graceful degradation doesn't seem mentioned in this TAG review, but I think it is an important point.
Comment by @jyasskin Nov 21, 2024 (See Github)
@nt1m [Trying to channel the rest of the TAG, but I haven't checked this with them, so it could be wrong.] There are two ideas here:
- The Webkit blog that we linked to in that point argues that "it’s an easy transition to go from thinking about CSS Grid to thinking about packed masonry-style layouts". That seems like an argument that you don't have to change the code much when you have a grid layout and want to adopt masonry, or that it's easy for people who already know grid to start using masonry. That doesn't seem like a great argument, since most future code will be written directly into either grid or masonry, and by people who had the option of learning either grid or masonry first.
- The point you're making in this comment, that it's good for code to gracefully degrade in browsers that don't support masonry. All things equal, code absolutely should degrade gracefully. But if other things aren't equal, it's probably better to prioritize some of the other considerations like (for example) learnability and the coherence of the whole space of properties. Graceful degradation would be more important if
@supports
didn't exist, if there were going to be a years-long gap between the different engines shipping this, or if pages written to use this in evergreen browsers are likely to be completely unusable in older browsers, but I didn't find an argument that that's the case for either masonry syntax.
Keep in mind that this review isn't guaranteed to be correct: it's just the TAG's opinion with maybe a wider view but less context and study than the CSSWG.
OpenedOct 14, 2024
こんにちは TAG-さん!
I'm requesting an early TAG design review of masonry layout in CSS.
Masonry layout creates grid-based tracks in a single axis, and stacks items tightly in the other, creating rows or columns but not both. It is currently drafted into https://www.w3.org/TR/css-grid-3/ with two possible syntax options: a grid-based syntax that uses a keyword to relax alignment in the stacking axis, and an independent syntax that uses a blend of flex and grid concepts with a new set of properties. The arguments in the debate center over a) which is easier to learn for authors and b) how might this decision impact possible future developments in one or both models (or CSS in general).
I'm opening this issue to ask the TAG to schedule a review of the spec in general and of the syntax question specifically. We are currently collecting feedback, and are hoping to have a CSSWG discussion on this question in late October / early November. We will update this issue as input comes in.
Further details:
You should also know that...