zfb
GitHub repository

Type to search...

to open search from anywhere

Flex item

Set flex growth, shrinkage, and the shorthand sizing behavior of an item.

Set a flex item's sizing behavior when the container has extra or insufficient room. The flex presets choose combinations of basis, growth and shrink; grow and shrink set those factors independently.

Quick reference

Example classExpected declarations
flex-1flex: 1 1 0%;
flex-autoflex: 1 1 auto;
flex-initialflex: 0 1 auto;
flex-noneflex: none;
growflex-grow: 1;
grow-0flex-grow: 0;
grow-[2]flex-grow: 2;
shrinkflex-shrink: 1;
shrink-0flex-shrink: 0;
shrink-[2]flex-shrink: 2;
basis-autoflex-basis: auto;
basis-1/2flex-basis: calc(100% * 1 / 2);
order-firstorder: -9999;
order-lastorder: 9999;
Example setup

Every preview explicitly starts from spec 1, reset "none", strict mode, spacingUnit "0.25rem", and no breakpoints. Numeric spacing values multiply that unit; no Tailwind theme is inherited. wind-demo classes are authored presentation scaffolding, with their CSS shown beside the exact HTML source.

Examples in use

Compare flex presets

The four presets share the available row differently because their flex-basis, flex-grow, and flex-shrink values differ.

Compare flex presets
HTML
<div class="wind-demo">
  <div class="wind-demo-note">Compare how each item uses its base size and available space.</div>
  <div class="wind-demo-frame flex w-72 gap-2">
    <div class="wind-demo-tile flex-1 w-16">flex-1</div>
    <div class="wind-demo-tile flex-auto w-16">flex-auto</div>
    <div class="wind-demo-tile flex-initial w-16">flex-initial</div>
    <div class="wind-demo-tile flex-none w-16">flex-none</div>
  </div>
</div>
CSS
@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
  :root {
    --zw-spacing-unit: .25rem;
  }
}
.wind-demo {
  font: 14px / 1.45 system-ui, sans-serif;
  color: #203046;
}

.wind-demo-frame {
  border: 1px solid #9aaabd;
  background: #f8fafc;
  padding: .75rem;
}

.wind-demo-note {
  color: #53677f;
  font-size: .875rem;
}

