Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Flex Shorthand

CSS Flex Shorthand

CSS CODES & EXAMPLES

CSS Flex Shorthand

Learn how the flex shorthand combines flex-grow, flex-shrink, and flex-basis into one powerful CSS declaration.

01

What is Flex Shorthand?

Combine three Flexbox properties

The CSS flex property is a shorthand for flex-grow, flex-shrink, and flex-basis.

Remember: The common three-value pattern is: flex: grow shrink basis;
02

Basic Syntax

Three values in one declaration
flex-shorthand.css
.item {
  flex: 1 1 200px;
}

The three values represent: grow, shrink, and basis.

03

Three-Value Syntax

flex-grow + flex-shrink + flex-basis
three-values.css
.item {
  flex: 1 1 250px;
}
1 flex-grow Can receive extra space
1 flex-shrink Can shrink when needed
250px flex-basis Initial main size
04

flex: 1

Common responsive pattern

The value flex: 1 is a very common way to make flex items share available space. It is especially useful for equal-width cards and columns.

flex-one.css
.item {
  flex: 1;
}
Flex 1
Flex 1
Flex 1
05

flex: 0 1 auto

Useful explicit default-style pattern

This three-value form explicitly sets grow to 0, shrink to 1, and basis to auto.

flex-auto.css
.item {
  flex: 0 1 auto;
}
Meaning: Do not grow automatically, allow shrinking, and use the item’s main-size information as the basis.
06

flex: 0 0 200px

Fixed-size flex item

With grow and shrink both set to 0, the item does not participate in flexible growth or shrinking.

fixed-flex.css
.item {
  flex: 0 0 200px;
}
Fixed 200px
Flexible Item
08

Two-Value Syntax

Grow and shrink values

The flex shorthand also supports shorter forms. When two unitless numbers are supplied, they represent grow and shrink.

two-values.css
.item {
  flex: 2 1;
}
Example: flex: 2 1; means grow factor 2 and shrink factor 1, with the basis using the shorthand’s omitted-value rules.
09

One-Value Syntax

Quick Flexbox patterns
flex: 1;

Flexible item that shares available space.

flex: 2;

Gets a larger grow factor than flex: 1.

flex: 0;

Does not grow and uses a zero flex basis.

flex: auto;

Commonly maps to 1 1 auto.

flex: none;

Commonly maps to 0 0 auto.

10

Flex Shorthand vs Separate Properties

Same concept, shorter code
separate-properties.css
.item {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 250px;
}

Can be written as:

shorthand.css
.item {
  flex: 1 1 250px;
}
11

Responsive Course Cards

Practical website example
CSS

CSS Flexbox

Learn Flexbox properties, alignment, sizing and responsive layouts.

View
HTML

HTML Basics

Learn the structure of modern web pages using semantic HTML.

View
WEB

Web Designing

Build clean and responsive websites using HTML and CSS.

View
13

Practice Task

Build a responsive three-column layout

🎯 Your Challenge

Create three responsive cards using the Flex shorthand.

  • Set the parent to display: flex;
  • Add gap: 20px;
  • Give every card flex: 1 1 250px;
  • Add a mobile media query.
  • Change the card basis and observe the result.
14

CSS Flex Shorthand Live Runner

Run and experiment with the example
LIVE PREVIEW
`;document.getElementById( "sncecFSHPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecFSHRun();} );

HTML Paragraph

  • 17/08/2026

HTML Basic

  • 16/08/2026

Leave a Reply

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