CSS min-width Property

The CSS min-width property sets the minimum width an element is allowed to have.

It prevents an element from becoming narrower than a specified value while allowing it to grow when its content or layout requires additional space. The property is commonly used for buttons, form controls, cards, tables, and responsive flexbox and grid layouts.

min-width Syntax

The min-width property accepts nonnegative lengths, percentages, intrinsic sizing keywords, and supported sizing functions.

Basic Syntax

selector {
  min-width: 200px;
}

Relative Length

.panel {
  min-width: 15rem;
}

Percentage Value

.panel {
  min-width: 50%;
}

Viewport-Relative Width

.panel {
  min-width: 30vw;
}

Intrinsic Sizing

.panel {
  min-width: min-content;
}
.panel {
  min-width: max-content;
}
.panel {
  min-width: fit-content(300px);
}

Automatic Minimum

.panel {
  min-width: auto;
}

CSS-Wide Keywords

.panel {
  min-width: initial;
}
.panel {
  min-width: inherit;
}
.panel {
  min-width: unset;
}
.panel {
  min-width: revert;
}
.panel {
  min-width: revert-layer;
}

The initial value is auto. Its behavior depends on the element's layout context, particularly when the element participates in a flex or grid layout.

Property Values

Value Description
auto Uses the automatic minimum width determined by the layout context. This is the initial value.
<length> Sets a minimum width using units such as px, em, rem, or viewport units.
<percentage> Sets a minimum width relative to the containing block's width when the percentage can be resolved.
min-content Uses the element's intrinsic minimum-content width.
max-content Uses the element's intrinsic maximum-content width.
fit-content() Uses intrinsic sizing limits together with the supplied available-space value.
stretch Establishes a minimum based on the containing block's available width, accounting for the element's margin box. Browser support varies.
initial Resets the property to auto.
inherit Uses the computed value from the parent element.
unset Resets the property to auto because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Elements that accept width constraints
Computed value As specified, with relative lengths converted to absolute lengths
Animation type By computed value type
Physical dimension Width
Logical equivalent min-inline-size in horizontal writing modes

How It Works

The min-width property establishes a lower limit on an element's width. If the preferred width is smaller than the minimum, the minimum takes precedence.

Width Below the Minimum

.box {
  width: 100px;
  min-width: 200px;
}

The minimum overrides the smaller preferred width, producing a used width of at least 200 pixels.

Width Above the Minimum

.box {
  width: 300px;
  min-width: 200px;
}

The preferred width remains 300 pixels because it satisfies the minimum.

Automatic Width

.box {
  width: auto;
  min-width: 200px;
}

The box is at least 200 pixels wide. Its final width depends on its display type, available space, and content.

Automatic Minimum

.box {
  min-width: auto;
}

In ordinary block layout, the automatic minimum width generally resolves to zero. Flex and grid items can instead have content-based automatic minimum widths that prevent them from shrinking below their content's intrinsic size.

Important Consideration

A minimum width does not establish an upper limit. Use max-width when an element must also have a maximum width.

min-width vs. width

The width property sets an element's preferred width, while min-width establishes a minimum width.

Preferred Width

.box {
  width: 200px;
}

The element has a preferred width of 200 pixels. Content that does not fit may overflow, depending on the layout and overflow rules.

Minimum Width

.box {
  min-width: 200px;
}

The element cannot become narrower than 200 pixels under the applicable sizing rules, but it may be wider.

Width with a Minimum

.box {
  width: 50%;
  min-width: 250px;
}

The preferred width is 50% of the containing block, but the element cannot become narrower than 250 pixels.

Comparison

Property Purpose
width Sets the preferred physical width.
min-width Sets the minimum permitted physical width.
max-width Sets the maximum permitted physical width.

Length and Percentage Values

Length and percentage values allow minimum widths to be defined using fixed, relative, and container-dependent dimensions.

Pixels

.panel {
  min-width: 250px;
}

The panel must be at least 250 pixels wide.

