Flex

Utilities for controlling how flex items both grow and shrink.

@include('_partials.class-table', [ 'rows' => [ [ '.flex-initial', 'flex: 0 1 auto;', "Allow a flex item to shrink but not grow, taking into account its initial size.", ], [ '.flex-1', 'flex: 1 1 0%;', "Allow a flex item to grow and shrink as needed, ignoring its initial size.", ], [ '.flex-auto', 'flex: 1 1 auto;', "Allow a flex item to grow and shrink, taking into account its initial size.", ], [ '.flex-none', 'flex: none;', "Prevent a flex item from growing or shrinking.", ], ] ])

Initial

Use .flex-initial to allow a flex item to shrink but not grow, taking into account its initial size:

@component('_partials.code-sample')

Items don't grow when there's extra space

Short
Medium length

Items shrink if possible when needed

Short
Medium length
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem

@slot('code')

Short
Medium length
Short
Medium length
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem
@endslot @endcomponent

Flex 1

Use .flex-1 to allow a flex item to grow and shrink as needed, ignoring its initial size:

@component('_partials.code-sample')

Default behavior

Short
Medium length
Significantly larger amount of content

With .flex-1

Short
Medium length
Significantly larger amount of content

@slot('code')

Short
Medium length
Significantly larger amount of content
@endslot @endcomponent

Auto

Use .flex-auto to allow a flex item to grow and shrink, taking into account its initial size:

@component('_partials.code-sample')

Default behavior

Short
Medium length
Significantly larger amount of content

With .flex-auto

Short
Medium length
Significantly larger amount of content

@slot('code')

Short
Medium length
Significantly larger amount of content
@endslot @endcomponent

None

Use .flex-none to prevent a flex item from growing or shrinking:

@component('_partials.code-sample')

Item that can grow or shrink if needed
Item that cannot grow or shrink
Item that can grow or shrink if needed
@endcomponent

Responsive

To control how a flex item both grows and shrinks at a specific breakpoint, add a {screen}: prefix to any existing utility class. For example, use md:flex-1 to apply the flex-1 utility at only medium screen sizes and above.

For more information about Tailwind's responsive design features, check out the Responsive Design documentation.

@component('_partials.responsive-code-sample') @slot('none')

Item that can grow or shrink if needed
Responsive flex item
Item that can grow or shrink if needed
@endslot @slot('sm')
Item that can grow or shrink if needed
Responsive flex item
Item that can grow or shrink if needed
@endslot @slot('md')
Item that can grow or shrink if needed
Responsive flex item
Item that can grow or shrink if needed
@endslot @slot('lg')
Item that can grow or shrink if needed
Responsive flex item
Item that can grow or shrink if needed
@endslot @slot('xl')
Item that can grow or shrink if needed
Responsive flex item
Item that can grow or shrink if needed
@endslot @slot('code')
Responsive flex item
@endslot @endcomponent

Customizing

Flex Values

By default Tailwind provides four flex utilities. You change, add, or remove these by editing the theme.flex section of your Tailwind config.

@component('_partials.customized-config', ['key' => 'theme.flex']) '1': '1 1 0%', auto: '1 1 auto',

  • initial: '0 1 auto',
  • inherit: 'inherit', none: 'none',
  • '2': '2 2 0%', @endcomponent

@include('_partials.variants-and-disabling', [ 'utility' => [ 'name' => 'flex', 'property' => 'flex', ], 'variants' => [ 'responsive', ], ])

Tailwind UI is now in early access!