max-width

Sets the maximum width of an element. It prevents the element from becoming wider than the specified value, even if the content or container is larger.

It is documented as part of the CSS Box Sizing specification.

/* Usage Example */
.article-content {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  /* keeps text lines at a readable length on large screens */
}

/* Syntax */
max-width: none;
max-width: length-percentage;
max-width: min-content;
max-width: max-content;
max-width: fit-content;
max-width: calc-size;
max-width: anchor-size;

/* Global values */
max-width: inherit;
max-width: initial;
max-width: revert;
max-width: revert-layer;
max-width: unset;
Widely available Since 2015 96% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.

1+
1+
1+
12+
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC