CSS max-inline-size Property

The CSS max-inline-size property sets the maximum size of an element along its inline axis.

It is a logical sizing property that corresponds to max-width in horizontal writing modes and max-height in vertical writing modes. Because it follows the writing mode rather than a fixed physical direction, it is useful for responsive layouts, readable text containers, and multilingual websites.

max-inline-size Syntax

The max-inline-size property accepts a nonnegative length, percentage, intrinsic sizing value, or the none keyword.

Basic Syntax

selector {
  max-inline-size: 600px;
}

Relative Length

.content {
  max-inline-size: 40rem;
}

Percentage Value

.content {
  max-inline-size: 80%;
}

Intrinsic Sizing

.content {
  max-inline-size: min-content;
}
.content {
  max-inline-size: max-content;
}
.content {
  max-inline-size: fit-content(500px);
}

No Maximum Limit

.content {
  max-inline-size: none;
}

CSS-Wide Keywords

.content {
  max-inline-size: initial;
}
.content {
  max-inline-size: inherit;
}
.content {
  max-inline-size: unset;
}
.content {
  max-inline-size: revert;
}
.content {
  max-inline-size: revert-layer;
}

The initial value is none, meaning the property does not impose a maximum inline size.

Property Values

Value Description
none Specifies no maximum inline-size constraint. This is the initial value.
<length> Sets the maximum inline size using units such as px, em, rem, or vw.
<percentage> Sets the maximum inline size relative to the containing block's inline size, when the percentage can be resolved.
min-content Uses the intrinsic minimum-content size as the maximum.
max-content Uses the intrinsic maximum-content size as the maximum.
fit-content() Uses intrinsic sizing while applying the specified available-space limit.
stretch Constrains the element's margin box to the available inline size of its containing block. Browser support varies.
initial Resets the property to none.
inherit Uses the computed value from the parent element.
unset Resets the property to none because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to Elements that accept width or height constraints
Computed value As specified, with relative lengths converted to absolute lengths
Animation type By computed value type
Initial maximum Unrestricted
Physical equivalent max-width or max-height, depending on writing mode

How It Works

The inline axis follows the direction in which text and other inline content are arranged. In horizontal writing modes, it runs horizontally. In vertical writing modes, it runs vertically.

The max-inline-size property establishes an upper limit along this axis without requiring the element to occupy the entire available size.

Set a Maximum Inline Size

.content-box {
  max-inline-size: 500px;
}

In horizontal writing mode, the content box cannot exceed 500 pixels in width, subject to minimum-size constraints and other applicable sizing rules.

Content Smaller Than the Maximum

.content-box {
  inline-size: 300px;
  max-inline-size: 500px;
}

The specified inline size remains 300 pixels because it is below the maximum.

Content Larger Than the Maximum

.content-box {
  inline-size: 700px;
  max-inline-size: 500px;
}

The maximum constrains the used inline size to 500 pixels.

Maximum Does Not Mean Fixed

When the inline size is determined by content or layout rules, the element can remain smaller than its maximum. The property does not automatically expand an element to the specified value.

Logical vs. Physical Sizing

Physical sizing properties use fixed dimensions such as width and height. Logical sizing properties follow the block and inline axes established by the writing mode.

Physical Maximum Width

.box {
  max-width: 600px;
}

This limits the physical width regardless of writing mode.

Logical Maximum Inline Size

.box {
  max-inline-size: 600px;
}

This limits width in horizontal writing modes and height in vertical writing modes.

Logical Sizing Properties

Property Purpose
inline-size Sets the preferred size along the inline axis.
min-inline-size Sets the minimum size along the inline axis.
max-inline-size Sets the maximum size along the inline axis.
block-size Sets the preferred size along the block axis.
min-block-size Sets the minimum size along the block axis.
max-block-size Sets the maximum size along the block axis.

Using logical properties helps a layout adapt when the writing mode changes without requiring separate physical width and height declarations.

Writing Modes

The physical dimension controlled by max-inline-size depends on the element's computed writing-mode.

Writing Mode Inline Axis Physical Equivalent
horizontal-tb Horizontal max-width
vertical-rl Vertical max-height
vertical-lr Vertical max-height
sideways-rl Vertical max-height
sideways-lr Vertical max-height

Horizontal Writing Mode

.horizontal-box {
  writing-mode: horizontal-tb;
  max-inline-size: 300px;
}

The maximum applies to the element's width.

Vertical Writing Mode

.vertical-box {
  writing-mode: vertical-rl;
  max-inline-size: 300px;
}

The maximum applies to the element's height.

Text Direction

The direction property affects inline progression, but changing between left-to-right and right-to-left text does not by itself change which physical dimension corresponds to the inline axis.

Important Consideration

Logical sizing follows the writing mode of the element receiving the property, not simply the language of the text it contains.

Length and Percentage Values

