π What Is max-block-size?
The max-block-size property sets themaximum size of an element in the block direction. The block direction depends on the writing-mode:
- β‘ Horizontal writing (English): block = height
- β¬ Vertical writing (Japanese/Chinese): block = width
Note
β Writing-mode aware
β Essential for internationalized + responsive layouts
π¦ Syntax
max-block-size syntax
max-block-size: <length> | <percentage> | none | max-content | min-content | fit-content();π Understanding Logical Directions
| Writing Mode | Block Direction | max-block-size Equals |
|---|---|---|
| horizontal-tb | vertical | max-height |
| vertical-rl | horizontal | max-width |
π 1. Basic Example (Horizontal Writing)
Basic max-block-size
.box {
max-block-size: 300px; /* same as max-height: 300px */
}π 2. Vertical Writing Mode Example
Vertical writing
.poem {
writing-mode: vertical-rl;
max-block-size: 300px; /* now acts like max-width */
}The block axis rotates automatically in vertical writing modes.
π 3. Using Percentages
Percentage limit
.panel {
max-block-size: 60%;
}Percentage is relative to the parentβs block-size (height in horizontal writing, width in vertical writing).
π 4. Prevent Elements from Growing Too Tall
Restrict growth
.description {
max-block-size: 200px;
overflow: auto;
}Useful for scrollable boxes that shouldn't exceed a certain height.
π 5. Intrinsic Sizing Keywords
Intrinsic keywords
.item {
max-block-size: max-content; /* grow as needed up to content max */
max-block-size: min-content; /* rarely used; restricts tightly */
max-block-size: fit-content(300px);
}π 6. Combine Min and Max Logical Sizes
Clamp block size
.box {
min-block-size: 150px;
max-block-size: 300px;
}π§ͺ Real-World Use Cases
1οΈβ£ Scrollable Modal Content
Modal content
.modal-body {
max-block-size: 50vh;
overflow-y: auto;
}Prevents the modal from overflowing the screen vertically.
2οΈβ£ Responsive Card Layout
Card example
.card {
max-block-size: 250px;
padding: 1rem;
}3οΈβ£ Vertical Writing Support
Japanese layout
.japan-text {
writing-mode: vertical-rl;
max-block-size: 400px; /* acts like max-width */
}4οΈβ£ Limit Chat Message Height
Chat message
.message {
max-block-size: 6rem;
overflow: hidden;
text-overflow: ellipsis;
}β οΈ Common Mistakes
- β Using max-height instead of max-block-size in RTL/vertical layouts
- β Forgetting block direction changes in vertical writing
- β Setting max-block-size on inline elements (must be block/inline-block/flex/grid item)
- β Forgetting to add overflow when the content exceeds max size
Note
π₯ Summary
The max-block-size property controls the maximum size along the block direction β acting like max-height in horizontal writing and max-width in vertical layouts. It's essential for responsive, restricted-size components like modals, cards, and text boxes.
Learn more βMDN Docs π