Root Font Units

.panel {
  min-width: 15rem;
}

The minimum width is calculated relative to the root element's font size.

Font-Relative Units

.panel {
  min-width: 12em;
}

The minimum width is based on the element's computed font size.

Character Units

.input-field {
  min-width: 20ch;
}

The ch unit is based on the advance width of the 0 glyph in the element's font. It is useful for approximate text-based dimensions.

Viewport Width

.panel {
  min-width: 30vw;
}

The minimum width is 30% of the viewport width.

Percentage Width

.parent {
  width: 600px;
}
.child {
  min-width: 50%;
}

The child's minimum width resolves to 300 pixels when its containing block is 600 pixels wide.

Calculated Minimum

.panel {
  min-width: calc(15rem + 2vw);
}

The minimum combines a root-font-relative length with a viewport-relative length.

Negative Values

.panel {
  min-width: -100px;
}

Negative lengths and percentages are invalid. Zero and positive values are permitted.

Intrinsic Sizing Values

Intrinsic sizing values establish minimum widths based on the element's content and available layout space.

min-content

.box {
  min-width: min-content;
}

The minimum is based on the intrinsic minimum-content width. For ordinary horizontal text, this is often influenced by the longest unbreakable word or content segment.

max-content

.box {
  min-width: max-content;
}

The minimum is based on the intrinsic maximum-content width. For ordinary horizontal text, this generally reflects the width required without soft wrapping.

fit-content()

.box {
  min-width: fit-content(300px);
}

The fit-content() function uses intrinsic sizing limits while considering the supplied available-space value.

stretch

.box {
  min-width: stretch;
}

The stretch keyword establishes a minimum based on the containing block's available width, accounting for the element's margin box. Browser support varies.

Important Consideration

Intrinsic sizing values depend on content and layout context. Check browser compatibility when using newer sizing keywords or functions.

Minimum and Maximum Width

The min-width and max-width properties establish lower and upper width constraints.

Width Range

.panel {
  min-width: 150px;
  max-width: 400px;
}

The panel's used width is constrained between 150 and 400 pixels, subject to the applicable sizing rules.

Preferred Width Below the Minimum

.panel {
  width: 100px;
  min-width: 200px;
}

The minimum overrides the smaller preferred width.

Preferred Width Above the Maximum

.panel {
  width: 500px;
  max-width: 350px;
}

The maximum limits the used width to 350 pixels, assuming no larger minimum applies.

Minimum Takes Precedence

.panel {
  min-width: 400px;
  max-width: 250px;
}

When the minimum exceeds the maximum, the minimum width takes precedence.

Box Sizing

.panel {
  box-sizing: border-box;
  min-width: 200px;
  padding: 20px;
  border: 2px solid #64748b;
}

With border-box, the specified minimum includes padding and borders. With content-box, the minimum applies to the content box.

Responsive Layouts

Minimum widths are useful for interface components that need a practical lower size limit. However, overly large minimums can cause horizontal overflow on narrow screens.

Minimum Button Width

.button {
  display: inline-block;
  min-width: 120px;
  padding: 12px 20px;
  box-sizing: border-box;
  text-align: center;
}

The button maintains a minimum width of 120 pixels and can become wider when its label requires more space.

Minimum Input Width

.form-input {
  width: 100%;
  min-width: 180px;
  box-sizing: border-box;
}

The input fills its containing block but cannot become narrower than 180 pixels. This may cause overflow if its container is smaller.

Responsive Minimum

.panel {
  min-width: clamp(150px, 25vw, 300px);
}

The minimum width responds to viewport size while remaining between 150 and 300 pixels.

Media Query Adjustment

.panel {
  min-width: 300px;
}
@media (max-width: 767px) {
  .panel {
    min-width: 0;
  }
}

The explicit minimum is removed on narrow screens, allowing the panel to shrink when its layout permits.

Responsive Card

.card {
  width: 100%;
  max-width: 400px;
  min-width: 0;
  box-sizing: border-box;
}