.wind-demo-tile {
  border: 1px solid #849bb3;
  background: #dce8f2;
  color: #203046;
  padding: .5rem;
  text-align: center;
}
.flex {
  display: flex;
}
.flex-1 {
  flex: 1 1 0%;
}
.flex-auto {
  flex: 1 1 auto;
}
.flex-initial {
  flex: 0 1 auto;
}
.flex-none {
  flex: none;
}
.w-16 {
  width: 4rem;
}
.w-72 {
  width: 18rem;
}
.gap-2 {
  column-gap: 0.5rem;
  row-gap: 0.5rem;
}
Configuration for this example
{
  "wind": {
    "spec": 1,
    "reset": "none",
    "strict": true,
    "tokens": {
      "spacingUnit": "0.25rem"
    },
    "breakpoints": {},
    "defaultTransitionTimingFunction": "ease",
    "authoredClasses": {
      "wind-demo": true,
      "wind-demo-frame": true,
      "wind-demo-note": true,
      "wind-demo-tile": true
    },
    "safelist": {
      "docs-preview": [
        "flex",
        "flex-1",
        "flex-auto",
        "flex-initial",
        "flex-none",
        "gap-2",
        "w-16",
        "w-72"
      ]
    }
  }
}
Authored demonstration CSS
.wind-demo { font: 14px/1.45 system-ui, sans-serif; color: #203046; }
.wind-demo-frame { border: 1px solid #9aaabd; background: #f8fafc; padding: 0.75rem; }
.wind-demo-note { color: #53677f; font-size: 0.875rem; }
.wind-demo-tile { border: 1px solid #849bb3; background: #dce8f2; color: #203046; padding: 0.5rem; text-align: center; }

Distribute extra space

grow expands an item at factor 1, grow-0 keeps the fixed item from expanding, and grow-[2] gets twice the free-space share of grow.

Distribute extra space
HTML
<div class="wind-demo">
  <p class="wind-demo-note">Extra space is split according to grow factors.</p>
  <div class="wind-demo-frame flex w-72 gap-2">
    <div class="wind-demo-tile grow">grow 1</div>
    <div class="wind-demo-tile grow-0 w-16">grow-0</div>
    <div class="wind-demo-tile grow-[2]">grow-[2]</div>
  </div>
</div>
CSS
@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
  :root {
    --zw-spacing-unit: .25rem;
  }
}
.wind-demo {
  font: 14px / 1.45 system-ui, sans-serif;
  color: #203046;
}

.wind-demo-frame {
  border: 1px solid #9aaabd;
  background: #f8fafc;
  padding: .75rem;
}

.wind-demo-note {
  color: #53677f;
  font-size: .875rem;
}

.wind-demo-tile {
  border: 1px solid #849bb3;
  background: #dce8f2;
  color: #203046;
  padding: .5rem;
  text-align: center;
}
.flex {
  display: flex;
}
.grow {
  flex-grow: 1;
}
.grow-0 {
  flex-grow: 0;
}
.grow-\[2\] {
  flex-grow: 2;
}
.w-16 {
  width: 4rem;
}
.w-72 {
  width: 18rem;
}
.gap-2 {
  column-gap: 0.5rem;
  row-gap: 0.5rem;
}
Configuration for this example
{
  "wind": {
    "spec": 1,
    "reset": "none",
    "strict": true,
    "tokens": {
      "spacingUnit": "0.25rem"
    },
    "breakpoints": {},
    "defaultTransitionTimingFunction": "ease",
    "authoredClasses": {
      "wind-demo": true,
      "wind-demo-frame": true,
      "wind-demo-note": true,
      "wind-demo-tile": true
    },
    "safelist": {
      "docs-preview": [
        "flex",
        "gap-2",
        "grow",
        "grow-0",
        "grow-[2]",
        "w-16",
        "w-72"
      ]
    }
  }
}
Authored demonstration CSS
.wind-demo { font: 14px/1.45 system-ui, sans-serif; color: #203046; }
.wind-demo-frame { border: 1px solid #9aaabd; background: #f8fafc; padding: 0.75rem; }
.wind-demo-note { color: #53677f; font-size: 0.875rem; }
.wind-demo-tile { border: 1px solid #849bb3; background: #dce8f2; color: #203046; padding: 0.5rem; text-align: center; }

Control compression

shrink items can compress below their starting widths; shrink-0 preserves its width. A factor of 2 gives the final item a larger share of the shrink.

Control compression
HTML
<div class="wind-demo">
  <p class="wind-demo-note">These starting widths are wider than the row.</p>
  <div class="wind-demo-frame flex w-64 gap-2">
    <div class="wind-demo-tile shrink w-48">shrink</div>
    <div class="wind-demo-tile shrink-0 w-48 wind-demo-alt">shrink-0 keeps its width</div>
    <div class="wind-demo-tile shrink-[2] w-48">shrink-[2]</div>
  </div>
</div>
CSS
@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
  :root {
    --zw-spacing-unit: .25rem;
  }
}
.wind-demo {
  font: 14px / 1.45 system-ui, sans-serif;
  color: #203046;
}

.wind-demo-alt {
  border-color: #b39761;
  background: #efe5cb;
  color: #483a1d;
}

.wind-demo-frame {
  border: 1px solid #9aaabd;
  background: #f8fafc;
  padding: .75rem;
}

.wind-demo-note {
  color: #53677f;
  font-size: .875rem;
}

.wind-demo-tile {
  border: 1px solid #849bb3;
  background: #dce8f2;
  color: #203046;
  padding: .5rem;
  text-align: center;
}
.flex {
  display: flex;
}
.shrink {
  flex-shrink: 1;
}
.shrink-0 {
  flex-shrink: 0;
}
.shrink-\[2\] {
  flex-shrink: 2;
}
.w-48 {
  width: 12rem;
}
.w-64 {
  width: 16rem;
}
.gap-2 {
  column-gap: 0.5rem;
  row-gap: 0.5rem;
}
Configuration for this example
{
  "wind": {
    "spec": 1,
    "reset": "none",
    "strict": true,
    "tokens": {
      "spacingUnit": "0.25rem"
    },
    "breakpoints": {},
    "defaultTransitionTimingFunction": "ease",
    "authoredClasses": {
      "wind-demo": true,
      "wind-demo-alt": true,
      "wind-demo-frame": true,
      "wind-demo-note": true,
      "wind-demo-tile": true
    },
    "safelist": {
      "docs-preview": [
        "flex",
        "gap-2",
        "shrink",
        "shrink-0",
        "shrink-[2]",
        "w-48",
        "w-64"
      ]
    }
  }
}
Authored demonstration CSS
.wind-demo { font: 14px/1.45 system-ui, sans-serif; color: #203046; }
.wind-demo-alt { border-color: #b39761; background: #efe5cb; color: #483a1d; }
.wind-demo-frame { border: 1px solid #9aaabd; background: #f8fafc; padding: 0.75rem; }
.wind-demo-note { color: #53677f; font-size: 0.875rem; }
.wind-demo-tile { border: 1px solid #849bb3; background: #dce8f2; color: #203046; padding: 0.5rem; text-align: center; }

Basis and order

basis-and-order uses exact supported Wind utility classes.

Basis and order
HTML
<div class="wind-demo-new flex"><span class="basis-auto order-first">first</span><span class="basis-1/2 order-last">last</span></div>
CSS
@layer zw-reset, zw-tokens, zfb-hi, base, components;
@layer zw-tokens {
  :root {
    --zw-spacing-unit: .25rem;
  }
}
.wind-demo-new {
  color: #203046;
  font: 14px / 1.5 system-ui, sans-serif;
}
.flex {
  display: flex;
}
.basis-1\/2 {
  flex-basis: calc(100% * 1 / 2);
}
.basis-auto {
  flex-basis: auto;
}
.order-first {
  order: -9999;
}
.order-last {
  order: 9999;
}
Configuration for this example
{
  "wind": {
    "spec": 1,
    "reset": "none",
    "strict": true,
    "tokens": {
      "spacingUnit": "0.25rem"
    },
    "breakpoints": {},
    "defaultTransitionTimingFunction": "ease",
    "authoredClasses": {
      "wind-demo-new": true
    },
    "safelist": {
      "docs-preview": [
        "flex",
        "basis-auto",
        "basis-1/2",
        "order-first",
        "order-last"
      ]
    }
  }
}
Authored demonstration CSS
.wind-demo-new { color: #203046; font: 14px/1.5 system-ui, sans-serif; }

Custom and named values

flex-1 is 1 1 0%, flex-auto is 1 1 auto, flex-initial is 0 1 auto, and flex-none is none. grow and shrink default to 1; the -0 forms use zero, and arbitrary numeric values such as grow-[2] are supported. Give the container display:flex to see the factors take effect.

Related guides: Utility grammar · Variants

Catalog details

flex-1

FieldValue
Catalog identifierv1.flex-1
Class patternflex-1
Grammar{"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false}
Accepted values1
Token categoriesNo token category
Negative-value policyforbidden
Conflict group and rankflex-item (5)
Order rank0
Selector shapeownElement
Spec version1
Emitter propertiesflex

Accepted values

KindSuffixEmitted value
exactnull"1 1 0%"

Declaration templates

PropertyValue kindFixed value
flexresolvednull

Catalog examples

Example classExpected declarations
flex-1flex: 1 1 0%

flex-auto

FieldValue
Catalog identifierv1.flex-auto
Class patternflex-auto
Grammar{"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false}
Accepted values1
Token categoriesNo token category
Negative-value policyforbidden
Conflict group and rankflex-item (5)
Order rank0
Selector shapeownElement
Spec version1
Emitter propertiesflex

Accepted values

KindSuffixEmitted value
exactnull"1 1 auto"

Declaration templates

PropertyValue kindFixed value
flexresolvednull

Catalog examples

Example classExpected declarations
flex-autoflex: 1 1 auto

flex-initial

FieldValue
Catalog identifierv1.flex-initial
Class patternflex-initial
Grammar{"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false}
Accepted values1
Token categoriesNo token category
Negative-value policyforbidden
Conflict group and rankflex-item (5)
Order rank0
Selector shapeownElement
Spec version1
Emitter propertiesflex

Accepted values

KindSuffixEmitted value
exactnull"0 1 auto"

Declaration templates

PropertyValue kindFixed value
flexresolvednull

Catalog examples

Example classExpected declarations
flex-initialflex: 0 1 auto

flex-none

FieldValue
Catalog identifierv1.flex-none
Class patternflex-none
Grammar{"acceptedKinds":["exact"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false}
Accepted values1
Token categoriesNo token category
Negative-value policyforbidden
Conflict group and rankflex-item (5)
Order rank0
Selector shapeownElement
Spec version1
Emitter propertiesflex

Accepted values

KindSuffixEmitted value
exactnull"none"

Declaration templates

PropertyValue kindFixed value
flexresolvednull

Catalog examples

Example classExpected declarations
flex-noneflex: none

grow

FieldValue
Catalog identifierv1.grow
Class patterngrow or grow-<suffix>
Grammar{"acceptedKinds":["keyword","arbitrary"],"arbitraryProperty":"flex-grow","allowsFractionSlash":false,"allowsColorOpacity":false}
Accepted values2
Token categoriesNo token category
Negative-value policyforbidden
Conflict group and rankflex-item (5)
Order rank0
Selector shapeownElement
Spec version1
Emitter propertiesflex-grow

Accepted values

KindSuffixEmitted value
keywordnull"1"
keyword"0""0"

Declaration templates

PropertyValue kindFixed value
flex-growresolvednull

Catalog examples

Example classExpected declarations
growflex-grow: 1

shrink

FieldValue
Catalog identifierv1.shrink
Class patternshrink or shrink-<suffix>
Grammar{"acceptedKinds":["keyword","arbitrary"],"arbitraryProperty":"flex-shrink","allowsFractionSlash":false,"allowsColorOpacity":false}
Accepted values2
Token categoriesNo token category
Negative-value policyforbidden
Conflict group and rankflex-item (5)
Order rank0
Selector shapeownElement
Spec version1
Emitter propertiesflex-shrink

Accepted values

KindSuffixEmitted value
keywordnull"1"
keyword"0""0"

Declaration templates

PropertyValue kindFixed value
flex-shrinkresolvednull

Catalog examples

Example classExpected declarations
shrinkflex-shrink: 1

basis

FieldValue
Catalog identifierv1.basis
Class patternbasis-<suffix>
Grammar{"acceptedKinds":["keyword","fraction"],"arbitraryProperty":null,"allowsFractionSlash":true,"allowsColorOpacity":false}
Accepted values8
Token categoriesNo token category
Negative-value policyforbidden
Conflict group and rankflex-item (5)
Order rank1
Selector shapeownElement
Spec version1
Emitter propertiesflex-basis

Accepted values

KindSuffixEmitted value
keyword"auto""auto"
keyword"full""100%"
keyword"px""1px"
keyword"0""0"
keyword"min""min-content"
keyword"max""max-content"
keyword"fit""fit-content"
keyword"content""content"

Declaration templates

PropertyValue kindFixed value
flex-basisresolvednull

Catalog examples

Example classExpected declarations
basis-autoflex-basis: auto

order

FieldValue
Catalog identifierv1.order
Class patternorder-<suffix>
Grammar{"acceptedKinds":["keyword","integer"],"arbitraryProperty":null,"allowsFractionSlash":false,"allowsColorOpacity":false}
Accepted values3
Token categoriesNo token category
Negative-value policyallowed
Conflict group and rankflex-item (5)
Order rank2
Selector shapeownElement
Spec version1
Emitter propertiesorder

Accepted values

KindSuffixEmitted value
keyword"first""-9999"
keyword"last""9999"
keyword"none""0"

Declaration templates

PropertyValue kindFixed value
orderresolvednull

Catalog examples

Example classExpected declarations
order-firstorder: -9999

Revision History

CreatedUpdated