Max-Width Property

Last updated: 2026-09-13

max-width Max-Width Property

The max-width property sets the maximum width of an element, preventing it from becoming too wide on large screens and hurting readability. Its default value, none, means there is no upper limit. It is a core tool for responsive design, often paired with width:100% so media elements adapt without exceeding their intrinsic size.

Category
Initial Valuenone
InheritedNo
Applies Tonon-replaced
Animation Typelength
CSS VersionCSS2
StatusStandard

📝 Syntax

max-width: none | <length> | <percentage> | min-content | max-content | fit-content;

⚙️ Values

ValueTypeDescription
noneKeywordNo maximum width.
<length>TypeA fixed maximum width.
<percentage>TypeA percentage relative to the containing block.

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
max-width v1 v12 v1 v1 v1
Supported in all major browsers
Tip: max-width takes precedence over width; even if width is set larger, the actual width will not exceed max-width.

❓ FAQ

QWhat does max-width:100% do?
Amax-width:100% keeps an element from being wider than its parent, and combined with height:auto it scales images proportionally without overflowing, which is the standard way to make media responsive. Unlike width:100%, which forces the element to fill the container and blows up small images, max-width:100% only shrinks the image when the container is narrower than the image's intrinsic size; larger images display at full size.
QHow do I center content while limiting its maximum width?
ASet a max-width to cap the width and use margin:0 auto to center the element horizontally, which is the most common approach. For example, an article body with max-width:800px; margin:0 auto; shrinks automatically on narrow screens and stays centered at 800px on wide ones. For margin:auto to work, the element must be block-level and narrower than the available space. This keeps reading lines a comfortable length on desktop displays while staying fully fluid on smaller screens.
QIf both max-width and width are set, which one wins?
Amax-width wins. When width exceeds max-width, the element renders at max-width; when width is smaller, width applies. The overall priority is min-width, then max-width, then width, so max-width caps width from above and can never go below min-width. This clamping is what keeps overly large width values from breaking a layout, which is why content stays within a comfortable reading measure.
QCan max-width use a percentage?
AYes. max-width accepts lengths, percentages, and content keywords. A percentage is computed against the containing block's width, so for example max-width:80% means no wider than 80% of the parent container. It also supports keywords such as min-content, max-content, and fit-content, which derive the upper bound from the content itself and give responsive behavior without media queries. Percentages are particularly useful for bounding panels inside fluid parents.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