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.
article { max-inline-size: 65ch; }
Try it
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
max-inline-size: none | <length> | <percentage> | min-content | max-content | fit-content | fit-content(<length-percentage>) | stretch
- Initial value:
none - Applies to: same as
widthandheight - 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
chfor text. Achis about the width of the digit zero in the element's font, so60chto75chgives 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 asauto) plus amax-inline-size. The box fills small screens and stops at the maximum on big ones. This replaces the oldwidth: 960px; margin: 0 autopattern, 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: autoto center it. - Media.
max-inline-size: 100%withblock-size: autokeeps images and videos inside their container while keeping their aspect ratio. - Min beats max. If both
min-inline-sizeandmax-inline-sizeapply and the minimum is larger, the minimum wins. - Padding and borders. Remember
box-sizing: withcontent-box, the limit applies to the content, so padding makes the box wider than the value. - Logical or physical? Both
max-inline-sizeandmax-widthare 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.
Related
min-inline-sizeโ the logical minimum widthinline-sizeโ the logical widthmax-block-sizeโ the logical maximum heightmax-widthโ the physical property- Lessons: Width and Height, Text Wrapping