The card can shrink to fit a narrow container while remaining no wider than 400 pixels. The minimum of zero is especially useful when the card is a flex or grid item.

Important Consideration

For components that must fit narrow screens, avoid minimum widths larger than the available container. Test layouts with long text, enlarged fonts, and mobile viewport sizes.

Flexbox and Grid

Flex and grid items can have content-based automatic minimum widths. These minimums can prevent items from shrinking as expected.

Flex Item Minimum Width

.flex-container {
  display: flex;
  width: 100%;
}
.flex-content {
  flex: 1;
  min-width: 0;
}

Setting min-width: 0 allows a row-direction flex item to shrink below its content-based automatic minimum.

Grid Item Minimum Width

.grid-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px;
}
.grid-content {
  min-width: 0;
}

The first grid track can shrink below its content's intrinsic minimum, and the grid item can shrink within the assigned track.

Responsive Grid Columns

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 16px;
}
.card {
  min-width: 0;
  padding: 20px;
  box-sizing: border-box;
}

The grid creates flexible columns with a target minimum of 220 pixels. The min() function allows the track minimum to become smaller when the container is narrower than 220 pixels.

Long Unbreakable Content

.flex-content {
  min-width: 0;
  overflow-wrap: anywhere;
}

The minimum allows the item to shrink, while overflow-wrap permits long text segments to break when necessary.

Important Consideration

Setting min-width: 0 does not automatically make overflowing content wrap. Additional wrapping or overflow rules may still be necessary.

Logical Sizing

The min-width property always controls physical width. Logical sizing properties adapt to the element's writing mode.

Physical Minimum Width

.box {
  min-width: 200px;
}

This always constrains the horizontal dimension.

Logical Minimum Inline Size

.box {
  min-inline-size: 200px;
}

In horizontal writing modes, this corresponds to min-width. In vertical writing modes, it corresponds to min-height.

Logical Minimum Block Size

.box {
  min-block-size: 200px;
}

In horizontal writing modes, this corresponds to min-height. In vertical writing modes, it corresponds to min-width.

Comparison

Property Horizontal Writing Mode Vertical Writing Mode
min-width Minimum width Minimum width
min-inline-size Minimum width Minimum height
min-block-size Minimum height Minimum width

Use min-width when the minimum must always apply to physical width. Use logical sizing when the constraint should follow the writing mode.

Overflow Behavior

A minimum width establishes a lower limit but does not guarantee that an element will fit inside its containing block.

Minimum Larger Than the Container

.container {
  width: 300px;
}
.panel {
  min-width: 500px;
}

The panel may extend beyond the 300-pixel container because its minimum width is 500 pixels.

Allow Content to Wrap

.panel {
  min-width: 0;
  overflow-wrap: anywhere;
}

The element can shrink when its layout permits, and long text can wrap instead of forcing additional width.

Scrollable Content

.code-panel {
  min-width: 0;
  overflow-x: auto;
}

The panel can fit within a constrained layout while providing horizontal scrolling for content that exceeds its width.

Minimum and Maximum Width

.panel {
  min-width: 200px;
  max-width: 600px;
  overflow-x: auto;
}

The element has minimum and maximum width constraints. Content wider than the available area can scroll when the element's used width is constrained.

Important Consideration

Use minimum widths only when they are necessary. A large minimum can force horizontal scrolling even when the preferred width is responsive.

min-width Example

This example compares a box with an automatic minimum width and a box with a minimum width of 220 pixels. Both boxes have a preferred width of 120 pixels.

HTML Example

<div class="min-width-demo">
  <div class="min-width-item">
    <h3>min-width: auto</h3>
    <div class="min-width-box automatic">
      <p>Sample content</p>
    </div>
  </div>
  <div class="min-width-item">
    <h3>min-width: 220px</h3>
    <div class="min-width-box limited">
      <p>Sample content</p>
    </div>
  </div>
</div>

CSS Example

