# Flexbox

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

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** CSS Flexbox, Flexible Box Layout, display: flex

## 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.

## 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

Lucy's menu has five links. With display: flex and gap: 1rem, they sit in a neat row with even gaps.

## Example code

```css
.menu {
  display: flex;
  justify-content: space-between;
}
```

The links in the menu spread out across one row.

## Why it matters

Menus, toolbars and cards are lined up this way on most sites. It also makes centring a box simple.

## Common mistake

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

## Three principles

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

## Related terms

- [CSS Grid](https://learn.benibix.com/term/development/css-grid)
- [Cascading Style Sheets (CSS)](https://learn.benibix.com/term/development/css)
- [CSS Box Model](https://learn.benibix.com/term/development/css-box-model)
- [Media Query](https://learn.benibix.com/term/development/media-query)
- [Fluid Layout](https://learn.benibix.com/term/design/fluid-layout)

## Told apart from

- [Flexbox vs CSS Grid](https://learn.benibix.com/compare/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.

## Taught in

- [Flexbox, Grid and Position](https://learn.benibix.com/learn/development-web/flexbox-grid-and-position): HTML, CSS and JS, 9/14

![Two halves. On the left, flexbox: three boxes of different widths sit side by side in one row, with an arrow along the row, and the line display: flex. On the right, grid: five boxes sit in two rows and three columns, the first box spanning two columns, with the line display: grid.](https://learn.benibix.com/diagrams/dev-css-layout.svg)

---

Source: https://learn.benibix.com/term/development/flexbox
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
