πŸ“ CSS block-size β€” Complete Tutorial

🌐 What Is block-size?

The block-size property defines the size of an element in the block direction. The block direction depends on the document’s writing mode:

  • ➑ In horizontal writing (English): block = height
  • ⬆ In vertical writing (Japanese, Chinese): block = width
>>β€œUse block-size for layouts that automatically adapt to writing modes and international languages.”

Note

βœ” Logical equivalent of height
βœ” Writing-mode aware
βœ” Supports responsive + multilingual UI

πŸ“¦ Syntax

block-size syntax

block-size: <length> | <percentage> | auto | max-content | min-content | fit-content();

πŸ“Œ Understanding Logical Directions

Writing ModeBlock Directionblock-size Equals
horizontal-tb (default)verticalheight
vertical-rlhorizontalwidth

πŸ“Œ 1. Basic Example (Horizontal Writing)

Block-size = height

.box {
  block-size: 200px; /* same as height: 200px */
}

πŸ“Œ 2. Vertical Writing Mode Example

Vertical writing

.vertical-text {
  writing-mode: vertical-rl;
  block-size: 200px; /* now acts like width */
}

In vertical-rl mode, block direction is horizontal β€” so block-size expands width.

πŸ“Œ 3. Using Percentages

Percentage block-size

.panel {
  block-size: 50%;
}

Applies to the block dimension relative to the parent’s block-size (height in horizontal writing).

πŸ“Œ 4. Using Intrinsic Sizing Keywords

Intrinsic block sizes

.box {
  block-size: max-content;  /* Expand to longest content */
  block-size: min-content;  /* Shrink to smallest */
  block-size: fit-content(300px); /* Fit but clamp */
}

πŸ“Œ 5. Replace Height With Block-Size in Responsive Layouts

Logical height replacement

.card {
  block-size: 300px;
}

Using logical properties makes your UI future-proof and multilingual-ready.

πŸ“Œ 6. Limiting Block Size

Min and max block size

.note {
  min-block-size: 150px;
  max-block-size: 300px;
}

πŸ§ͺ Real-World Use Cases

1️⃣ Card Component with Consistent Vertical Size

Card component

.card {
  block-size: 250px;
  padding: 1rem;
}

2️⃣ Vertical Language Support (Japanese Layout)

Japanese layout

.japan {
  writing-mode: vertical-rl;
  block-size: 200px; /* horizontal sizing */
}

3️⃣ Responsive Fullscreen Section

Fullscreen block

section.full {
  block-size: 100vh;
}

Works just like height, but adjusts for writing modes automatically.

⚠️ Common Mistakes

  • ❌ Mixing logical (block-size) and physical (height) sizing β†’ conflicts
  • ❌ Forgetting writing mode affects block direction
  • ❌ Assuming block-size changes width (only in vertical modes!)

Note

Use block-size consistently when building international-friendly layouts.

πŸ”₯ Summary

The block-size property is the logical equivalent ofheight in CSS (or width in vertical writing modes). It makes your layout responsive to writing direction, language, and orientation.

>>β€œThink in block and inline directions β€” not top and side β€” for modern, global CSS.”

Learn more β†’MDN Docs πŸ“˜