.min-width-demo {
  display: grid;
  gap: 20px;
  padding: 20px;
  background-color: #f1f5f9;
}
.min-width-item h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.min-width-box {
  box-sizing: border-box;
  width: 120px;
  padding: 15px;
  background-color: #dbeafe;
  border: 2px solid #2563eb;
  border-radius: 6px;
}
.min-width-box p {
  margin: 0;
}
.automatic {
  min-width: auto;
}
.limited {
  min-width: 220px;
}
Browser Result

min-width: auto

Sample content

min-width: 220px

Sample content

The first box uses its preferred width of 120 pixels. The second box expands to 220 pixels because its minimum width overrides the smaller preferred width.

Responsive Button Example

<button class="action-button" type="button">Continue</button>
.action-button {
  min-width: 140px;
  max-width: 100%;
  padding: 12px 20px;
  box-sizing: border-box;
  background-color: #2563eb;
  color: #fff;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

The button maintains a minimum width of 140 pixels. If the containing block becomes narrower than 140 pixels, the minimum takes precedence over the maximum and may cause overflow.

Common Mistakes

Confusing min-width with width

.box {
  min-width: 200px;
}

This establishes a minimum rather than a fixed width. The element can become wider when its layout requires additional space.

Using Negative Values

.box {
  min-width: -100px;
}

Negative lengths and percentages are invalid.

Conflicting Minimum and Maximum Widths

.box {
  min-width: 400px;
  max-width: 200px;
}

The minimum width takes precedence when it exceeds the maximum.

Expecting min-width to Prevent Overflow

A minimum width can cause overflow when it exceeds the available space. It does not guarantee that an element will fit inside its container.

Ignoring Automatic Minimum Sizes

Flex and grid items can resist shrinking because of content-based automatic minimum widths. Use min-width: 0 when an item must be allowed to shrink below that minimum.

Using Large Minimums on Mobile Screens

.panel {
  min-width: 800px;
}

A large minimum can force horizontal scrolling on narrow screens. Use responsive values or adjust the minimum at smaller viewport widths.

Forgetting Box Sizing

With content-box, padding and borders add to the specified minimum content-box width. Use border-box when the minimum should include them.

Confusing Physical and Logical Sizing

min-width always controls physical width. Use min-inline-size when the minimum should follow the logical inline axis.

Important Considerations

Keep the following points in mind when using min-width:

  • The property sets a minimum physical width.
  • Its initial value is auto.
  • The property is not inherited.
  • It does not prevent an element from becoming wider than the minimum.
  • Length and percentage values must be nonnegative.
  • Percentage values depend on the containing block's width and applicable sizing rules.
  • Intrinsic sizing values depend on content and layout context.
  • min-width takes precedence when it exceeds max-width.
  • width sets a preferred width, while min-width establishes a lower limit.
  • box-sizing affects whether padding and borders are included in the specified minimum.
  • Minimum widths are useful for buttons, form controls, and interface components.
  • Large minimum widths can cause horizontal overflow.
  • Flex and grid items can have content-based automatic minimum widths.
  • Setting min-width: 0 can allow certain flex and grid items to shrink.
  • Long unbreakable content may require additional wrapping or overflow rules.
  • The property always controls physical width, regardless of writing mode.
  • Use min-inline-size when the constraint should follow the logical inline axis.
  • Test minimum widths on narrow screens and with enlarged text.

Browser Support

The CSS min-width property is Baseline - Widely available. It is supported in current versions of all major browsers, including Chrome, Edge, Firefox, and Safari.

Basic length, percentage, and auto values have broad support. Newer intrinsic sizing values, including stretch, may have different browser compatibility requirements.

For current compatibility information, visit Can I Use? and search for min-width.

When using newer sizing keywords or functions, check compatibility for those specific values.

Specifications

The min-width property is defined in CSS Sizing Module Level 3.

CSS Sizing Module Level 3: Minimum Size Properties

The specification defines minimum size constraints and their relationship to preferred and maximum sizes.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: min-width