CSS max-block-size Property

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

It is a logical sizing property that corresponds to max-height in horizontal writing modes and max-width in vertical writing modes. Unlike physical sizing properties, max-block-size adapts to the element's writing mode, making it useful for multilingual and responsive layouts.

max-block-size Syntax

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

Basic Syntax

selector {
  max-block-size: 300px;
}

Percentage Value

.element {
  max-block-size: 80%;
}

Relative Length

.element {
  max-block-size: 20rem;
}

Intrinsic Sizing

.element {
  max-block-size: max-content;
}
.element {
  max-block-size: min-content;
}
.element {
  max-block-size: fit-content(300px);
}

No Maximum Limit

.element {
  max-block-size: none;
}

CSS-Wide Keywords

.element {
  max-block-size: initial;
}
.element {
  max-block-size: inherit;
}
.element {
  max-block-size: unset;
}
.element {
  max-block-size: revert;
}
.element {
  max-block-size: revert-layer;
}

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

Property Values

Value Description
none Specifies no maximum block-size constraint. This is the default.
<length> Sets a maximum block size using units such as px, em, rem, or vh.
<percentage> Sets a maximum block size relative to the containing block's size along the corresponding axis, when that size 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 size as an available-space limit.
stretch Limits the element's margin box to the available size of its containing block. Support varies.
initial Resets the property to none.
inherit Inherits 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-height or max-width, depending on writing mode

How It Works

The block axis is the direction in which blocks are arranged in the element's writing mode. In horizontal English text, blocks typically progress from top to bottom, so the block axis corresponds to the physical height.

The max-block-size property establishes an upper limit for the element's size along that axis.

Maximum Block Size

.content-box {
  max-block-size: 200px;
}

The content box can be smaller than 200 pixels, but its block size is constrained to a maximum of 200 pixels, subject to other sizing rules.

Content Smaller Than the Maximum

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

If the content requires only 100 pixels of block size, the element does not automatically expand to 300 pixels. The property sets a maximum, not a required size.

Content Larger Than the Maximum

.content-box {
  max-block-size: 150px;
  overflow: auto;
}

When content exceeds the maximum, the element can become scrollable if the overflow rules permit scrolling.

Maximum Size Is Not a Fixed Size

.box {
  block-size: 100px;
  max-block-size: 200px;
}

The element's specified block size remains 100 pixels because it is below the maximum.

By contrast, a specified block size of 300 pixels would be constrained by the 200-pixel maximum, unless another sizing rule takes precedence.

Logical vs. Physical Sizing

Physical sizing properties refer to width and height. Logical sizing properties refer to the block and inline axes, which depend on the writing mode.

Physical Maximum Height

.box {
  max-height: 200px;
}

This limits the physical height regardless of writing mode.

Logical Maximum Block Size

.box {
  max-block-size: 200px;
}

This limits the block-axis dimension. It corresponds to height in horizontal writing modes and width in vertical writing modes.

Logical Sizing Properties

Logical Property Purpose
block-size Sets the 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.
inline-size Sets the 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.

Logical properties are particularly useful when a layout needs to support multiple writing directions without separate width and height rules.

Writing Modes

The physical dimension controlled by max-block-size depends on the computed writing-mode of the element.

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

Horizontal Writing Mode

.horizontal-box {
  writing-mode: horizontal-tb;
  max-block-size: 150px;
}

The maximum applies to the element's height.

Vertical Writing Mode

.vertical-box {
  writing-mode: vertical-rl;
  max-block-size: 150px;
}

The maximum applies to the element's width because its block axis runs horizontally.

Writing Direction

The direction property can affect inline progression, but it does not by itself switch the block axis between horizontal and vertical. That behavior is determined by writing-mode.

Length and Percentage Values

Length and percentage values provide direct control over the maximum block-axis dimension.

Pixels

.panel {
  max-block-size: 250px;
}

Pixels establish a fixed maximum size along the block axis.

Relative Font Units

.panel {
  max-block-size: 20rem;
}

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

Viewport Units

.panel {
  max-block-size: 60vh;
}

The maximum is based on 60% of the viewport height. The vh unit always refers to viewport height, even when the element uses a vertical writing mode.

Percentage

.container {
  block-size: 400px;
}
.panel {
  max-block-size: 50%;
}

When the containing block's corresponding dimension is definite, the percentage can resolve against that dimension. In this example, the maximum is 200 pixels.

Unresolved Percentages

If the containing block's relevant size depends on its content, a percentage maximum may not resolve as expected. In common non-absolute positioning contexts, it can behave as though no maximum were specified.

Nonnegative Values

.panel {
  max-block-size: 0;
}

Zero is valid and limits the block size to zero. Negative length and percentage values are invalid.

Intrinsic Sizing Values

Intrinsic sizing values allow the maximum block size to depend on the element's content and available space.

min-content

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

The maximum uses the element's intrinsic minimum-content contribution along the block axis.

max-content

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

The maximum uses the intrinsic maximum-content size along the block axis.

fit-content()

.box {
  max-block-size: fit-content(250px);
}

The fit-content() function combines intrinsic minimum and maximum sizing with a supplied available-space limit.

stretch

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

The stretch keyword constrains the element's margin box to the containing block's available size. Browser support for this keyword should be checked separately from basic max-block-size support.

Important Consideration

Intrinsic sizing behavior can depend on the layout context and available space. Some values have less consistent browser support than basic lengths and percentages.

Minimum and Maximum Sizing

The max-block-size property works with block-size and min-block-size to establish sizing constraints.

Set a Size Range

.panel {
  min-block-size: 100px;
  max-block-size: 300px;
}

The panel can grow with its content, but its used block size is constrained by the minimum and maximum values.

Explicit Block Size

.panel {
  block-size: 400px;
  max-block-size: 250px;
}

The maximum constraint limits the used block size to 250 pixels.

Minimum Takes Precedence

.panel {
  min-block-size: 300px;
  max-block-size: 200px;
}

When the minimum exceeds the maximum, the minimum constraint takes precedence. The resulting used block size cannot be smaller than the minimum.

Responsive Sizing

.panel {
  block-size: auto;
  max-block-size: min(400px, 70vh);
}

The min() function selects the smaller of the two limits, helping prevent the panel from becoming too tall for the viewport in horizontal writing modes.

Box Sizing

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

With border-box, the maximum includes padding and borders. With content-box, the specified maximum applies to the content box.

Overflow Behavior

A maximum size constraint does not automatically hide content that exceeds the available space. Overflow behavior must be considered separately.

Default Overflow

.panel {
  max-block-size: 150px;
  overflow: visible;
}

Content can extend beyond the constrained box because the default overflow behavior permits it.

Scrollable Content

.panel {
  max-block-size: 150px;
  overflow: auto;
}

Scrollbars appear when necessary, allowing users to access content that exceeds the available space.

Hide Overflow

.panel {
  max-block-size: 150px;
  overflow: hidden;
}

Content extending beyond the box is clipped. Avoid hiding essential information that users need to read or interact with.

Logical Overflow

.panel {
  max-block-size: 150px;
  overflow-block: auto;
}

The logical overflow-block property targets overflow along the block axis, but its browser support is less consistent. The physical overflow shorthand is generally the safer choice for production layouts.

max-block-size Example

This example compares a content panel with no maximum block-size constraint and one with a maximum of 120 pixels. The second panel becomes scrollable when its content exceeds the limit.

HTML Example

<div class="max-block-demo">
  <div class="max-block-item">
    <h3>max-block-size: none</h3>
    <div class="max-block-panel no-limit">
      <p>HTML provides the structure of a web page.</p>
      <p>CSS controls the appearance of HTML elements.</p>
      <p>JavaScript adds interactive behavior.</p>
      <p>Responsive layouts adapt to different screens.</p>
    </div>
  </div>
  <div class="max-block-item">
    <h3>max-block-size: 120px</h3>
    <div class="max-block-panel limited">
      <p>HTML provides the structure of a web page.</p>
      <p>CSS controls the appearance of HTML elements.</p>
      <p>JavaScript adds interactive behavior.</p>
      <p>Responsive layouts adapt to different screens.</p>
    </div>
  </div>
</div>

CSS Example

.max-block-demo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.max-block-item {
  min-width: 0;
}
.max-block-item h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}
.max-block-panel {
  padding: 15px;
  background-color: #e0f2fe;
  border: 1px solid #0284c7;
  border-radius: 6px;
}
.max-block-panel p {
  margin: 0 0 12px;
}
.max-block-panel p:last-child {
  margin-bottom: 0;
}
.no-limit {
  max-block-size: none;
}
.limited {
  max-block-size: 120px;
  overflow: auto;
}
@media (max-width: 575px) {
  .max-block-demo {
    grid-template-columns: 1fr;
  }
}
Browser Result

max-block-size: none

HTML provides the structure of a web page.

CSS controls the appearance of HTML elements.

JavaScript adds interactive behavior.

Responsive layouts adapt to different screens.

max-block-size: 120px

HTML provides the structure of a web page.

CSS controls the appearance of HTML elements.

JavaScript adds interactive behavior.

Responsive layouts adapt to different screens.

The first panel expands to accommodate its content. The second panel is limited to 120 pixels along the block axis, with scrolling available for additional content.

Vertical Writing Mode Example

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

In vertical writing mode, the block axis runs horizontally. The specified block size of 240 pixels is constrained by the 180-pixel maximum, so the maximum affects width rather than height.

Common Mistakes

Confusing max-block-size with block-size

.box {
  max-block-size: 300px;
}

This sets an upper limit. It does not force the element to become 300 pixels tall or wide.

Assuming the Property Always Controls Height

In vertical writing modes, max-block-size controls the horizontal dimension. Use max-height when a physical height limit is required regardless of writing mode.

Using Negative Values

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

Negative lengths and percentages are invalid for this property.

Expecting Percentages to Always Resolve

.box {
  max-block-size: 50%;
}

A percentage maximum may not constrain the element if the containing block's corresponding dimension is indefinite.

Ignoring Overflow

Content can overflow a constrained element. Use an appropriate overflow property when content must remain accessible inside the limited area.

Conflicting Minimum and Maximum Values

.box {
  min-block-size: 400px;
  max-block-size: 200px;
}

The minimum takes precedence when it exceeds the maximum.

Confusing Block and Inline Axes

max-block-size limits the block axis. Use max-inline-size to limit the inline axis.

Mixing Physical and Logical Constraints

.box {
  max-height: 200px;
  max-block-size: 300px;
}

In horizontal writing mode, both declarations affect the same physical dimension. The cascade determines which declaration takes precedence. Prefer a consistent sizing approach when possible.

Important Considerations

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

  • The property sets the maximum size along the block axis.
  • Its initial value is none.
  • The property is not inherited.
  • In horizontal writing modes, it corresponds to max-height.
  • In vertical writing modes, it corresponds to max-width.
  • It does not force an element to expand to the maximum size.
  • Length and percentage values must be nonnegative.
  • Percentage values depend on the containing block's corresponding dimension.
  • Intrinsic sizing keywords can produce content-dependent constraints.
  • The min-block-size property takes precedence if its minimum exceeds the maximum.
  • The box-sizing property determines whether padding and borders are included in the specified size.
  • Overflow behavior must be handled separately.
  • Logical sizing is useful for multilingual layouts and different writing modes.
  • The max-inline-size property controls the other logical axis.
  • Use supported values when consistent behavior across browsers is important.

Browser Support

The CSS max-block-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-block-size.

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

Specifications

The max-block-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 how they map to physical dimensions according to writing mode.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: max-block-size