Skip to content
BENIBIX Learn

Flexbox vs CSS Grid

People think flexbox and grid do the same job, and they do not. Flexbox lines things up in one row or one column. Grid puts things in rows and columns at once. Most pages use both: grid for the page, flexbox for the menu inside it.

Development🌐 Web Development

Flexbox

A CSS layout that puts things in one row or column and shares the space.

Flexbox is a CSS layout that puts items in a row or a column. You turn it on with display: flex on the parent box. Then you choose how the items share the space. They can bunch at one end, spread evenly or sit in the middle. Items can grow or shrink to fit. It works along one direction at a time.

Example
Lucy's menu has five links. With display: flex and gap: 1rem, they sit in a neat row with even gaps.
Why it matters
Menus, toolbars and cards are lined up this way on most sites. It also makes centring a box simple.
Full entry
Development🌐 Web Development

CSS Grid

A CSS layout that puts things in rows and columns at the same time.

CSS Grid is a layout that places items in rows and columns at once. You turn it on with display: grid and say how many columns you want. Each item then drops into the next cell. One item can span more than one cell, like a wide header. It works in two directions, which suits whole page layouts and galleries.

Example
Jack shows twelve photos with grid-template-columns: repeat(3, 1fr). They fall into four neat rows of three.
Why it matters
Whole page layouts used to need tricks. Grid does them in a few lines.
Full entry

In one line

Flexbox
A CSS layout that puts things in one row or column and shares the space.
CSS Grid
A CSS layout that puts things in rows and columns at the same time.