Skip to: content, navigation

by Tommy Olsson and Paul O’Brien

min-width (CSS property)

Browser support full matrix
IE7+ FF1+ Saf2+ Op9.2+
Full Full Full Full
Spec
Inherited Initial Version
No 0 CSS2

Example

This style rule assigns a minimum width of 100 pixels to paragraphs within the element with ID "example":

#example p {
  min-width: 100px;
}

Try it yourself!View all demos

Description

This property sets the minimum content width of a block or a replaced element. This minimum width does not include padding, borders, or margins—see The CSS Box Model.

An element to which min-width is applied will never be narrower than the minimum width specified, but it will be allowed to grow normally if its content exceeds the minimum width set.

min-width is often used in conjunction with max-width to produce a width range for the element concerned.

Combining min-width and width

It should be noted that min-width and width values should not be applied to the same element if they use the same unit, as one will override the other. For example, if the width is set to 150px and the min-width is set to 60px, the actual width of the element is 150px, and the min-width declaration becomes redundant:

#example {
  min-width: 60px;
  width: 150px;
}

In the above example, the width of the element will be fixed at 150px.

However, it’s acceptable to set both min-width and width when their values are given in different units:

#example {
  min-width: 3em;
  width: 138px;
}

As the min-width is based on em units, at some stage, due to text resizing (for example), the em width may be larger than the 138px width we’ve set. In cases such as this, the element will be allowed to expand further than the 138px width, thus accommodating the resizing of the em-based text.

If the contents of a block require more horizontal space than is afforded by the limits that have been set, the behavior is defined by the overflow property.

Value

The property takes a CSS length (px, pt, em, and so on), or a percentage. Negative length values are illegal.

Percentage values refer to the width of the element’s containing block. If the containing block’s width is negative, the used value is zero.

Compatibility

IE5.5None
6.0None
7.0Full
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Partial
2.0Full
3.0Full
Opera9.2Full
9.5Full

Safari’s support for this property, when applied to positioned elements, is limited to versions 2.0.2 or above.

Internet Explorer for Windows versions up to and including 7 don’t support the value inherit.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters