π CSS max-inline-size β Complete Tutorial
π What Is max-inline-size?
The max-inline-size property sets themaximum size of an element along the inline direction. The inline direction depends on the documentβs writing-mode:
- β‘ Horizontal writing (English): inline = width
- β¬ Vertical writing (Japanese/Chinese): inline = height
>>βUse max-inline-size to prevent elements from growing too wide (or too tall in vertical writing modes).β
Note
β Logical alternative to max-width
β Writing-mode aware
β Makes UI more robust in RTL & vertical scripts
β Writing-mode aware
β Makes UI more robust in RTL & vertical scripts
π¦ Syntax
max-inline-size syntax
max-inline-size: <length> | <percentage> | none | max-content | min-content | fit-content();π Understanding Logical Directions
| Writing Mode | Inline Direction | max-inline-size Equals |
|---|---|---|
| horizontal-tb | left β right | max-width |
| vertical-rl | top β bottom | max-height |
π 1. Basic Example (Horizontal Writing)
Basic max-inline-size
.box {
max-inline-size: 400px; /* same as max-width: 400px */
}π 2. Vertical Writing Mode Example
Vertical writing example
.vertical {
writing-mode: vertical-rl;
max-inline-size: 300px; /* now acts like max-height */
}The logical inline direction flips when writing mode changes.
π 3. Using Percentages
Percentage max inline size
.panel {
max-inline-size: 80%;
}Limits width relative to parentβs inline-size (usually width).
π 4. Limit Text Width for Better Readability
Text width control
p {
max-inline-size: 65ch; /* ideal readable line length */
}Very common in blogs & documentation sites.
π 5. Intrinsic Sizing Keywords
Intrinsic keywords
.item {
max-inline-size: max-content;
max-inline-size: min-content;
max-inline-size: fit-content(300px);
}π 6. Responsive Card Layout
Card example
.card {
max-inline-size: 350px;
padding: 1rem;
}π 7. Prevent Buttons From Becoming Too Wide
Button limit
button {
max-inline-size: 12rem;
}π 8. Use With Flex and Grid Layouts
Flex/Grid item
.flex-item {
flex: 1;
max-inline-size: 400px;
}
.grid-item {
max-inline-size: 250px;
}π§ͺ Real-World Use Cases
1οΈβ£ Blog or Article Container
Article width
.content {
max-inline-size: 70ch;
margin-inline: auto;
}Ensures perfect reading width even in RTL languages.
2οΈβ£ Product Cards That Should Not Stretch
Product card
.product {
max-inline-size: 300px;
}3οΈβ£ Prevent Form Inputs From Getting Too Wide
Form input
input {
max-inline-size: 20rem;
}4οΈβ£ Japanese / Vertical Writing Layouts
Vertical layout
.vertical-text {
writing-mode: vertical-rl;
max-inline-size: 25rem; /* acts like max-height */
}β οΈ Common Mistakes
- β Using max-width instead of max-inline-size in RTL/vertical layouts
- β Forgetting inline direction changes in writing-mode
- β Applying max-inline-size to inline elements without making them block/inline-block
- β Expecting it to add overflow β you must set overflow manually
Note
Logical properties like max-inline-size are more future-proof, especially for multilingual websites.
π₯ Summary
The max-inline-size property defines the maximum size along the inline axis β usually max-width, but it becomesmax-height in vertical writing modes. It enables more adaptable, global-friendly, and responsive layouts.
>>βInline-size and block-size are the modern way to think about dimensions β flexible and writing-mode aware.β
Learn more βMDN Docs π