Of course, you can set the widths and heights of flex items or make use of the calc() function but then you lose flexbox’s main appeal: flexibility. With flexbox, it’s hard to predict behavior at certain viewports and you can get surprising results. Authors can then precisely position and size the building block elements of their application into the grid areas defined by the intersections of these columns and rows.” The W3 docs of the Grid module assert: “It provides a mechanism for authors to divide available space for layout into columns and rows using a set of predictable sizing behaviors. If you want to accurately control the position of items within a layout, CSS Grid is the way to go. Each item is a grid cell, lined up along both a horizontal and a vertical axis. Focus on Content Placement: CSS GridĬSS Grid focuses on precise content placement. You need to assess each layout individually on a case by case basis to pick the better option. All the authors mentioned above warn against this approach, as it can seriously limit possibilities. The most common misconception about the two layout modules is that Grid is for full-page layouts and flexbox is for smaller components. And, there are other popular tools such as Flexbox Grid that do the same. All Bootstrap 4 sites out there makes use of flexbox to accomplish two-dimensional layouts, consisting of rows and columns. The best example is Bootstrap 4’s grid system which is based on flexbox. In fact, we can create two-dimensional layouts with flexbox (due to its wrapping ability) and one-dimensional layouts with CSS Grid (due to its auto-placement ability), too.Īlthough flexbox is originally not for building grids, it’s frequently used that way. It is a strong distinction though that 2D layout is possible with grid though in ways it is not in flexbox.”Īnd, this is how CSS works in real life. I wouldn't want someone to think they have to use flexbox and not grid because grid is only when you need 2D. flexbox, only because I find most of my day-to-day usage of grid is "1D" and it's great for that. For instance, Chris Coyier made the following statement in his aforementioned article: “I'm not the world's biggest fan of the "1D" vs. This is how W3C wants us to use flexbox and Grid, however practice frequently overrides theory and not everyone is fan of the one-dimensional vs. Grid allows you to create two-dimensional layouts where you can precisely place grid items into cells defined by rows and columns.
On the other hand, CSS Grid lets you work along two axes: horizontally and vertically. The flexbox cross axis is always perpendicular to the main axis.Ī flex layout can also wrap in multiple rows or columns and flexbox treats each row or column as a separate entity, based on its content and the available space.
Flexbox lays out items along either the horizontal or the vertical axis, so you have to decide whether you want a row-based or a column-based layout.
The most important thing to know is that flexbox is one-dimensional, while CSS Grid is two-dimensional. As the topic is likely to stay relevant in the future, I’d recommend reading some of the articles above and developing your own stance on the question, as nothing is set in stone yet. You can also find many other related blog posts, articles, videos, and discussions all over the web. The MDN Community has created some thorough docs on the basic differences between Grid and flexbox, which is currently the best available documentation on the subject.Michelle Barker also responded to Chris’ Twitter thread by authoring another excellent Grid vs flexbox article in her popular CSS blog.