-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
300 lines (249 loc) · 8.15 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
---
title: writing-mode
slug: Web/CSS/writing-mode
page-type: css-property
browser-compat: css.properties.writing-mode
---
{{CSSRef}}
The **`writing-mode`** [CSS](/en-US/docs/Web/CSS) property sets whether lines of text are laid out horizontally or vertically, as well as the direction in which blocks progress. When set for an entire document, it should be set on the root element (`html` element for HTML documents).
{{EmbedInteractiveExample("pages/css/writing-mode.html")}}
This 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, it also determines the ordering of block-level content.
## Syntax
```css
/* Keyword values */
writing-mode: horizontal-tb;
writing-mode: vertical-rl;
writing-mode: vertical-lr;
/* Global values */
writing-mode: inherit;
writing-mode: initial;
writing-mode: revert;
writing-mode: revert-layer;
writing-mode: unset;
```
The `writing-mode` property is specified as one of the values listed below. The flow direction in horizontal scripts is also affected by the [directionality of that script](https://www.w3.org/International/questions/qa-scripts.en), either left-to-right (`ltr`, like English and most other languages) or right-to-left (`rtl`, like Hebrew or Arabic).
### Values
- `horizontal-tb`
- : For `ltr` scripts, content flows horizontally from left to right. For `rtl` scripts, content flows horizontally from right to left. The next horizontal line is positioned below the previous line.
- `vertical-rl`
- : For `ltr` scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the left of the previous line. For `rtl` scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the right of the previous line.
- `vertical-lr`
- : For `ltr` scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the right of the previous line. For `rtl` scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the left of the previous line.
- `sideways-rl`
- : For `ltr` scripts, content flows vertically from top to bottom. For `rtl` scripts, content flows vertically from bottom to top. All the glyphs, even those in vertical scripts, are set sideways toward the right.
- `sideways-lr`
- : For `ltr` scripts, content flows vertically from bottom to top. For `rtl` scripts, content flows vertically from top to bottom. 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` instead.
- `lr-tb`
- : Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead.
- `rl`
- : Deprecated except for SVG1 documents. For CSS, use `horizontal-tb` instead.
- `tb`
- : Deprecated except for SVG1 documents. For CSS, use `vertical-lr` instead.
- `tb-lr`
- : Deprecated except for SVG1 documents. For CSS, use `vertical-lr` instead.
- `tb-rl`
- : Deprecated except for SVG1 documents. For CSS, use `vertical-rl` instead.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{CSSSyntax}}
## Examples
### Using multiple writing modes
This example demonstrates all of the writing modes, showing each with text in various languages.
#### HTML
The HTML is a {{HTMLElement("table")}} with each writing mode in a row with a column showing text in various scripts using that writing mode.
```html
<table>
<caption>
Using multiple writing modes
</caption>
<tr>
<th>Value</th>
<th>Vertical script</th>
<th>Horizontal (LTR) script</th>
<th>Horizontal (RTL) script</th>
<th>Mixed script</th>
</tr>
<tr class="text1">
<th>horizontal-tb</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="text2">
<th>vertical-lr</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="text3">
<th>vertical-rl</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="experimental text4">
<th>sideways-lr</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
<tr class="experimental text5">
<th>sideways-rl</th>
<td>我家没有电脑。</td>
<td>Example text</td>
<td>מלל ארוך לדוגמא</td>
<td>1994年に至っては</td>
</tr>
</table>
<p class="notice">
Your browser does not support the <code>sideways-lr</code> or
<code>sideways-rl</code> values.
</p>
```
#### CSS
```css hidden
table {
border-collapse: collapse;
}
td,
th {
border: 2px black solid;
padding: 4px;
}
th {
background-color: lightgray;
}
.experimental {
display: none;
}
.notice {
display: table-row;
font-weight: bold;
text-align: center;
}
@supports (writing-mode: sideways-lr) {
.experimental {
display: table-row;
}
.notice {
display: none;
}
}
```
The CSS that adjusts the directionality of the content looks like this:
```css
.text1 td {
writing-mode: horizontal-tb;
}
.text2 td {
writing-mode: vertical-lr;
}
.text3 td {
writing-mode: vertical-rl;
}
.text4 td {
writing-mode: sideways-lr;
}
.text5 td {
writing-mode: sideways-rl;
}
```
#### Result
{{EmbedLiveSample("Using_multiple_writing_modes", 400, 700)}}
### Using writing-mode with transforms
If your browser doesn't support `sideways-lr`, a workaround is to use {{cssxref("transform")}} to achieve a similar effect depending on the script direction.
The effect of `vertical-rl` is the same as with `sideways-lr`, so no transformation is required for left-to-right scripts.
In some cases, rotating the text 180 degrees is sufficient to achieve the effect of `sideways-lr`, but font glyphs may not be designed to be rotated, so this may produce unexpected positioning or rendering.
#### HTML
```html
<table>
<caption>
Using writing-mode with transforms
</caption>
<thead>
<tr>
<th>Vertical LR</th>
<th>Vertical LR with transform</th>
<th>Sideways LR</th>
<th>Only rotate</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="vertical-lr">我家没有电脑。</span>
<span class="vertical-lr">Example text</span>
</td>
<td>
<span class="vertical-lr rotated">我家没有电脑。</span>
<span class="vertical-lr rotated">Example text</span>
</td>
<td>
<span class="sideways-lr">我家没有电脑。</span>
<span class="sideways-lr">Example text</span>
</td>
<td>
<span class="only-rotate">我家没有电脑。</span>
<span class="only-rotate">Example text</span>
</td>
</tr>
</tbody>
</table>
```
#### CSS
```css
.vertical-lr {
writing-mode: vertical-lr;
}
.rotated {
transform: rotate(180deg);
}
.sideways-lr {
writing-mode: sideways-lr;
}
.only-rotate {
inline-size: fit-content;
transform: rotate(-90deg);
}
```
```css hidden
table {
border-collapse: collapse;
}
td,
th {
border: 2px black solid;
padding: 4px;
}
th {
background-color: lightgray;
}
span {
display: inline-block;
width: 1.5em;
text-align: center;
}
```
#### Result
{{EmbedLiveSample("Using_writing-mode_with_transforms", 400, 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- SVG [`writing-mode`](/en-US/docs/Web/SVG/Attribute/writing-mode) attribute
- {{Cssxref("direction")}}
- {{Cssxref("unicode-bidi")}}
- {{Cssxref("text-orientation")}}
- {{Cssxref("text-combine-upright")}}
- [CSS logical properties](/en-US/docs/Web/CSS/CSS_logical_properties_and_values)
- [Styling vertical text (Chinese, Japanese, Korean and Mongolian)](https://www.w3.org/International/articles/vertical-text/) on W3.org (2022)
- [CSS writing modes](/en-US/docs/Web/CSS/CSS_writing_modes) module
- [Creating vertical form controls](/en-US/docs/Web/CSS/CSS_writing_modes/Vertical_controls)