CSS Reference ยท Box Model and Sizing
The min-width property
Reference for the CSS min-width property: set a floor under an element's width, use it with percentages and flex items, and fix overflowing flex children.
The min-width property sets a lower limit for an element's width. If the computed width would be smaller, the box is widened to min-width. It beats max-width only in one case: when the two conflict, min-width wins.
It is most useful to stop flexible elements from becoming unreadably narrow, and it also has an important hidden role in flexbox and grid: the automatic minimum size of items.
.button { min-width: 8rem; } .flex-child { min-width: 0; }
Try it
In the first row the flex item refuses to shrink below its content, so the text sticks out past the frame. In the second row min-width: 0 lets the item shrink, and the ellipsis appears.
Syntax
min-width: auto | <length-percentage [0,โ]> | min-content | max-content | fit-content | fit-content(<length-percentage>) | stretch;
- Initial value:
auto - Applies to: all elements except non-replaced inline elements, table rows and row groups
- Inherited: no
- Animatable: yes, as a length or percentage
- Computed value: a percentage or
autoas specified, otherwise an absolute length
Values
| Value | Description |
|---|---|
auto |
Computes to 0 for most boxes. For flex and grid items it is the content-based minimum size. |
<length> |
A fixed floor such as 200px or 12rem. |
<percentage> |
A percentage of the containing block's width. |
min-content, max-content, fit-content |
Content-based floors. |
stretch |
Fill the available space. Newer, with limited support. |
Usage notes
min-widthoverridesmax-widthandwidth. The order is: the used width is clamped bymax-width, then raised bymin-width.- Flexbox overflow fix. A flex item's
min-width: autoprevents it from shrinking below its content. Long words, URLs, code blocks and images then overflow. Settingmin-width: 0(oroverflow: hidden) lets the item shrink. - Grid has the same behavior. Use
minmax(0, 1fr)instead of1frfor the same reason. - Don't force widths on small screens. A large
min-widthcan create horizontal scrolling on phones. Prefermin-width: min(20rem, 100%). - Tables. On table cells it acts as a hint in practice; test across browsers.
- Logical equivalent:
min-inline-size.
Browser support
Supported in every browser. min-width: auto for flex items is implemented consistently in all current browsers.
Related
max-widthโ upper limitwidthโ preferred widthmin-heightโ the vertical floorflex-shrinkโ how items shrink- Lesson: Width and Height
- Lesson: Flex Items