CSS Reference Property

min-width

The min-width property is used to set a minimum width of a specified element.

It is sometimes useful to constrain the width of an element in CSS to a certain range. Two properties are available to set a minimum and maximum width for an element: the min-width property and the max-width property.

The min-width property overrides both the width and max-width properties and prevents the value of the width property from becoming smaller than a specified value.

Official Syntax

  • Syntax:

    min-width: <length> | <percentage> | inherit
  • Initial: 0
  • Applies To: all elements but non-replaced inline elements, table columns, and column groups
  • Animatable: yes, as a length, percentage, or calc()

Notes

In CSS3, new values have been introduced to the min-width property. The official syntax looks as follows:

min-width: [ [<a href="http://tympanus.net/codrops/css_reference/length"><length></a> | <a href="http://tympanus.net/codrops/css_reference/percentage"><percentage></a>] && [border-box | content-box]? ] | available | min-content | max-content | fit-content

Values

<length>
Specifies a fixed minimum computed width. See the <length> entry for a list of possible values.
<percentage>
The <percentage> is calculated with respect to the width of the containing block. If the containing block’s width is negative, the used value is zero. If the containing block’s width depends on this element’s width, then the resulting layout is undefined in CSS 2.1.

See the <percentage> entry for a list of possible values.

inherit
The element inherits its minimum width value from its parent.

The following experimental keyword values have been introduced in CSS3.

available
Width is equal to the containing block width minus the current element’s margin, border, and padding.
max-content
The intrinsic preferred width. The max-content width is, roughly, the width the content would have if no “soft” line breaks were inserted, i.e., if each paragaph is one long line.
min-content
The intrinsic minimum width. The min-content width is, roughly, the narrowest the box can get by breaking all lines at all possible break points.

The following image helps understand the min-content and max-content values.

min-max-content
For example, in a simple paragraph with just text the max-content width is the width of the line if all words are laid out on one line; and the min-content width is the width of the longest word (or the longest syllable, if hyphenation is turned on).

More about min-content and max-content:

The min-content value is the narrowest a box can get by breaking all lines at all possible break points. In the above image, we saw how a text-only content can affect the container’s width with min-content. The same concept applies if you have an image inside an element. The element is an inline-element, and therefore a break point is also possible after it. So, if the element contained a piece of text, and an image, the image is more likely to be wider than any word inside the paragraph (unless you’re using some fancy and super long words, of course), so the image can be the content that specifies the minimum width of the element with min-content.

But, since the element can have a width greater than its minimum width, the value of min-width in this case is the same as width

View this demo on the Codrops Playground

Using max-content, the content inside the element will not break at any soft break points, and the text will be rendered as one long line, and the element must stretch to fit the longest line inside it, and that will be the minimum width it can have.

View this demo on the Codrops Playground
fit-content
Same as min-content.

Notes

Negative values are not allowed.

The keyword values (in contrast to length and percentage values) are not influenced by the box-sizing property, they always set the size of the content box.

Available, max-content, min-content and fit-content are equivalent to 0 when set on the min-width of vertical elements (when the writing mode is vertical, i.e. the writing-mode property has a value of vertical-rl or vertical-lr).

Examples

min-width: 250px;
min-width: 50%;
min-width: 100vh;
min-width: inherit;
                

Browser Support

The min-width property works in all major browsers: Chrome, Firefox, Safari, Opera, Internet Explorer, and on Android and iOS.

The new experimental values added in CSS3 are not yet supported in all browsers, and some of them have different equivalents supported in some browsers. The browser support for the new values is shown in the following table:

Intrinsic & Extrinsic Sizing

Allows for the heights and widths to be specified in intrinsic values using the `max-content`, `min-content`, `fit-content` and `stretch` (formerly `fill`) properties.

W3C Working Draft

Supported from the following versions:

Desktop

  • 94
  • 66
  • No
  • 95
  • 16

Mobile / Tablet

  • 16
  • 130
  • No
  • 130
  • 130

* denotes prefix required.

  • Supported:
  • Yes
  • No
  • Partially
  • Polyfill

Stats from caniuse.com

Notes

CSS 2.1 explicitly leaves the behavior of min-width with <table> undefined, so it is still not supported by all browsers.

Written by . Last updated December 11, 2016 at 10:39 pm by Manoela Ilic.

Do you have a suggestion, question or want to contribute? Submit an issue.