CSS max-width Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The max-width property sets the maximum horizontal width of an element. It stops the used width from growing past the value you set.

The box can stay narrower than the limit. It cannot grow wider once it hits the ceiling. Pair it with min-width for a floor. For writing-mode-aware sizing, see max-inline-size.

Standard-track.

Not deprecated. Length, percentage, and none are Baseline. Intrinsic keywords (fit-content, max-content) are widely supported; stretch is newer and limited.

Limited support stretch

The stretch keyword for max-width is not ready for everyday use. Prefer lengths, percentages, or none.

CSS Syntax

syntax.css
max-width: none | <length> | <percentage> | min-content | max-content | fit-content | initial | inherit;

Start with none, lengths, and percentages. auto is not a valid value here.

Property Values

ValueDescriptionTry it
noneDefault. No maximum widthTry it
<length>Fixed ceiling such as 20rem, 600px, or 40chTry it
<percentage>Percent of the containing block’s widthTry it
initialResets to noneTry it
inheritTakes the parent’s max-widthTry it

How to Use max-width

Choose a horizontal ceiling, then decide whether the box should also fill smaller containers.

  1. Leave max-width: none when the box should grow freely.
  2. Set a length or percentage to cap growth (great for readable line lengths).
  3. Combine width: 100% with a max so the box is fluid on small screens and capped on large ones.
  4. Use max-inline-size when the layout must follow writing mode.
PieceRequired?Role
Block or replaced elementYesNon-replaced inlines ignore max-width
max-width valueYesnone, length, percentage, or keyword
Containing block widthFor %Percentage resolves against the parent width
width: 100%OptionalMakes the box fill space up to the max

Live Preview

Same text, different max-width values. Watch the box stop growing wider.

max-width always limits horizontal size. The box can stay narrower than the cap.

Box
This box grows wider until it hits the max-width ceiling you set.

max-width: 12rem

CSS Examples

Each snippet focuses on max-width. Use Try It Yourself for a live editor.

Example 1 — Readable Length Cap

Stop a paragraph from stretching too wide on large screens.

CSS
<style>
  p {
    max-width: 20rem;
  }
</style>

<p>This paragraph will not grow wider than 20rem.</p>
Try It Yourself

How It Works

  1. Set a ceiling. 20rem is the maximum width.
  2. Short content stays short. The box can be narrower than 20rem.
  3. Long lines wrap. Extra text wraps inside the capped width.
  4. Other units work too. Try ch, em, or px the same way.

Example 2 — Fluid Width with a Cap

Fill the parent on small screens, but never exceed 12rem.

CSS
<style>
  .box {
    width: 100%;
    max-width: 12rem;
  }
</style>

<div class="box">Fluid up to 12rem.</div>
Try It Yourself

How It Works

  1. Ask for full width. width: 100% tries to fill the parent.
  2. Add a ceiling. max-width: 12rem wins when 100% would be wider.
  3. Small parents stay fluid. If the parent is under 12rem, the box still fills it.
  4. Override rule. When width and max-width conflict, the max wins.

Example 3 — No Cap vs Cap

Compare free growth with a hard ceiling on the same text.

CSS
<style>
  .free {
    max-width: none;
  }

  .capped {
    max-width: 12rem;
  }
</style>

<p class="free">Grows with the container.</p>
<p class="capped">Stops at 12rem.</p>
Try It Yourself

How It Works

  1. Leave the default. none means no horizontal ceiling.
  2. Add a ceiling. 12rem stops growth at that width.
  3. Text still wraps. The capped box wraps words instead of becoming wider.
  4. Remember min-width. If min-width is larger than the max, the min wins.

Edge Cases & Pitfalls

If the cap seems ignored, one of these is usually why.

auto

auto is not valid

Unlike width, max-width does not accept auto. Use none to remove the ceiling.

override

max-width beats width

max-width overrides width when both apply. min-width overrides max-width if the min is larger.

logical

Always horizontal, not logical

max-width always limits physical width. Prefer max-inline-size when writing mode may change.

inline

Non-replaced inlines ignore it

A plain span does not take max-width. Use a block, flex item, or replaced element.

a11y

Tight caps can hurt zoomed text

When users enlarge text, a tight max may feel cramped. Prefer flexible units like rem or ch for text columns.

Browser Support

max-width is a browser layout property. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

max-width

Length, percentage, and none work everywhere. Intrinsic keywords are widely supported; stretch is newer and limited.

99% Common values
Google Chrome 1+
Full
Mozilla Firefox 1+
Full
Apple Safari 1+
Full
Microsoft Edge 12+
Full
Opera Supported
Full
Samsung Internet Supported
Full
Internet Explorer 7+
Full
max-width Widely supported

Bottom line: Safe for everyday ceilings. Treat stretch as progressive enhancement until support is broad.

Key Takeaways

  • Role: set a ceiling on how wide a box can grow.
  • Common values: none, lengths, and percentages.
  • Initial value: none. Not inherited. auto is invalid.
  • Responsive pattern: width: 100% plus a max-width cap.

One line: max-width is a horizontal ceiling — the box can be narrower, never wider than the limit.

Frequently Asked Questions

It sets a maximum horizontal width for an element. The box can be narrower than the limit, but it cannot grow wider once it reaches that ceiling.
The initial value is none, which means there is no maximum width. The element can grow with its content and container.
width sets a preferred or fixed size. max-width only sets an upper limit. The box can still shrink below the max when the container is narrower.
Yes. max-width overrides width when the preferred width is larger. min-width overrides max-width if they conflict.
No. auto is not valid for max-width. Use none to remove the cap, or a length or percentage to set one.
It is Baseline and widely available in all major browsers. Newer keywords like stretch have limited support. It is a browser layout property, not a Node.js feature.

Next: min-block-size

Learn the logical minimum size on the block axis.

min-block-size tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful