liveBook · Manning

Flex-basis

As explained in Web Design Playground

A CSS flexbox property that sets the initial main-size of a flex item before free space is distributed.

A flex item needs a starting size before it grows or shrinks to fit its container. `flex-basis` suggests that starting size. Think of it as giving each item a place to start, not necessarily its final size. section 12.6

To choose a basis, follow the container’s direction:

  • In a row, the basis sets a starting width. In a column, it sets a starting height. section 12.6
  • Use a measurement such as `10em`, or a percentage, when you want to suggest a specific size. section 12.6
  • Use `auto` to start from the item’s width or height property. Without one, `auto` uses the content-based size; `content` requests that content-based size directly. section 12.6
item {
    flex-basis: value|auto|content;
}

The rule shows the three choices: a measured value, `auto`, or `content`. Replace `value` with a CSS measurement or percentage. section 12.6

Give a wrapping block room to breathe

In a flexible page layout, `flex-wrap` lets blocks move onto another line when horizontal room runs out. Add a `flex-basis` value to establish a minimum block width, and set `flex-shrink: 0` so the block does not shrink below it. Try changing the viewport width in the flexible-layout Playground (`wdpg.io/13-3-1`) and watch when the blocks wrap. section 13.9

You can also set the basis alongside growth and shrink settings with the `flex` shorthand. For example, `flex: 0 0 10em` gives an item a fixed size of `10em`. Start with `flex-basis` when the question is simply, “How big should this item be before flexbox adjusts it?” section 12.6 section 12.18

How Web Design Playground covers it

How deep it goes
Explains row and column sizing, measurement values, `auto`, `content`, and shorthand syntax without detailing a sizing algorithm.
Examples
Uses a `10em` shorthand declaration and a flexible-layout Playground where blocks wrap as the viewport narrows.
What it assumes
Assumes familiarity with CSS width, height, and measurement units while introducing flex-basis syntax and values directly.
What you can do after
Apply it via CSS flex-basis and flex-shrink to set starting sizes and minimum block widths in a wrapping layout.
How it connects
Connects flex-basis to flex-direction, flex-grow, flex-shrink, the flex shorthand, and flex-wrap in responsive layouts.

Also explained in

Compare how 5 books explain flex-basis →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.