Writing Modes, Direction and Vertical Text
Text that doesn't run left to right: writing-mode for vertical CJK and Mongolian, sideways modes for rotated labels, text-orientation and text-combine-upright, right-to-left direction with dir, bidirectional isolation, and :dir().
kvi5hnuCode Sprout team member7 min readOn this page
Most CSS is written with left-to-right, top-to-bottom text in mind. But Arabic and Hebrew run right to left, and Chinese, Japanese and Korean are often set in vertical lines. CSS handles all of these with a few properties, and with the logical properties from article 47, which follow the text instead of the screen.
writing-mode
writing-mode sets the direction lines run (the inline axis) and the direction they stack (the block axis):

| Value | Lines run | Lines stack | Used for |
|---|---|---|---|
horizontal-tb (initial) | horizontally | top to bottom | most scripts |
vertical-rl | top to bottom | right to left | traditional Chinese, Japanese and Korean |
vertical-lr | top to bottom | left to right | Mongolian |
sideways-rl | top to bottom, glyphs rotated clockwise | right to left | rotated labels |
sideways-lr | bottom to top, glyphs rotated anticlockwise | left to right | rotated labels, spine text |
writing-mode is inherited, and an element whose writing mode differs from its parent's becomes an independent formatting context, laid out as a block in the parent.
In a vertical mode, the logical properties swap their physical meaning. Tested in Chrome, in a vertical-rl container:
margin-block: 10pxbecamemargin-leftandmargin-right.padding-inline-startbecamepadding-top.inline-size: 150pxbecame the height.
That's why layouts built with logical properties work unchanged in vertical text.
Sideways text for labels
The sideways-* values rotate the whole line, including Latin letters, which is what you want for a rotated table header or a book spine: sideways-lr reads from bottom to top. They work in all browsers since Chrome 132. Tested in Chrome: at the default 16px, "Label" in sideways-lr took the same 18 × 36px box as in vertical-rl, but reads in the opposite direction.
th.rotated { writing-mode: sideways-lr; } /* reads bottom to top */
Before these values, rotated labels used transform: rotate(-90deg), which doesn't change the layout box, so the text overlaps its neighbours. A writing mode changes the box itself.
Latin text and numbers in vertical lines
In vertical text, Chinese and Japanese characters stand upright, but Latin letters and digits are rotated 90° by default. Two properties change that:
| Property | Values |
|---|---|
text-orientation | mixed (default: CJK upright, Latin rotated), upright (everything upright, Latin letters stacked one above another), sideways (everything rotated) |
text-combine-upright | none, or all: squeeze the whole run of characters into the space of one character, horizontally |
Tested in Chrome, at 20px in vertical-rl: "ABC" was 41px tall rotated, and 69px with text-orientation: upright, as the letters stacked. "26" with text-combine-upright: all took only 20px of the line, the length of one character.
text-combine-upright is meant for short runs, like two-digit dates in Japanese vertical text (tate-chū-yoko). Apply it to an element wrapping just those digits:
<p class="vertical">令和<span class="tcy">8</span>年<span class="tcy">11</span>月</p>
.vertical { writing-mode: vertical-rl; }
.tcy { text-combine-upright: all; }
Direction: right-to-left text
Arabic, Hebrew, Persian and Urdu are written right to left. Set the direction with the HTML dir attribute, not CSS:
<html lang="ar" dir="rtl">
The CSS direction property exists, but direction is part of the content's meaning, and dir also works when CSS doesn't load, and is understood by assistive technology and browser features like form controls. Use dir="auto" for user-generated content of unknown language: the browser picks a direction from the first strong character.
With dir="rtl":
startandendintext-alignand logical properties flip. Tested in Chrome:margin-inline-start: 20pxinsidedir="rtl"becamemargin-right.- Flex and grid items run from right to left.
- Physical properties, like
left,margin-leftandrotate, don't change. Icons that indicate direction, like arrows, may need mirroring::dir(rtl) .icon-next { scale: -1 1; }.
Bidirectional text
Right-to-left text often contains left-to-right parts, like numbers, product names or URLs. The Unicode bidirectional algorithm orders them automatically, but it can get things wrong when neutral characters like punctuation sit between runs of different directions, especially with text inserted from data:
<p>User <bdi>إيان</bdi>: 3 posts</p>
<bdi>isolates text of unknown direction, so it doesn't affect its surroundings. Use it for user names and other inserted values.<bdo dir="rtl">forces a direction, overriding the algorithm.- In CSS,
unicode-bidi: isolatedoes what<bdi>does, andunicode-bidi: isolate-overridewhat<bdo>does (it both isolates and overrides). Prefer the HTML elements, for the same reasons asdir.
:dir()
The :dir(rtl) and :dir(ltr) pseudo-classes match by the element's resolved direction, inherited from dir on an ancestor, unlike [dir="rtl"], which matches only elements with the attribute. Tested in Chrome: a <span> inside <div dir="rtl"> matched :dir(rtl). It works in all browsers since Chrome 120.
body { font: 0.85rem system-ui, sans-serif; margin: 1rem; }
.row { display: flex; gap: 1.5rem; align-items: flex-start; }
.jp { writing-mode: vertical-rl; inline-size: 9rem; margin: 0; /* inline-size is the line length: here, the height */
font-size: 1.05rem; line-height: 1.7;
padding: 0.5rem; background: #f4efe6; border-radius: 6px; }
.tcy { text-combine-upright: all; }
table { border-collapse: collapse; }
th.rot { writing-mode: sideways-lr; padding: 0.4rem 0.2rem; font-weight: 600; color: #8a3b12; }
td { text-align: center; padding: 0.3rem 0.5rem; border-block-start: 1px solid #d8cfc0; }
.rtl { margin-top: 1rem; padding: 0.5rem; background: #f4efe6; border-inline-start: 4px solid #8a3b12; font-size: 1rem; }
:dir(rtl) .next { display: inline-block; scale: -1 1; } /* mirror the arrow for right-to-left */
The Japanese paragraph runs top to bottom and right to left, with the two digits combined upright; the table headers are rotated with sideways-lr, and the Arabic line's border is on its start side, which is the right.

Compare the three labels: both writing modes give the label a tall, narrow box that its neighbours respect, while rotate() turns only the drawing and leaves the original wide box behind.
What's current
writing-modewithsideways-rlandsideways-lr: all browsers since Chrome 132.text-orientationandtext-combine-upright: all: all browsers.:dir(): all browsers since Chrome 120.- Logical properties (article 47) work everywhere, and are the way to write direction-independent CSS.
Common questions
How do I rotate a table header without overlapping?
Use writing-mode: sideways-lr instead of a transform, so the layout box rotates with the text.
Should I use direction: rtl or dir="rtl"?
dir="rtl" in the HTML. Direction belongs to the content.
Why are digits sideways in my vertical text?
text-orientation: mixed rotates Latin characters. Wrap short numbers in an element with text-combine-upright: all, or use text-orientation: upright.
How do I style elements differently in right-to-left pages?
Use logical properties so most styles adapt automatically, and :dir(rtl) for the rest, like mirrored icons.
Summary
writing-modesets the inline and block directions;vertical-rlis for CJK,vertical-lrfor Mongolian,sideways-*for rotated labels.- Logical properties follow the writing mode, so layouts work in any direction.
text-orientationandtext-combine-uprightcontrol Latin letters and numbers in vertical lines.- Set direction with HTML
dir;dir="auto"for unknown text;<bdi>isolates inserted text. :dir()matches the resolved direction, including inherited.
Practice questions
In writing-mode: vertical-rl, which physical side does padding-inline-start apply to?
Answer
The top. In vertical-rl, lines run from top to bottom, so the inline start is the top.
Why is writing-mode: sideways-lr better than transform: rotate(-90deg) for a rotated table header?
Answer
A transform only changes how the box is drawn, not its layout size, so the column stays as wide as the unrotated text and the rotated text overlaps neighbours. A writing mode changes the box, so the header is narrow and tall.
A comment system shows user names that may be in Arabic or English, followed by a number. How do you keep the number in the right place?
Answer
Wrap each user name in <bdi>, so its direction is isolated from the surrounding text: <bdi>{name}</bdi>: 3 comments.
Write CSS that mirrors arrow icons in right-to-left content, wherever the direction comes from.
Answer
:dir(rtl) .arrow { scale: -1 1; }
:dir() matches the inherited direction, unlike [dir="rtl"] .arrow, which needs an ancestor with the attribute, and doesn't work for dir="auto".
Previous: White Space, Line Breaking, Hyphenation and text-wrap: balance and pretty
Next: Readable Typography: Measure, Line Height, Vertical Rhythm and Spacing

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.