Currently Empty: ₹0.00
CSS Flex Basis
CSS CODES & EXAMPLES
CSS Flex Basis
Learn how the flex-basis property defines the
initial main size of a flex item before available space is
distributed.
01
What is Flex Basis?
Define the initial size of a flex item
The CSS flex-basis property specifies the initial
main size of a flex item before the remaining space is
distributed using Flexbox.
Remember:
flex-basis controls the starting size of a flex
item along the main axis.
02
Basic Syntax
Set the initial main size
flex-basis.css
.item {
flex-basis: 200px;
}
The value can be a length, percentage, auto,
0, or other valid sizing values.
03
flex-basis: 200px
Fixed initial basis
When the flex direction is row, a length value
such as 200px defines the initial width of the
flex item.
basis-px.css
.container {
display: flex;
}
.item {
flex-basis: 200px;
}200px Basis
200px Basis
200px Basis
04
flex-basis: 50%
Use percentage valuesA percentage value defines the flex basis relative to the flex container’s inner main size.
basis-percent.css
.item {
flex-basis: 50%;
}50%
50%
05
flex-basis: auto
Use the item’s main-size property
With flex-basis: auto, Flexbox considers the
item’s definite main size, such as width in a
row layout, when determining its base size.
basis-auto.css
.item {
width: 250px;
flex-basis: auto;
}
Important:
auto allows the item’s main-size property to
contribute to its flex base size.
06
flex-basis: 0
Start from zero main size
Setting flex-basis: 0 tells Flexbox to start the
flex sizing calculation from a zero basis, subject to the
other sizing constraints.
basis-zero.css
.item {
flex-grow: 1;
flex-basis: 0;
}Flex 1
Flex 1
Flex 1
07
Flex Basis vs Width
Understand the difference| Property | Purpose | Flexbox Role |
|---|---|---|
width | Sets width | Normal sizing property |
flex-basis | Sets initial main size | Used directly by Flexbox |
flex-basis: auto | Uses main-size information | Considers width/height where appropriate |
08
Flex Basis with Flex Grow
Starting size plus available space
flex-basis defines the starting point while
flex-grow controls how an item receives positive
free space.
grow-basis.css
.item {
flex-grow: 1;
flex-basis: 200px;
}Grow 1
Basis 200px
Basis 200px
Grow 1
Basis 200px
Basis 200px
09
Flex Basis with Flex Shrink
Starting size plus negative free space
When the container does not have enough space,
flex-shrink can reduce items from their flex
base size.
shrink-basis.css
.item {
flex-shrink: 1;
flex-basis: 300px;
}Basis 300px
Shrink 1
Shrink 1
Basis 300px
Shrink 1
Shrink 1
10
Flex Shorthand
Grow, shrink and basis together
The flex shorthand combines
flex-grow, flex-shrink, and
flex-basis.
flex-shorthand.css
.item {
flex: 1 1 250px;
}Meaning:
1 = grow,
1 = shrink,
250px = basis.
11
Responsive Course Cards
Practical education website exampleCSS Flexbox
Learn modern Flexbox layouts, alignment and responsive design techniques.
Web Designing
Build professional responsive websites using HTML and CSS.
12
Important Points
Quick revision
✓
flex-basis defines the initial main size of
a flex item.
✓
In a row layout, the main axis is normally horizontal.
✓
In a column layout, the main axis is normally vertical.
✓
flex-basis works together with
flex-grow and flex-shrink.
✓
flex-basis: auto can use the item’s main-size
information.
✓
The shorthand flex can define all three
values together.
13
Practice Task
Test your Flexbox knowledge🎯 Build Three Equal Cards
Create three cards using Flexbox and make them share the available space equally.
-
Set the parent to
display: flex; -
Give each card
flex-basis: 0; -
Give each card
flex-grow: 1; -
Add a suitable
gap. - Make the layout responsive on mobile screens.
14
CSS Flex Basis Live Runner
Run the practical exampleLIVE PREVIEW