Lengths and percentages allow the maximum inline size to be expressed in fixed, relative, or container-dependent units.

Pixels

.content {
  max-inline-size: 600px;
}

The maximum inline size is 600 pixels.

Root Font Units

.content {
  max-inline-size: 45rem;
}

The maximum is calculated relative to the root element's font size.

Character Units

.article {
  max-inline-size: 65ch;
}

The ch unit is based on the advance width of the 0 glyph in the element's font. It is useful for approximating readable line lengths in horizontal text.

Viewport Units

.content {
  max-inline-size: 80vw;
}

The maximum is 80% of the viewport width. The vw unit always refers to viewport width, regardless of writing mode.

Percentage Value

.container {
  inline-size: 800px;
}
.content {
  max-inline-size: 75%;
}

When the containing block's corresponding dimension is 800 pixels, the maximum resolves to 600 pixels.

Zero and Negative Values

.content {
  max-inline-size: 0;
}

Zero is valid. Negative length and percentage values are invalid.

Intrinsic Sizing Values

Intrinsic sizing values calculate constraints using the element's content and available space.

min-content

.box {
  max-inline-size: min-content;
}

The maximum is based on the element's minimum-content inline size. For text, this can be influenced by the longest unbreakable segment.

max-content

.box {
  max-inline-size: max-content;
}

The maximum is based on the size the content would prefer without soft wrapping opportunities restricting its inline dimension.

fit-content()

.box {
  max-inline-size: fit-content(500px);
}

The fit-content() function combines intrinsic sizing limits with the specified available-space value.

stretch

.box {
  max-inline-size: stretch;
}

The stretch keyword limits the margin box to the available inline size of the containing block. Support varies by browser.

Important Consideration

Intrinsic sizing values can behave differently depending on the layout context. Check browser support for the specific value, especially when using newer sizing features.

Minimum and Maximum Sizing

The max-inline-size property works with inline-size and min-inline-size to control an element's size along the inline axis.

Set an Inline Size Range

.panel {
  min-inline-size: 200px;
  max-inline-size: 600px;
}

The panel's inline size is constrained between the specified minimum and maximum, subject to layout rules.

Preferred Inline Size

.panel {
  inline-size: 800px;
  max-inline-size: 600px;
}

The maximum constrains the used inline size to 600 pixels.

Minimum Takes Precedence

.panel {
  min-inline-size: 500px;
  max-inline-size: 300px;
}

When the minimum exceeds the maximum, the minimum takes precedence.

Flexible Container

.content {
  inline-size: 100%;
  max-inline-size: 70rem;
  margin-inline: auto;
}

This creates a content container that can use the available inline space without exceeding 70rem. The logical margins center it when the layout provides extra space.

Box Sizing

.panel {
  box-sizing: border-box;
  max-inline-size: 500px;
  padding: 20px;
  border: 2px solid #64748b;
}

With border-box, padding and borders are included in the specified maximum. With content-box, the maximum applies to the content box.

Responsive Layouts

The max-inline-size property is particularly useful for limiting content width while allowing layouts to adapt to smaller screens.

Readable Article Width

article {
  max-inline-size: 65ch;
  margin-inline: auto;
}

This limits the article's inline dimension to approximately 65 character units, helping prevent excessively long text lines.

Responsive Content Container

.content-container {
  inline-size: 100%;
  max-inline-size: 1200px;
  margin-inline: auto;
}

The container can fill the available inline space on smaller screens while remaining limited to 1200 pixels on larger screens.

Viewport-Based Maximum

.content-container {
  max-inline-size: min(100%, 70rem);
}

The min() function selects the smaller of the available percentage and the fixed maximum.

Responsive Card

.card {
  inline-size: 100%;
  max-inline-size: 350px;
  box-sizing: border-box;
}

The card can shrink with its container while remaining no larger than 350 pixels along the inline axis.

Important Consideration

Padding, borders, and minimum-size constraints can affect whether an element fits within the available space. Use box-sizing: border-box when the specified maximum should include padding and borders.

Images and Media

Logical maximum sizing can constrain images and other media while respecting the writing mode.

Responsive Image

img {
  max-inline-size: 100%;
  block-size: auto;
}

In horizontal writing mode, this behaves similarly to max-width: 100% with an automatic height. It helps prevent images from exceeding their containing block's inline size.

Limit Image Size

.article-image {
  max-inline-size: 500px;
  block-size: auto;
}

The image cannot exceed 500 pixels along its inline axis, subject to other applicable sizing constraints.

Video Element

video {
  max-inline-size: 100%;
  block-size: auto;
}

This provides a logical inline-size constraint for video elements.

Images in Vertical Writing Modes

.vertical-media {
  writing-mode: vertical-rl;
  max-inline-size: 300px;
}

In this writing mode, the maximum applies to the element's physical height rather than its width.

Important Consideration

