Writing modes and direction
Definition and purpose
The inline axis follows text within a line; the block axis follows successive lines or blocks. In horizontal writing they correspond to horizontal and vertical dimensions, but vertical writing changes that mapping.
RTL flex row
<!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 { width: 200px; display: flex; direction: rtl; } #a,#b { width: 40px; height: 20px; } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>The first item starts at the right edge in RTL.
Syntax and mental model
writing-mode: horizontal-tb places blocks top to bottom. vertical-rl places successive vertical lines right to left. HTML dir="rtl" specifies right-to-left base direction for Persian or Arabic; lang="fa" identifies the language. These attributes serve different purposes.
Vertical blocks
<!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 { width: 200px; height: 100px; writing-mode: vertical-rl; } #a,#b { width: 40px; height: 50px; } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>Successive blocks advance from right to left, not top to bottom.
Common mistakes
Do not rotate a horizontal layout with transform to simulate vertical writing. Do not assume lang alone establishes direction.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Adaptive layout project, Readable article mini-project. Next lesson: Logical sizes and spacing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Writing modes and direction — knowledge check
Five questions on writing modes and direction.
What determines block flow direction?
What identifies Persian language?
What sets RTL base direction semantically?
Where do vertical-rl blocks progress?
Is the inline axis always horizontal?