Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

flex-shrink

How much a flex item shrinks when there is not enough space.

Syntax

flex-shrink: number;

Values

ParameterTypeDescription
1numberShrinks along with the others (the default).
0numberDoes not shrink — keeps its size.

Examples

An image that keeps its width next to text:

<style>
  .row { display: flex; gap: 8px; width: 260px; border: 1px dashed gray; }
  .row img { width: 80px; }
</style>
 
<div class="row">
  <img src="/media/photo-200x200.jpg" alt="" style="flex-shrink: 0;">
  <p>A long text next to the image does not squeeze it, because the image has flex-shrink: 0.</p>
</div>

Notes

flex-shrink: 0 is the usual fix for icons and avatars that get squashed in a row.

See also

  • flex — A shorthand for how a flex item grows, shrinks and what size it starts from.
  • flex-grow — How much of the free space a flex item takes.
  • min-width — The minimum width: the element cannot become narrower.

In the tutorial

  • Flex items — How to control individual items in flexbox — flex-grow, flex-shrink, flex-basis, the flex shorthand, align-self, order and margin auto.

Thanks for reading!

Donate to the site — we work hard for you.