Flex Shrink - Tailwind CSS
Tailwind CSS home page Introducing Catalyst A modern application UI kit for React Theme Tailwind CSS on GitHub Flexbox & Grid Flex Shrink Tailwind CSS v4.0 is here → Learn more in the upgrade guide. Quick reference Class Properties shrink flex-shrink : 1 ; shrink-0 flex-shrink : 0 ; Basic usage Shrink Use shrink to allow a flex item to shrink if needed: 01 02 03 < div class = " flex ... " > < div class = " flex-none w-14 h-14 ...
" > 01 </ div > < div class = " shrink w-64 h-14 ... " > 02 </ div > < div class = " flex-none w-14 h-14 ... " > 03 </ div > </ div > Don’t shrink Use shrink-0 to prevent a flex item from shrinking: 01 02 03 < div class = " flex ... " > < div class = " flex-1 h-16 ... " > 01 </ div > < div class = " shrink-0 h-16 w-32 ... " > 02 </ div > < div class = " flex-1 h-16 ... " > 03 </ div > </ div > Applying conditionally Hover, focus, and other states Tailwind lets you conditionally apply utility classes in different states using variant modifiers.
For example, use hover : shrink-0 to only apply the shrink-0 utility on hover . < div class = " shrink hover:shrink-0 " > <!-- ... --> </ div > For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation. Breakpoints and media queries You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more.
For example, use md: shrink-0 to apply the shrink-0 utility at only medium screen sizes and above. < div class = " shrink md:shrink-0 " > <!-- ... --> </ div > To learn more, check out the documentation on Responsive Design , Dark Mode and other media query modifiers . Using custom values Customizing your theme By default, Tailwind provides two shrink utilities. You can customize these values by editing theme.flexShrink or theme.extend.flexShrink in your tailwind.config.js file. tailwind.config.js module . exports = { theme : { extend : { flexShrink : { 2 : '2' } } } } Learn more about customizing the default theme in the theme customization documentation. Arbitrary values If you need to use a one-off flex-shrink value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value. < div class = " shrink-[2] " > <!-- ... --> </ div > Learn more about arbitrary value support in the arbitrary values documentation.
On this page Quick reference Basic usage Shrink Don't shrink Applying conditionally Hover, focus, and other states Breakpoints and media queries Using custom values Customizing your theme Arbitrary values From the creators of Tailwind CSS Make your ideas look awesome, without relying on a designer. “This is the survival kit I wish I had when I started building apps.” Derrick Reimer, SavvyCal