-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.html
More file actions
2189 lines (1682 loc) · 84.4 KB
/
Overview.html
File metadata and controls
2189 lines (1682 loc) · 84.4 KB
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang=en>
<head><meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Writing Modes Module Level 3</title>
<link href="../default.css" rel=stylesheet type="text/css">
<style type="text/css">
object { vertical-align: middle; }
.sidebar { float: right; background: #eee; border: solid gray; margin: 1em; }
.landscape { height: 10em; }
.portrait { width: 10em; }
.sidebar .figure { margin: 1em; }
.sidebar object { margin: 0 auto; display: block; }
.figurepair { display: table; margin: 1em auto; }
.figurepair .figure { display: table-cell; }
h2, .example { clear: both; }
img, object { max-width: 100%; }
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Writing Modes Module Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 28 December
2010</h2>
<dl>
<dt>This version:
<dd><a
href="http://www.w3.org/TR/2010/ED-css3-writing-modes-20101228">http://www.w3.org/TR/2010/ED-css3-writing-modes-20101228</a>
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-writing-modes/">http://www.w3.org/TR/css3-writing-modes/</a>
<dt>Previous version:
<dd>-
<dt>Editors:
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a>
(Invited Expert)
<dd><a href="mailto:kojiishi@gluesoft.co.jp">Koji Ishii</a> (<a
href="http://www.antenna.co.jp/">Antenna House</a>)
href="http://www.antenna.co.jp/">Antenna House</a>)
<dt>Previous Editors:
<dd><a href="mailto:paulnel@microsoft.com">Paul Nelson</a> (<a
href="http://www.microsoft.com/">Microsoft</a>)
<dd><a href="mailto:michelsu@microsoft.com">Michel Suignard</a> (<a
href="http://www.microsoft.com/">Microsoft</a>)
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2010 <a
href="http://www.w3.org/"><acronym title="World Wide Web
Consortium">W3C</acronym></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute
of Technology">MIT</acronym></a>, <a href="http://www.ercim.eu/"><acronym
title="European Research Consortium for Informatics and
Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p>This module specifies the text layout model in CSS and the properties
that control it. It covers bidirectional and vertical text.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-writing-modes%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-writing-modes” in the subject, preferably like this:
“[<!---->css3-writing-modes<!---->] <em>…summary of
comment…</em>”
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<p>This is the first public working draft of the CSS Writing Modes module
as a separate specification. The functionality was split off from the <a
href="/TR/2003/CR-css3-text-20030514/">CSS Text module of 14 May 2003.</a>
<h2 class="no-num no-toc" id=Contents>Table of Contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span>Introduction</a>
<ul class=toc>
<li><a href="#vertical-intro"><span class=secno>1.1. </span>Introduction
to Vertical Text</a>
</ul>
<li><a href="#text-flow"><span class=secno>2. </span>Writing Modes and
Terminology</a>
<li><a href="#text-direction"><span class=secno>3. </span>Inline Direction
and Bidirectionality</a>
<ul class=toc>
<li><a href="#direction"><span class=secno>3.1. </span>Specifying
Directionality: the ‘<code class=property>direction</code>’
property</a>
<li><a href="#unicode-bidi"><span class=secno>3.2. </span>Embeddings and
Overrides: the ‘<code class=property>unicode-bidi</code>’
property</a>
<li><a href="#bidi-example"><span class=secno>3.3. </span>Example of
Bidirectional Text</a>
<li><a href="#bidi-box-model"><span class=secno>3.4. </span>Box model
for inline elements in bidirectional context</a>
8096
;
</ul>
<li><a href="#writing-mode"><span class=secno>4. </span>Block Flow
Direction: the ‘<code class=property>writing-mode</code>’
property</a>
<ul class=toc>
<li><a href="#vertical-layout"><span class=secno>4.1. </span>Box Layout
in Vertical Writing Modes</a>
</ul>
<li><a href="#line-orientation"><span class=secno>5. </span>Line
Orientation</a>
<ul class=toc>
<li><a href="#text-orientation"><span class=secno>5.1. </span>Orienting
Text: the ‘<code class=property>text-orientation</code>’
property</a>
</ul>
<li><a href="#abstract-layout"><span class=secno>6. </span>Abstract Box
Layout</a>
<ul class=toc>
<li><a href="#dimensions"><span class=secno>6.1. </span>Logical vs
Physical Dimensions</a>
<ul class=toc>
<li><a href="#orthogonal-flows"><span class=secno>6.1.1.
</span>Orthogonal Flows</a>
</ul>
<li><a href="#directions"><span class=secno>6.2. </span>Logical vs
Physical Directions</a>
<ul class=toc>
<li><a href="#block-directions"><span class=secno>6.2.1.
</span>Logical Directions</a>
<li><a href="#line-directions"><span class=secno>6.2.2.
</span>Line-Relative Directions</a>
<li><a href="#logical-to-physical"><span class=secno>6.2.3.
</span>Abstract-to-Physical Mappings</a>
<li><a href="#physical-only"><span class=secno>6.2.4. </span>Purely
Physical Properties</a>
<li><a href="#caption-side"><span class=secno>6.2.5. </span>The
‘<code class=property>caption-side</code>’ property</a>
</ul>
</ul>
<li><a href="#text-combine"><span class=secno>7. </span>Glyph Composition:
the ‘<code class=property>text-combine</code>’ property</a>
<li class=no-num><a href="#acknowledgements">Acknowledgements</a>
<li class=no-num><a href="#bidi-html">Appendix B: Bidi Rules for HTML</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
</ul>
<!--end-toc-->
<h2 id=intro><span class=secno>1. </span>Introduction</h2>
<p><em>This section is non-normative.</em>
<p>This module defines support for various international writing
directions, such as left-to-right (e.g., Latin scripts), right-to-left
(e.g., Hebrew or Arabic), bidirectional (e.g., mixing Latin with Arabic)
and vertical (e.g., Asian scripts).
<p>Inherently bottom-to-top scripts are not handled in this version. See <a
href="#UTN22" rel=biblioentry>[UTN22]<!--{{UTN22}}--></a> for an
explanation of relevant issues.
<h3 id=vertical-intro><span class=secno>1.1. </span>Introduction to
Vertical Text</h3>
<p>In addition to extensions to CSS2.1's support for bidirectional text,
this module introduces the rules and properties needed to support vertical
text layout in CSS.
<p>Unlike languages that use the Latin script which are primarily laid out
horizontally, Asian languages such as Chinese and Japanese can be laid
vertically. The Japanese example below shows the same text laid out
horizontally and vertically. In the horizontal case, text is read from
left to right, top to bottom. For the vertical case, the text is read top
to bottom, right to left. Indentation from the left edge in the
left-to-right horizontal case translates to indentation from the top edge
in the top-to-bottom vertical case.
<div class=figure>
<p><img alt="A comparison of horizontal and vertical Japanese shows that
although the lines rotate, the characters remain upright. Some glyphs,
however change: a period mark shifts from the bottom left of its glyph
box to the top right. Running headers, however, may remain laid out
horizontally across the top of the page." src=vert-horiz-comparison.png></p>
<p class=caption>Comparison of vertical and horizontal Japanese</p>
</div>
<p class=note>For Chinese and Japanese lines are ordered either right to
left, while for Mongolian and Manchu left to right.
<p>The change from horizontal to vertical writing can affect not just the
layout, but also the typesetting. For example, the position of a
punctuation mark within its spacing box can change from the horizontal to
the vertical case, and in some cases alternate glyphs are used.
<p>Vertical text that includes Latin script text or text from other scripts
normally displayed horizontally can display that text in a number of ways.
For example, Latin words can be rotated sideways, or each letter can be
oriented upright.
<div class=figure>
<p><img alt="Latin initialisms like GNP can appear either rotated 90°
clockwise, or with the letters stacked upright."
sr
188A
c=vert-latin-layouts.png></p>
<p class=caption>Examples of Latin in vertical Japanese</p>
</div>
<p>In some special cases such as two-digit numbers in dates, text is fit
compactly into a single vertical character box:
<div class=figure>
<p><img alt="Diagram of showing the two-digit numbers of a date set
halfwidth side-by-side in a vertical column of text" class=example
src=tate-chu-yoko.png>
<p>Example of horizontal-in-vertical two-digit numbers</p>
</div>
<!--
<div class="figure">
<p><img src="vert-number-layouts.png"
alt="An exerpt from MacFan shows several possible vertical layouts
for numbers: the two-digit month and day are written as
horizontal-in-vertical blocks; the years are written with
each character upright; except in the English phrase
“for Mac 2011”, where the date is rotated to
match the rotated Latin."/></p>
<p class="caption">MacFan, December 2010, p.49</p>
</div>
-->
<p>Layouts often involve a mixture of vertical and horizontal elements:
<div class=figure>
<p><img alt="Magazines often mix horizontal and vertical layout; for
example, using one orientation for the main article text and a different
one for sidebar or illustrative content." src=vert-horiz-combination.png></p>
<p class=caption>Mixture of vertical and horizontal elements</p>
</div>
<p>Vertical text layouts also need to handle bidirectional text layout;
clockwise-rotated Arabic, for example, is laid out bottom-to-top.
<h2 id=text-flow><span class=secno>2. </span>Writing Modes and Terminology</h2>
<p>A <dfn id=writing-mode0>writing mode</dfn> in CSS is determined by the
‘<a href="#writing-mode1"><code
class=property>writing-mode</code></a>’, ‘<a
href="#direction0"><code class=property>direction</code></a>’, and
‘<a href="#text-orientation0"><code
class=property>text-orientation</code></a>’ properties. It is
defined primarily in terms of its <a
href="#inline-base-direction"><i>inline base direction</i></a> and <a
href="#block-flow-direction"><i>block flow direction</i></a>:
<div class=sidebar>
<div class="figure right"> <object class=landscape
data="diagrams/text-flow-vectors-tb.svg" type="image/svg+xml"></object>
<p class=caption>Latin-based writing mode
</div>
<div class="figure left"> <object class=portrait
data="diagrams/text-flow-vectors-lr-reverse.svg"
type="image/svg+xml"></object>
<p class=caption>Mongolian-based writing mode
</div>
<div class="figure right"> <object class=landscape
data="diagrams/text-flow-vectors-tb.svg" type="image/svg+xml"></object>
<object class=portrait data="diagrams/text-flow-vectors-rl.svg"
type="image/svg+xml"></object>
<p class=caption>Han-based writing mode
</div>
</div>
<p>The <dfn id=inline-base-direction>inline base direction</dfn> is the
primary direction in which content is ordered on a line and defines on
which sides the "start" and "end" of a line are. The ‘<a
href="#direction0"><code class=property>direction</code></a>’
property specifies the inline base direction of an element and, together
with the ‘<a href="#unicode-bidi0"><code
class=property>unicode-bidi</code></a>’ property and the inherent
directionality of any text content, determines the ordering of
inline-level content within a line.
<p>The <dfn id=block-flow-direction>block flow direction</dfn> is the
direction in which block-level boxes stack and the direction in which line
boxes stack within a block container. The ‘<a
href="#writing-mode1"><code class=property>writing-mode</code></a>’
property determines the block flow direction.
<p>A <dfn id=horizontal-writing-mode>horizontal writing mode</dfn> is one
with horizontal lines of text, i.e. a downward or upward block flow. A
<dfn id=vertical-writing-mode>vertical writing mode</dfn> is one with
vertical lines of text, i.e. a leftward or rightward block flow.
<p class=note>These terms should not be confused with <dfn
id=vertical-block-flow>vertical block flow</dfn> (which is a downward or
upward block flow) and <dfn id=horizontal-block-flow>horizontal block
flow</dfn> (which is leftward or rightward block flow). To avoid
confusion, the CSS specifications avoid this latter set of terms.
<p>Writing systems typically have one or two native writing modes. Some
examples are:
<ul>
<li>Latin-based systems are typically written using a left-to-right inline
direction with a downward (top-to-bottom) block flow direction.
<li>Arabic-based systems are typically written using a right-to-left
inline direction with a downward (top-to-bottom) block flow direction.
<li>Mongolian-based systems are typically written using a top-to-bottom
inline direction with a rightward (left-to-right) block flow direction.
<li>Han-based systems are commonly written using a left-to-right inline
direction with a downward (top-to-bottom) block flow direction,
<strong>or</strong> a top-to-bottom inline direction with a leftward
(right-to-left) block flow direction. Many magazines and newspapers will
mix these two writing modes on the same page.
</ul>
<p>Some additional characteristics, the line orientation and glyph
orientation, are primarily used to handle scripts placed in a non-native
writing mode. The <dfn id=line-orientation0>line orientation</dfn>
determines which side of the line is the "top" and thus which sides are
<dfn id=under>under</dfn> or <dfn id=over>over</dfn> the line. This
determines the interpretation of alignment in the transverse dimension of
the line. It also determines the default <dfn id=glyph-orientation>glyph
orientation</dfn> for scripts in a non-native orientation. These
characteristics are controlled by the ‘<a
href="#text-orientation0"><code
class=property>text-orientation</code></a>’ property.
<div class=example>
<p>In the following example, two blocks elements (1 and 3) separated by an
image (2) are presented in various flow writing modes.</p>
<p>Here is a diagram of horizontal writing mode (<code>writing-mode:
horizontal-tb</code>):</p>
<p><img alt="Diagram of horizontal layout: blocks 1, 2, and 3 are stacked
top-to-bottom" height=300 src=horizontal.png width=219></p>
<p>Here is a diagram for the right-to-left vertical writing mode commonly
used in East Asia (<code>writing-mode: vertical-rl</code>):</p>
<p><img alt="Diagram of a right-to-left vertical layout: blocks 1, 2, and
3 are arranged side by side from right to left" height=191
src=vertical-rl.png width=297></p>
<p>And finally, here is a diagram for the left-to-right vertical writing
mode used for Manchu and Mongolian (<code>writing-mode: lr</code>):</p>
<p><img alt="Diagram of left-to-right vertical layout: blocks 1, 2, and 3
are arranged side by side from left to right" height=191
src=vertical-lr.png width=300></p>
</div>
<p class=note>See Unicode Technical Note #22 <a href="#UTN22"
rel=biblioentry>[UTN22]<!--{{UTN22}}--></a> (<a
href="http://fantasai.inkedblade.net/style/discuss/vertical-text/paper">HTML
version</a>) for a more in-depth introduction to writing modes and
vertical text.
<h2 id=text-direction><span class=secno>3. </span>Inline Direction and
Bidirectionality</h2>
<p>While the characters in most scripts are written from left to right,
certain scripts are written from right to left. In some documents, in
particular those written with the Arabic or Hebrew script, and in some
mixed-language contexts, text in a single (visually displayed) block may
appear with mixed directionality. This phenomenon is called <span
class=index-def id=bidirectionality title="bidirectionality (bidi)"><dfn
id=bidirectionality0>bidirectionality</dfn></span>, or "bidi" for short.
<p>The Unicode standard (<a
href="http://www.unicode.org/reports/tr9/">Unicode Standard Annex #9</a>)
defines a complex algorithm for determining the proper ordering of
bidirectional text. The algorithm consists of an implicit part based on
character properties, as well as explicit controls for embeddings and
overrides. CSS relies on this algorithm to achieve proper bidirectional
rendering. The <span class=propinst-direction>‘<a
href="#direction0"><code class=property>direction</code></a>’</span>
and <span class=propinst-unicode-bidi>‘<a
href="#unicode-bidi0"><code
class=property>unicode-bidi</code></a>’</span> properties allow
authors to specify how the elements and attributes of a document language
map to this algorithm.
<p>User agents that support bidirectional text must apply the Unicode
bidirectional algorithm to every sequence of inline boxes uninterrupted by
a forced (<a
href="http://www.unicode.org/reports/tr9/#Bidirectional_Character_Types">bidi
class B</a>) line break or block boundary. This sequence forms the
"paragraph" unit in the bidirectional algorithm. The paragraph embedding
level is set according to the value of the ‘<a
href="#direction0"><code class=property>direction</code></a>’
property of the containing block rather than by the heuristic given in
steps P2 and P3 of the Unicode algorithm.
<p>Because the base directionality of a text depends on the structure and
semantics of the document, these properties should in most cases be used
only to map bidi information in the markup to its corresponding CSS
styles. If a document language provides markup features to control bidi,
authors and users should use those features and not specify CSS rules to
override them.
<p>The HTML 4 specification (<a href="#HTML401"
rel=biblioentry>[HTML401]<!--{{HTML401}}--></a>, section 8.2) defines
bidirectionality behavior for HTML elements. The HTML 4 specification also
contains more information on bidirectionality issues.
<p class=note>Because HTML UAs can turn off CSS styling, we advise HTML
authors to use the HTML ‘<code class=property>dir</code>’
attribute and <bdo> element to ensure correct bidirectional layout
in the absence of a style sheet.
<h3 id=direction><span class=secno>3.1. </span>Specifying Directionality:
the ‘<a href="#direction0"><code
class=property>direction</code></a>’ property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=direction0>direction</dfn>
<tr>
<th>Value:
<td>ltr | rtl
<tr>
<th>Initial:
<td>ltr
<tr>
<th>Applies to:
<td>all elements
<tr>
<th>Inherited:
<td>yes
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed value:
<td>specified value
</table>
<p>This property specifies the base directionality of text and elements on
a line, and the directionality of embeddings and overrides (see ‘<a
href="#unicode-bidi0"><code class=property>unicode-bidi</code></a>’)
for the Unicode bidirectional algorithm. In addition, it affects the
ordering of <a href="http://www.w3.org/TR/CSS21/tables.html">table</a>
column layout, the direction of horizontal <a
href="http://www.w3.org/TR/CSS21/visufx.html#overflow">overflow</a>, and
the default alignment of text within a line, and other things that depend
on the base inline base direction.
<p>Values for this property have the following meanings:
<dl>
<dt><strong>ltr</strong>
<dd>Left-to-right directionality.
<dt><strong>rtl</strong>
<dd>Right-to-left directionality.
</dl>
<p class=note>The ‘<a href="#direction0"><code
class=property>direction</code></a>’ property has no reordering in
inline-level elements whose ‘<a href="#unicode-bidi0"><code
class=property>unicode-bidi</code></a>’ property's value is
‘<code class=css>normal</code>’.
<p>The value of the ‘<a href="#direction0"><code
class=property>direction</code></a>’ property on the root element is
also propagated to the initial containing block and, together with the
‘<a href="#writing-mode1"><code
class=property>writing-mode</code></a>’ property, determines the
document's principal writing mode. (See <a
href="#principal-writing-mode">below</a>.)
<p class=note>Note that the ‘<a href="#direction0"><code
class=property>direction</code></a>’ property of the HTML BODY
element is <em>not</em> propagated to the viewport. That special behavior
only applies to the background and overflow properties.
<p class=note>The ‘<a href="#direction0"><code
class=property>direction</code></a>’ property, when specified for
table column elements, is not inherited by cells in the column since
columns are not the ancestors of the cells in the document tree. Thus, CSS
cannot easily capture the "dir" attribute inheritance rules described in
<a href="#HTML401" rel=biblioentry>[HTML401]<!--{{HTML401}}--></a>,
section 11.3.2.1.
<h3 id=unicode-bidi><span class=secno>3.2. </span>Embeddings and Overrides:
the ‘<a href="#unicode-bidi0"><code
class=property>unicode-bidi</code></a>’ property</h3>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=unicode-bidi0>unicode-bidi</dfn>
<tr>
<th>Value:
<td>normal | [ [ embed | isolate ] || [ plaintext | bidi-override ] ]
<tr>
<th>Initial:
<td>normal
<tr>
<th>Applies to:
<td>all elements, but see prose
<tr>
<th>Inherited:
<td>no
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed value:
<td>specified value
</table>
<p>Values for this property have the following meanings:
<dl>
<dt><strong>normal</strong>
<dd>The element does not open an additional level of embedding with
respect to the bidirectional algorithm. For inline-level elements,
implicit reordering works across element boundaries.
<dt><strong>embed</strong>
<dd>If the element is inline-level, this value opens an additional level
of embedding with respect to the bidirectional algorithm. The direction
of this embedding level is given by the ‘<a
href="#direction0"><code class=property>direction</code></a>’
property. Inside the element, reordering is done implicitly. This
corresponds to adding a LRE (U+202A; for ‘<code
class=css>direction: ltr</code>’) or RLE (U+202B; for ‘<code
class=css>direction: rtl</code>’) at the start of the element and a
PDF (U+202C) at the end of the element.
<dt><strong>bidi-override</strong>
<dd>For inline-level elements this creates an override. For block-level,
table-cell, table-caption, or inline-block elements this creates an
override for inline-level descendants not within another block-level,
table-cell, table-caption, or inline-block element. This means that
inside the element, reordering is strictly in sequence according to the
<span class=propinst-direction>‘<a href="#direction0"><code
class=property>direction</code></a>’</span> property; the implicit
part of the bidirectional algorithm is ignored. This corresponds to
adding a LRO (U+202D; for ‘<code class=css>direction:
ltr</code>’) or RLO (U+202E; for ‘<code class=css>direction:
rtl</code>’) at the start of the element and a PDF (U+202C) at the
end of the element.
<dt><strong>isolate</strong>
<dd>For the purposes of the Unicode bidirectional algorithm, the contents
of the element are considered to be inside a separate, independent
paragraph, and for the purpose of bidi resolution in its containing bidi
paragraph (if any), the element itself is treated as if it were an Object
Replacement Character (U+FFFC). (If the element is broken across multiple
lines, then each box of the element is treated as an Object Replacement
Character.)
<dt><strong>plaintext</strong>
<dd>
<p>For the purposes of the Unicode bidirectional algorithm, the base
directionality of each "paragraph" for which the element is the
containing block element is determined not by the element's computed
‘<a href="#direction0"><code
class=property>direction</code></a>’ as usual, but by following
rules P1, P2, and P3 of the Unicode bidirectional algorithm. However, if
no direction-determining character is found in step P2, then the value
of the ‘<a href="#direction0"><code
class=property>direction</code></a>’ property is used instead.
Note this value has no effect on inline elements.
</dl>
<p>The final order of characters in each block-level element is the same as
if the bidi control codes had been added as described above, markup had
been stripped, and the resulting character sequence had been passed to an
implementation of the Unicode bidirectional algorithm for plain text that
produced the same line-breaks as the styled text. In this process,
non-textual entities such as images are treated as neutral characters,
unless their <span class=propinst-unicode-bidi>‘<a
href="#unicode-bidi0"><code
class=property>unicode-bidi</code></a>’</span> property has a value
other than ‘<code class=property>normal</code>’, in which case
they are treated as strong characters in the <span
class=propinst-direction>‘<a href="#direction0"><code
class=property>direction</code></a>’</span> specified for the
element.
<p>Please note that in order to be able to flow inline boxes in a uniform
direction (either entirely left-to-right or entirely right-to-left), more
inline boxes (including anonymous inline boxes) may have to be created,
and some inline boxes may have to be split up and reordered before
flowing.
<p>Because the Unicode algorithm has a limit of <em title="According to
unicode 3.0, chapter 3, section 12, definition BD2. Specifically, page 58
here: http://www.unicode.org/unicode/uni2book/ch03.pdf"> 61 levels</em> of
embedding, care should be taken not to use <span
class=propinst-unicode-bidi>‘<a href="#unicode-bidi0"><code
class=property>unicode-bidi</code></a>’</span> with a value other
than ‘<code class=property>normal</code>’ unless appropriate.
In particular, a value of ‘<code
class=property>inherit</code>’ should be used with extreme caution.
However, for elements that are, in general, intended to be displayed as
blocks, a setting of ‘<code class=css>unicode-bidi:
isolate</code>’ is preferred to keep the element together in case
display is changed to inline (see example below).
<p>The following example shows an XML document with bidirectional text. It
illustrates an important design principle: document language designers
should take bidi into account both in the language proper (elements and
attributes) and in any accompanying style sheets. The style sheets should
be designed so that bidi rules are separate from other style rules, and
such rules should not be overridden by other style sheets so that the
document language's bidi behavior is preserved.
<h3 id=bidi-example><span class=secno>3.3. </span>Example of Bidirectional
Text</h3>
<div class=example>
<p>In this example, lowercase letters stand for inherently left-to-right
characters and uppercase letters represent inherently right-to-left
characters. The text stream is shown in logical backing store order.</p>
<pre class=xml-example><code class=xml>
<HEBREW>
<PAR>HEBREW1 HEBREW2 english3 HEBREW4 HEBREW5</PAR>
<PAR>HEBREW6 <EMPH>HEBREW7</EMPH> HEBREW8</PAR>
</HEBREW>
<ENGLISH>
<PAR>english9 english10 english11 HEBREW12 HEBREW13</PAR>
<PAR>english14 english15 english16</PAR>
<PAR>english17 <HE-QUO>HEBREW18 english19 HEBREW20</HE-QUO></PAR>
</ENGLISH>
</code></pre>
<p>Since this is arbitrary XML, the style sheet is responsible for setting
the writing direction. This is the style sheet:</p>
<pre>
/* Rules for bidi */
HEBREW, HE-QUO {direction: rtl; unicode-bidi: embed;}
ENGLISH {direction: ltr; unicode-bidi: embed;}
/* Rules for presentation */
HEBREW, ENGLISH, PAR {display: block;}
EMPH {font-weight: bold;}
</pre>
<p>The HEBREW element is a block with a right-to-left base direction, the
ENGLISH element is a block with a left-to-right base direction. The PARs
are blocks that inherit the base direction from their parents. Thus, the
first two PARs are read starting at the top right, the final three are
read starting at the top left. Please note that HEBREW and ENGLISH are
chosen as element names for explicitness only; in general, element names
should convey structure without reference to language.</p>
<p>The EMPH element is inline-level, and since its value for <span
class=propinst-unicode-bidi>‘<a href="#unicode-bidi0"><code
class=property>unicode-bidi</code></a>’</span> is ‘<code
class=property>normal</code>’ (the initial value), it has no effect
on the ordering of the text. The HE-QUO element, on the other hand,
creates an embedding.</p>
<p>The formatting of this text might look like this if the line length is
long:</p>
<pre class=ascii-art>
5WERBEH 4WERBEH english3 2WERBEH 1WERBEH
8WERBEH <b>7WERBEH</b> 6WERBEH
english9 english10 english11 13WERBEH 12WERBEH
english14 english15 english16
english17 20WERBEH english19 18WERBEH
</pre>
<p>Note that the HE-QUO embedding causes HEBREW18 to be to the right of
english19.</p>
<p>If lines have to be broken, it might be more like this:</p>
<pre class=ascii-art>
2WERBEH 1WERBEH
-EH 4WERBEH english3
5WERB
-EH <b>7WERBEH</b> 6WERBEH
8WERB
english9 english10 en-
glish11 12WERBEH
13WERBEH
english14 english15
english16
english17 18WERBEH
20WERBEH english19
</pre>
<p>Because HEBREW18 must be read before english19, it is on the line above
english19. Just breaking the long line from the earlier formatting would
not have worked. Note also that the first syllable from english19 might
have fit on the previous line, but hyphenation of left-to-right words in
a right-to-left context, and vice versa, is usually suppressed to avoid
having to display a hyphen in the middle of a line.</p>
</div>
<!-- example -->
<h3 id=bidi-box-model><span class=secno>3.4. </span>Box model for inline
elements in bidirectional context</h3>
<!-- CSS2.1 8.6 -->
<p>For each line box, UAs must take the inline boxes generated for each
element and render the margins, borders and padding in visual order (not
logical order).
<p>When the element's ‘<a href="#direction0"><code
class=property>direction</code></a>’ property is ‘<code
class=css>ltr</code>’, the left-most generated box of the first line
box in which the element appears has the left margin, left border and left
padding, and the right-most generated box of the last line box in which
the element appears has the right padding, right border and right margin.
<p>When the element's ‘<a href="#direction0"><code
class=property>direction</code></a>’ property is ‘<code
class=css>rtl</code>’, the right-most generated box of the first
line box in which the element appears has the right padding, right border
and right margin, and the left-most generated box of the last line box in
which the element appears has the left margin, left border and left
padding.
<h2 id=writing-mode><span class=secno>4. </span>Block Flow Direction: the
‘<a href="#writing-mode1"><code
class=property>writing-mode</code></a>’ property</h2>
<table class=propdef>
<tbody>
<tr>
<th>Name:
<td><dfn id=writing-mode1>writing-mode</dfn>
<tr>
<th>Value:
<td>horizontal-tb | vertical-rl | vertical-lr
<tr>
<th>Initial:
<td>horizontal-tb
<tr>
<th>Applies to:
<td>All elements except table row groups, table column groups, table
rows, and table columns
<tr>
<th>Inherited:
<td>yes
<tr>
<th>Percentages:
<td>N/A
<tr>
<th>Media:
<td>visual
<tr>
<th>Computed value:
<td>specified value
</table>
<p>This property sets the block flow direction. Possible values:
<dl>
<dt>horizontal-tb
<dd>Top-to-bottom block flow. The writing mode is horizontal.
<dt>vertical-rl
<dd>Right-to-left block flow. The writing mode is vertical.
<dt>vertical-lr
<dd>Left-to-right block flow. The writing mode is vertical.
</dl>
<p>SVG1.1 <a href="#SVG11" rel=biblioentry>[SVG11]<!--{{!SVG11}}--></a>
defines some additional values: ‘<code class=css>lr</code>’,
‘<code class=css>lr-tb</code>’, ‘<code
class=css>rl</code>’, ‘<code class=css>rl-tb</code>’,
‘<code class=css>tb</code>’, and ‘<code
class=css>tb-rl</code>’. These values are <em>deprecated</em> in any
context except SVG1 documents. Implementations that wish to support them
in the context of CSS must treat these values as follows:
<table class=data>
<thead>
<tr>
<th>SVG1
<th>CSS
<tbody>
<tr>
<td>lr
<td rowspan=3>horizontal-tb
<tr>
<td>lr-tb
<tr>
<td>rl
<tr>
<td>tb
<td rowspan=2>vertical-rl
<tr>
<td>tb-rl
</table>
<p class=note>In SVG1.1, these values set the <dfn
id=inline-progression-direction>inline progression direction</dfn>, in
other words, the direction the current text position advances each time a
glyph is added. This is a geometric process that happens <a
href="#after"><em>after</em></a> bidi reordering, and thus has no effect
on the interpretation of the ‘<a href="#direction0"><code
class=property>direction</code></a>’ property (which is independent
of ‘<a href="#writing-mode1"><code
class=property>writing-mode</code></a>’). (See <a
href="http://www.w3.org/TR/SVG/text.html#RelationshipWithBiDirectionality">Relationship
with bidirectionality</a>. <a href="#SVG11"
rel=biblioentry>[SVG11]<!--{{!SVG11}}--></a>) There are varying
interpretations on whether this process causes "writing-mode: rl" to
merely shift the text string or reverse the order of all glyphs in the
text.
<p class=issue>See <a href=test-writing-mode-direction.svg>this demo</a> to
check out your implementation's interpretation! (Note that most SVG
implementations don't support the ‘<a href="#direction0"><code
class=property>direction</code></a>’ property, and thus your results
may be skewed on that account. Examine the red line of text: if the
numbers are not in reverse order, your implementation doesn't support
"direction: rtl".)
<p>The ‘<a href="#writing-mode1"><code
class=property>writing-mode</code></a>’ property determines the
direction of block flow. This determines the progression of block-level
boxes in a block formatting context; the progression of line boxes in a
block container that contains inlines; and the progression of rows in a
table. As a result it also determines which side of a box is its <dfn
id=before>before</dfn> edge (i.e. the edge that comes earlier in the
progression) and which side is its <dfn id=after>after</dfn> edge (i.e.
the edge that comes later in the progression).