Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Flex Basis

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 values

A 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.
07

Flex Basis vs Width

Understand the difference
PropertyPurposeFlexbox Role
widthSets widthNormal sizing property
flex-basisSets initial main sizeUsed directly by Flexbox
flex-basis: autoUses main-size informationConsiders 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
Grow 1
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
Basis 300px
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 example
CSS

CSS Flexbox

Learn modern Flexbox layouts, alignment and responsive design techniques.

WEB

Web Designing

Build professional responsive websites using HTML and CSS.

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 example
LIVE PREVIEW
`;document.getElementById( "sncecFBPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecFBRun();} );

HTML Lists

  • 17/08/2026

CSS Colors

  • 17/08/2026

Leave a Reply

Your email address will not be published. Required fields are marked *