CSS max-width Property
Description
The max-width property establishes an upper limit on an element’s used width, ensuring the box will not be laid out wider than that limit even if its container or intrinsic content would normally allow it to expand. It acts as a clamp during the layout process: if the element’s natural or specified size would exceed this limit, the final used width is reduced to the maximum. This makes the property a simple but powerful tool for preventing oversized elements and preserving visual rhythm across varying viewport sizes.
Because it participates in the browser’s sizing resolution, max-width interacts closely with other sizing constraints. When combined with a specified width and a min-width, the final used width must satisfy the set of constraints together (the layout system resolves them so the used width does not violate the minimum or exceed the maximum). The effective measurement of the constraint depends on how the box model is interpreted, so differences in whether the element’s width includes decorations or not can change the apparent effect of the upper bound. Percentage-based upper bounds are resolved relative to the element’s containing block, so they scale with available space rather than remaining absolute.
In practice, authors use max-width to create responsive, robust designs: to cap text column measure for readability, prevent images and media from breaking fixed-width layouts, and allow elements to shrink without ever growing past a sensible limit. When content exceeds the constrained width, the treatment of that overflow is governed by the element’s overflow handling, so you should consider overflow when combining behaviors. Also bear in mind that the property remains an upper limit inside different layout contexts (normal flow, flex, grid), but the container’s layout algorithm and the element’s role in that algorithm - for example as a child of a complex layout - can influence the final computed size; it’s useful to keep the container’s display behavior in mind when predicting outcomes.
A few practical tips: use max-width to make media scale down gracefully while allowing them to grow to a sensible maximum, and pair it with careful container planning so elements don’t produce awkward whitespace or overflow. Because the property only limits growth and does not force enlargement, it is often paired conceptually with other sizing rules to produce predictable, adaptive interfaces.
Definition
- Initial value
- none
- Applies to
- All elements except non-replaced inline elements and table elements
- Inherited
- No
- Computed value
- The percentage as specified or the absolute length or 'none'
- Animatable
- Yes
- JavaScript syntax
- object.style.maxWidth
Interactive Demo
Syntax
max-width: [ [<length> | <percentage>] && [border-box | content-box]? ] | available | min-content | max-content | fit-content | none
Values
- <length>Specifies a fixed width. Negative values are not allowed.
- <percentage>A percentage relative to the width of the containing block. If the containing block has no width explicitly set then is is treated as none. Negative values are not allowed.
- max-contentThe max-content width or height.
- min-contentThe min-content width or height.
- availableThe containing block width or height minus margin, border, and padding.
- fit-contentIf the total available space is finite, equals to min(max-content, max(min-content, fill-available)). Otherwise, equal to the max-content measure. Requires CSS Intrinsic & Extrinsic Sizing Module support in browsers.
- noneThe width has no maximum value.
Example
Browser Support
The following information will show you the current browser support for the CSS max-width property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