When preserving an image's aspect ratio, avoid forcing conflicting inline and block sizes. Automatic sizing along one axis generally allows the intrinsic aspect ratio to be maintained.

max-inline-size Example

This example compares two content boxes. The first uses the available width without an explicit maximum, while the second is limited to 280 pixels along the inline axis.

HTML Example

<div class="max-inline-demo">
  <div class="max-inline-item">
    <h3>max-inline-size: none</h3>
    <div class="max-inline-box no-limit">
      <p>This box can use the available width of its container.</p>
    </div>
  </div>
  <div class="max-inline-item">
    <h3>max-inline-size: 280px</h3>
    <div class="max-inline-box limited">
      <p>This box cannot exceed 280 pixels along the inline axis.</p>
    </div>
  </div>
</div>

CSS Example

.max-inline-demo {
  display: grid;
  gap: 20px;
  padding: 20px;
  background-color: #f1f5f9;
}
.max-inline-item h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.max-inline-box {
  box-sizing: border-box;
  inline-size: 100%;
  padding: 18px;
  background-color: #dbeafe;
  border: 2px solid #2563eb;
  border-radius: 6px;
}
.max-inline-box p {
  margin: 0;
}
.no-limit {
  max-inline-size: none;
}
.limited {
  max-inline-size: 280px;
}
Browser Result

max-inline-size: none

This box can use the available width of its container.

max-inline-size: 280px

This box cannot exceed 280 pixels along the inline axis.

The first box stretches across the available inline space. The second box is constrained to 280 pixels when enough space is available, but can shrink on narrower screens.

Vertical Writing Mode Example

<div class="vertical-inline-demo">
  <p>Logical sizing follows the inline axis.</p>
</div>
.vertical-inline-demo {
  writing-mode: vertical-rl;
  inline-size: 300px;
  max-inline-size: 180px;
  block-size: 140px;
  box-sizing: border-box;
  padding: 15px;
  background-color: #dcfce7;
  border: 2px solid #16a34a;
}

In vertical writing mode, the inline axis runs vertically. The specified inline size of 300 pixels is constrained by the 180-pixel maximum, so the maximum affects the element's height.

Common Mistakes

Confusing max-inline-size with inline-size

.box {
  max-inline-size: 500px;
}

This sets a maximum, not a required inline size. The element can remain smaller.

Assuming the Property Always Controls Width

In vertical writing modes, max-inline-size controls the physical height. Use max-width when a fixed physical width constraint is required.

Using Negative Values

.box {
  max-inline-size: -100px;
}

Negative length and percentage values are invalid.

Conflicting Minimum and Maximum Values

.box {
  min-inline-size: 500px;
  max-inline-size: 300px;
}

The minimum takes precedence when it exceeds the maximum.

Confusing Block and Inline Axes

max-inline-size constrains the inline axis. Use max-block-size for the block axis.

Mixing Physical and Logical Constraints

.box {
  max-width: 600px;
  max-inline-size: 400px;
}

In horizontal writing mode, both declarations affect the physical width. The cascade determines which value applies. Prefer a consistent sizing approach when possible.

Forgetting Box Sizing

With the default content-box sizing, padding and borders can increase the total rendered dimension beyond the specified content-box maximum.

Expecting Percentages to Always Resolve

Percentage constraints depend on the containing block's corresponding dimension. In layouts with indefinite sizes, percentage sizing can behave differently than expected.

Important Considerations

Keep the following points in mind when using max-inline-size:

  • The property sets the maximum size along the inline axis.
  • Its initial value is none.
  • The property is not inherited.
  • In horizontal writing modes, it corresponds to max-width.
  • In vertical writing modes, it corresponds to max-height.
  • It does not force an element to expand to the maximum size.
  • Length and percentage values must be nonnegative.
  • Percentage values are relative to the containing block's corresponding dimension.
  • Intrinsic sizing keywords depend on content and layout context.
  • min-inline-size takes precedence when its minimum exceeds the maximum.
  • box-sizing affects whether padding and borders are included in the specified maximum.
  • The property is useful for readable text containers and responsive layouts.
  • Logical sizing adapts to different writing modes.
  • max-block-size constrains the other logical axis.
  • Newer intrinsic sizing values may have different browser support requirements.
  • Test logical sizing in the writing modes used by your website.

Browser Support

The CSS max-inline-size property is Baseline - Widely available. It is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.

Basic length, percentage, and none values have broad support. Some newer intrinsic sizing values, including stretch, may have different compatibility requirements.

For current compatibility information, visit Can I Use? and search for max-inline-size.

When supporting older browsers, test logical sizing together with the writing modes used by your website.

Specifications

The max-inline-size property is defined in CSS Logical Properties and Values Level 1.

CSS Logical Properties and Values Level 1: Logical Dimension Properties

The specification defines logical sizing properties and their mapping to physical dimensions according to writing mode.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: max-inline-size