Skip to content
BENIBIX Learn

Flexbox

Development🌐 Web DevelopmentBrowser Code

Also known as CSS Flexbox, Flexible Box Layout, display: flex

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

Think of it like

Think of it like books on a shelf. You can push them left, spread them out or stand them in the middle.

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.

Definition

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 code

css
.menu {
  display: flex;
  justify-content: space-between;
}
The links in the menu spread out across one row.
Flexbox, on the left, lines items up along one row.

Common mistake

Using flexbox for a full page of rows and columns. That is a job for grid.

Key takeaways

  1. 1
    One direction. A row or a column, not both.
  2. 2
    Share the space. Items can grow, shrink or spread out.
  3. 3
    Set on the parent. display: flex goes on the box around them.

Compare

Learn it properly