Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

max-width — maximum width

max-width limits an element’s physical width rather than setting it unconditionally. When size constraints conflict, min-width takes precedence.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

max-width: none;
max-width: 320px;
max-width: 100%;
/* Common forms, not the complete grammar. */

max-width specifies the maximum physical width. Its initial value, none, means no such limit; the property is not inherited.

Common values are nonnegative lengths and percentages. Percentages reference the containing block’s width. max-width constrains width, but a conflicting min-width wins.

For quantitative values such as lengths and percentages, box-sizing: content-box applies the limit to the content width, while border-box includes padding and borders in the limit. box-sizing does not change how intrinsic sizing keywords such as min-content are interpreted. max-width alone does not clip overflowing content.

In the example, width: 100% initially gives 400px, while max-width: 240px limits the border-box width to 240px.

Examples

<!doctype html>
<meta charset="utf-8">
<title>max-width</title>
<style>
  .container { width: 400px; }
  .box {
    box-sizing: border-box;
    width: 100%;
    max-width: 240px;
    padding: 10px;
    border: 2px solid;
  }
</style>
<div class="container">
  <div class="box">max-width</div>
</div>
<pre id="result"></pre>
<script>
  const box = document.querySelector('.box');
  document.querySelector('#result').textContent =
    `width: ${box.getBoundingClientRect().width}px`;
</script>

Result

width: 240px

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources