Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Container Queries and Logical Properties

The max-inline-size property

Reference for the CSS max-inline-size property: cap the logical width, build readable line lengths with ch units, and see how it follows the writing mode.

The max-inline-size property sets the largest size an element may have along the inline axis. In horizontal writing modes it behaves like max-width; in vertical writing modes it behaves like max-height.

It is the standard tool for keeping text at a comfortable line length and for stopping boxes and media from growing past their container.

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

Try it

A readable line length

The limited box stops growing at about 36 characters per line plus its padding, however wide the preview is. On a narrow screen it simply shrinks with its container.

Syntax

CSS
max-inline-size: none | <length> | <percentage> | min-content | max-content
               | fit-content | fit-content(<length-percentage>) | stretch
  • Initial value: none
  • Applies to: same as width and height
  • Inherited: no
  • Animatable: yes, as a length or percentage
  • Computed value: as for max-width
  • Percentages: relative to the inline size of the containing block

Values

Value Description
none No upper limit.
<length> A fixed maximum such as 40rem, 600px or 65ch.
<percentage> A share of the containing block's inline size.
min-content, max-content, fit-content Intrinsic sizing keywords based on the content.
stretch The maximum is the full available space. Newer; check a compatibility table.

Usage notes

  • ch for text. A ch is about the width of the digit zero in the element's font, so 60ch to 75ch gives roughly 60 to 75 characters per line. Set the maximum on the text container, not on the whole page.
  • Fluid up to a point. Set inline-size: 100% (or leave a block as auto) plus a max-inline-size. The box fills small screens and stops at the maximum on big ones. This replaces the old width: 960px; margin: 0 auto pattern, which causes horizontal scrolling on narrow screens.
  • Center it with auto margins. A block with a limited size is placed at the start edge. Add margin-inline: auto to center it.
  • Media. max-inline-size: 100% with block-size: auto keeps images and videos inside their container while keeping their aspect ratio.
  • Min beats max. If both min-inline-size and max-inline-size apply and the minimum is larger, the minimum wins.
  • Padding and borders. Remember box-sizing: with content-box, the limit applies to the content, so padding makes the box wider than the value.
  • Logical or physical? Both max-inline-size and max-width are fine in horizontal-only sites. Use the logical form when components may appear in vertical text or you want one rule for all writing modes.

Browser support

Supported in all current major browsers and part of Baseline; the stretch keyword is newer, so check a compatibility table.