Is CSS Grid better than Flexbox?

css flexbox vs css grid

In this post you’ll learn what is the difference between CSS Grid and Flexbox, and when you should use each of them. CSS Flexbox has been around for a couple of years now, and is becoming more and more popular amongst front-end developers. There is also CSS Grid which is newer and has almost the same capabilities but some of them are better and some of them are worse than Flexbox.

What are the differences?

  1. The main difference between CSS Grid and Flexbox is that Flexbox is made for one dimensional layouts and Grid is made for two dimensional layouts. Let’s say you have a div with 2 links and want to display them in-line. For this you should use Flexbox because you will have more flexibility and it requires less code which will be easier to maintain. If you’re looking to create a layout that contains rows and columns, you should use CSS Grid.
  2. CSS Grid requires less media queries to build a responsive layout because it has functionalities like grid-gap, auto-placement, repeat(), minmax() and auto-fill.
  3. There doesn’t seem to be a way to force the auto-placement functionality from Grid to leave some columns or rows empty
  4. The new fr unit makes the use of CSS Grid even easier, taking care of most of the responsive work by taking up a fraction of the space available in the container.
  5. When it comes to browser support, Flexbox is far ahead of CSS Grid.
  6. Animation support for Flexbox is much better than for CSS Grid

Still not sure what to choose?

In my opinion, Grid was designed to be used with Flexbox and both of them should be used together.

Andy

Front-end Engineer & Designer based in Dublin currently working @IBM.
I write about: Javascript, HTML, CSS, React JS, React Native and UI/UX Design.

Add comment