Logical sizes and spacing
Definition and purpose
Logical sizes and spacing follow writing direction. They let one set of rules position content relative to the start and end of a line instead of hard-coding left and right.
Asymmetric RTL padding
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #a, #b { background: lightblue; } #p { direction: rtl; } #a { inline-size: 100px; padding-inline: 8px 16px; } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>The start padding maps to right and the end to left.
Syntax and mental model
inline-size and block-size correspond to width and height in horizontal writing. padding-inline: 8px 16px gives the inline start and end different padding. margin-block sets spacing along the block axis. In RTL horizontal text the inline start is right; in vertical LTR writing it is top.
Vertical logical size
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #a, #b { background: lightblue; } #a { writing-mode: vertical-rl; inline-size: 90px; block-size: 40px; margin-block-start: 6px; } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>Inline size is physical height in this writing mode.
Common mistakes
Mixing physical and logical properties on the same side can produce competing declarations. Prefer one consistent approach unless a genuinely physical edge is required.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Writing modes and direction. Next lesson: Logical borders and insets.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Logical sizes and spacing — knowledge check
Five questions on logical sizes and spacing.
What is inline-size in horizontal writing?
What is inline-size in vertical writing?
Which side is inline-start in horizontal RTL?
Which axis does margin-block use?
Can physical and logical declarations conflict?