π What Is inline-size?
The inline-size property defines the size of an element along the inline direction. The inline direction depends on the documentβs writing mode:
- β‘ In horizontal writing (English): inline = width
- β¬ In vertical writing (Japanese, Chinese): inline = height
Note
β Writing-mode aware
β Great for international & responsive web design
π¦ Syntax
inline-size syntax
inline-size: <length> | <percentage> | auto | max-content | min-content | fit-content();π Understanding Logical Directions
| Writing Mode | Inline Direction | inline-size Equals |
|---|---|---|
| horizontal-tb (default) | left β right | width |
| vertical-rl | top β bottom | height |
π 1. Basic Example (Horizontal Writing)
Inline-size = width
.box {
inline-size: 300px; /* same as width: 300px */
}π 2. Vertical Writing Mode Example
Vertical writing
.vertical {
writing-mode: vertical-rl;
inline-size: 300px; /* now affects height */
}In vertical writing, inline direction is vertical β so inline-size becomes height.
π 3. Using Percentages
Percentage inline-size
.panel {
inline-size: 50%;
}Applies against the parent's **inline-size** (width in horizontal writing).
π 4. Using Intrinsic Sizing Keywords
Intrinsic inline-size
.box {
inline-size: max-content; /* Expand to longest content */
inline-size: min-content; /* Shrink to smallest size */
inline-size: fit-content(250px);
}π 5. Replace Width With Inline-Size in Flexible Layouts
Logical width replacement
.card {
inline-size: 400px;
}Makes components work automatically in RTL and vertical text environments.
π 6. Limiting Inline Size
Min & Max inline-size
.text-block {
min-inline-size: 200px;
max-inline-size: 600px;
}Equivalent to:min-width & max-width in horizontal writing.
π§ͺ Real-World Use Cases
1οΈβ£ Restrict Paragraph Width for Readability
Readable text
p {
max-inline-size: 65ch;
}Ensures ideal reading line length, even in RTL languages.
2οΈβ£ Responsive Card Layout
Card
.card {
inline-size: 90%;
max-inline-size: 400px;
}3οΈβ£ Vertical Writing UI Component
Vertical mode
.japan {
writing-mode: vertical-rl;
inline-size: 200px; /* this becomes height */
}β οΈ Common Mistakes
- β Mixing width and inline-size (causes conflicts)
- β Forgetting inline direction changes in vertical writing
- β Setting inline-size on inline elements without display: block/inline-block
Note
π₯ Summary
The inline-size property defines an elementβs size along the inline axis (width in most languages, height in vertical scripts). It replaces width in modern, writing-modeβresponsive CSS.
Learn more βMDN Docs π