The writing-mode
CSS property defines whether lines of text are laid out horizontally or vertically and the direction in which blocks progress.
/* Keyword values */ writing-mode: horizontal-tb; writing-mode: vertical-rl; writing-mode: vertical-lr; /* Global values */ writing-mode: inherit; writing-mode: initial; writing-mode: unset;
Syntax
The property specifies the block flow direction, which is the direction in which block-level containers are stacked, and the direction in which inline-level content flows within a block container. Thus the writing-mode
property also determines the ordering of block-level content.
Initial value | horizontal-tb |
---|---|
Applies to | all elements except table row groups, table column groups, table rows, and table columns |
Inherited | yes |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
Values
horizontal-tb
- Content flows horizontally from left to right, vertically from top to bottom. The next horizontal line is positioned below the previous line.
vertical-rl
- Content flows vertically from top to bottom, horizontally from right to left. The next vertical line is positioned to the left of the previous line.
vertical-lr
- Content flows vertically from top to bottom, horizontally from left to right. The next vertical line is positioned to the right of the previous line.
sideways-rl
- Content flows vertically from top to bottom and all the glyphs, even those in vertical scripts, are set sideways toward the right.
sideways-lr
- Content flows vertically from top to bottom and all the glyphs, even those in vertical scripts, are set sideways toward the left.
lr
- Deprecated except for SVG1 documents. For CSS, use
horizontal-tb
. lr-tb
- Deprecated except for SVG1 documents. For CSS, use
horizontal-tb
. rl
- Deprecated except for SVG1 documents. For CSS, use
horizontal-tb
. tb
- Deprecated except for SVG1 documents. For CSS, use
vertical-lr
. tb-rl
- Deprecated except for SVG1 documents. For CSS, use
vertical-rl
.
Formal syntax
horizontal-tb | vertical-rl | vertical-lr | sideways-rl | sideways-lr
Example
<table> <tr> <th>value</th> <th>Vertical script</th> <th>Horizontal script</th> <th>Mixed script</th> </tr> <tr> <td>horizontal-tb</td> <td class="example Text1"><span>我家没有电脑。</span></td> <td class="example Text1"><span>Example text</span></td> <td class="example Text1"><span>1994年に至っては</span></td> </tr> <tr> <td>vertical-lr</td> <td class="example Text2"><span>我家没有电脑。</span></td> <td class="example Text2"><span>Example text</span></td> <td class="example Text2"><span>1994年に至っては</span></td> </tr> <tr> <td>vertical-rl</td> <td class="example Text3"><span>我家没有电脑。</span></td> <td class="example Text3"><span>Example text</span></td> <td class="example Text3"><span>1994年に至っては</span></td> </tr> <tr> <td>sideways-lr</td> <td class="example Text4"><span>我家没有电脑。</span></td> <td class="example Text4"><span>Example text</span></td> <td class="example Text4"><span>1994年に至っては</span></td> </tr> <tr> <td>sideways-rl</td> <td class="example Text5"><span>我家没有电脑。</span></td> <td class="example Text5"><span>Example text</span></td> <td class="example Text5"><span>1994年に至っては</span></td> </tr>
table { border-collapse:collapse; } td, th {border: 1px black solid; padding: 3px; } th {background-color: lightgray; } .example { height:75px; width:75px; } .example.Text1 span, .example.Text1 { writing-mode: horizontal-tb; -webkit-writing-mode: horizontal-tb; -ms-writing-mode: horizontal-tb; } .example.Text2 span, .example.Text2 { writing-mode: vertical-lr; -webkit-writing-mode: vertical-lr; -ms-writing-mode: vertical-lr; } .example.Text3 span, .example.Text3 { writing-mode: vertical-rl; -webkit-writing-mode: vertical-rl; -ms-writing-mode: vertical-rl; } .example.Text4 span, .example.Text4 { writing-mode: sideways-lr; -webkit-writing-mode: sideways-lr; -ms-writing-mode: sideways-lr; } .example.Text5 span, .example.Text5 { writing-mode: sideways-rl; -webkit-writing-mode: sideways-rl; -ms-writing-mode: sideways-rl; }
Actual result
Specification
Specification | Status | Comment |
---|---|---|
CSS Writing Modes Module Level 3 The definition of 'writing-mode' in that specification. |
Candidate Recommendation | Initial definition |
Unknown The definition of 'writing-mode' in that specification. |
Unknown | Add sideways-lr and sideways-rl |
Browser compatibility
Feature | Chrome | Edge | Firefox | Internet Explorer (defunct) | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 8-webkit (Yes) |
(Yes)-webkit (Yes) |
41 (41)[1][3] | 9-ms[2] | 15-webkit | 5.1-webkit |
lr |
48 (uprefixed) | (Yes) | 43 (43) | 9-ms[2] | (Yes) | ? |
lr-tb |
||||||
rl |
||||||
rl-tb |
||||||
tb |
||||||
tb-rl |
||||||
horizontal-tb |
(Yes) (as of 58) | (Yes) (as of 40) | 43 (43) | No support (as of 11) | (Yes) (as of 44) | ? |
vertical-lr |
||||||
vertical-rl |
||||||
sideways-lr |
No support (as of 58) | No support (as of 40) | 43 (43) | No support (as of 11) | No support (as of 44) | ? |
sideways-rl |
Feature | Android | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | |
---|---|---|---|---|---|---|---|---|---|
Basic support | 3-webkit | (Yes) | 47-webkit (Yes) |
(Yes)-webkit (Yes) |
41.0 (41) [1][3] | ? | ? | 5.1 -webkit | |
SVG 1.1 values lr , lr-tb , rl , tb , tb-rl |
? | 48.0 (uprefixed) | 48.0 (uprefixed) | (Yes) | 43.0 (43) | ? | ? | ? | |
sideways-rl,sideways-lr |
No support[4] | No support | No support | No support | ? | ? | ? | ? | |
vertical-lr |
vertical-rl |
No support[4] | No support | No support | No support | ? | ? | ? | ? |
[1] An experimental implementation was available since Gecko 36. It is governed by the preference layout.css.vertical-text.enabled
, defaulting to false
until Firefox 38. From Firefox 39 and Firefox 40, the preference was true
for Nightly and DevTools editions only. Note that not all CSS widgets (e.g. tables) obey to it, yet. The preference has been removed in Gecko 51 and this property cannot be disabled since this version.
[2] The implementation in Internet Explorer differs from the specification. See the related article in the Internet Explorer Dev Center.
[3] Bidirectional and rtl scripts are supported in vertical modes only since Gecko 42.
See also
- SVG
writing-mode
attribute direction
unicode-bidi
text-orientation
text-combine-upright