🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Flex Basis

Control the initial size of flex items. Understand how basis interacts with direction, growing, and shrinking.

style.css
.item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 200px;
}
/* Initial size: 200px */
📐
style.css
1 / 8
📐

Tutor:Welcome. Flex-basis sets the initial main size of a flex item. It acts like a starting point before growing or shrinking.


Flex Mastery

Unlock nodes by learning layout and sizing.

Concept 1: Flex Containers

Before talking about basis, we need a flex container. display: flex establishes a new formatting context where children become flex items.

System Check

What happens to the direct children of a container with display: flex?


Community Layouts

Share Flex Patterns

Built a complex grid with flex-basis? Share your solution.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Flex Basis

Author

Pascual Vila

Frontend Instructor.

The flex-basis property defines the initial size of a flex item before the remaining space is distributed. It acts as the starting point for the flex sizing algorithm.

The "Hypothetical" Size

Think of flex-basis as the "ideal" size of the element. If there is enough space in the container, the item will be this size. If not, it might shrink. If there is extra space, it might grow from this size.

Basis vs Width

When flex-direction is row, flex-basis controls the width. When flex-direction is column, it controls the height.

  • auto: (Default) Looks at the item's width/height property. If those are auto, it looks at content size.
  • content: Sizes based on the content inside.
  • Length units (px, %, etc.): Sets a hard value, ignoring content size.

The Flex Shorthand

It is recommended to use the flex shorthand: flex: grow shrink basis.

For example, flex: 1 1 0 sets the basis to 0, forcing all items to start from nothing and share space equally regardless of their content. flex: 1 1 auto lets them start at their natural size, meaning larger content gets more space.

Best Practices

Use flex-basis: 0 (or flex: 1) for equal-width columns. Use flex-basis: auto when the content size matters. Avoid mixing width and flex-basis on the same element to prevent confusion.

Flex Terminology

flex-basis
The initial size of a flex item along the main axis before any growing or shrinking occurs.
Main Axis
The primary direction of the flex container (row or column). Flex-basis always applies to this axis.
flex-grow
Determines how much of the remaining space (space left after basis) the item should take up.
flex-shrink
Determines how much the item should shrink if there isn't enough space for the flex-basis.