8000 csswg-drafts/css-writing-modes/Overview.bs at d44d66ee608c3f61b4c191f2bf8584267973ba51 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
executable file
·
2647 lines (2288 loc) · 120 KB

File metadata and controls

executable file
·
2647 lines (2288 loc) · 120 KB
<h1>CSS Writing Modes Level 3</h1>
<pre class='metadata'>
Shortname: css-writing-modes
Level: 3
Status: ED
Group: csswg
ED: http://dev.w3.org/csswg/css-writing-modes-3/
TR: http://www.w3.org/TR/css-writing-modes-3/
Previous Version: http://www.w3.org/TR/2014/CR-css-writing-modes-3-20140320/
!Issue Tracking: <a href="http://www.w3.org/Style/CSS/Tracker/products/30">http://www.w3.org/Style/CSS/Tracker/products/30</a>
Editor: fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
Editor: Koji Ishii, Invited Expert, kojiishi@gluesoft.co.jp
Former Editor: Shinyu Murakami, <a href="http://www.antenna.co.jp/">Antenna House</a>, murakami@antenna.co.jp
Former Editor: Paul Nelson, <a href="http://www.microsoft.com/">Microsoft</a>, paulnel@microsoft.com
Former Editor: Michel Suignard, <a href="http://www.microsoft.com/">Microsoft</a>, michelsu@microsoft.com
Abstract: CSS Writing Modes Level 3 defines CSS support for various international writing modes, such as left-to-right (e.g. Latin or Indic), right-to-left (e.g. Hebrew or Arabic), bidirectional (e.g. mixed Latin and Arabic) and vertical (e.g. Asian scripts).
At Risk: The ''use-glyph-orientation'' of 'text-orientation'
At Risk: The ''digits'' value of 'text-combine-upright'.
At Risk: The look-ahead/look-behind sequencing rules for 'text-combine-upright'.
Ignored Terms: glyph orientation, *-left, *-right, *-top, *-bottom, block containers, text-combine-mode
Link Defaults: css21 (property) display/min-height/max-height/min-width/max-width/clip, css-text-3 (property) letter-spacing, css-text-decor-3 (property) text-decoration, svg2 (property) glyph-orientation-vertical/glyph-orientation-horizontal
</pre>
<style>
object { vertical-align: middle; }
.sidebar { float: right; background: #eee; border: solid gray; margin: 1em; }
.sidebar .figure { margin: 1em; }
.sidebar object { margin: 0 auto; display: block; }
.figurepair { display: table; margin: 1em auto; }
.figurepair .figure { display: table-cell; padding-left: .5em; padding-right: .5em; }
h2, .example { clear: both; }
.figure img,
.figure object,
.example img,
dd img { max-width: 100%; display: block; margin: 1em auto; }
div.figure table {
margin:auto;
}
.ascii-art {
display: table;
margin: 1em auto;
}
</style>
<h2 id="text-flow">
Introduction to Writing Modes</h2>
<p>CSS Writing Modes Level 3 defines CSS features to support for various international
writing modes, such as left-to-right (e.g. Latin or Indic), right-to-left
(e.g. Hebrew or Arabic), bidirectional (e.g. mixed Latin and Arabic) and
vertical (e.g. Asian scripts).</p>
<p>A <dfn export>writing mode</dfn> in CSS is determined by the 'writing-mode',
'direction', and 'text-orientation' properties. It is defined primarily
in terms of its <i>inline base direction</i> and <i>block flow direction</i>:
<div class="sidebar">
<div class="figure right">
<a href="diagrams/text-flow-vectors-tb.svg">
<img src="diagrams/text-flow-vectors-tb.png" class="landscape"
alt="Latin-based writing mode"></a>
<p class="caption">Latin-based writing mode
</div>
<div class="figure left">
<a href="diagrams/text-flow-vectors-lr-reverse.svg">
<img src="diagrams/text-flow-vectors-lr-reverse.png" class="landscape"
alt="Mongolian-based writing mode"></a>
<p class="caption">Mongolian-based writing mode
</div>
<div class="figure right">
<a href="diagrams/text-flow-vectors-tb.svg">
<img src="diagrams/text-flow-vectors-tb.png" class="landscape"
alt="Han-based writing mode"></a>
<a href="diagrams/text-flow-vectors-rl.svg">
<img src="diagrams/text-flow-vectors-rl.png" class="landscape"
alt="Han-based writing mode"></a>
<p class="caption">Han-based writing mode
</div>
</div>
<p>The <dfn export>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 'direction' property specifies the
inline base direction of a box and, together with the 'unicode-bidi'
property and the inherent directionality of any text content, determines
the ordering of inline-level content within a line.
<p>The <dfn export>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 'writing-mode' property determines the
block flow direction.</p>
<p>A <dfn export>horizontal writing mode</dfn> is one with horizontal lines of
text, i.e. a downward or upward block flow.
A <dfn export>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>vertical block flow</dfn> (which is a downward or
upward block flow) and <dfn>horizontal block flow</dfn> (which is
leftward or rightward block flow). To avoid confusion, CSS
specifications avoid this latter set of terms.</p>
<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>The 'text-orientation' component of the writing mode determines the
<i>line orientation</i>, and controls
details of text layout such as the <i>glyph orientation</i>.
<p class="note">See Unicode Technical Note #22 [[UTN22]]
(<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.
<h3 id="placement">
Module Interactions</h3>
<p>This module replaces and extends the 'unicode-bidi' and 'direction'
features defined in [[!CSS21]] sections 8.6 and 9.10.
<h3 id="values">
Values</h3>
<p>This specification follows the
<a href="http://www.w3.org/TR/CSS21/about.html#property-defs">CSS property
definition conventions</a> from [[!CSS21]]. Value types not defined in
this specification are defined in CSS Level 2 Revision 1 [[!CSS21]].
Other CSS modules may expand the definitions of these value types: for
example [[CSS3COLOR]], when combined with this module, expands the
definition of the &lt;color&gt; value type as used in this specification.</p>
<p>In addition to the property-specific values listed in their definitions,
all properties defined in this specification also accept the
<a href="http://www.w3.org/TR/CSS21/cascade.html#value-def-inherit">inherit</a>
keyword as their property value. For readability it has not been repeated
explicitly.
<a id="bidi" title=''></a>
<h2 id="text-direction">
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
<dfn export>bidirectionality</dfn>, or "bidi" for short.</p>
<div class="figure">
<p><img src="diagrams/bidi.png"
alt="An example of bidirectional text is a Latin name in an Arabic
sentence. The sentence overall is typeset right-to-left, but
the letters in the Latin word in the middle are typeset
left-to-right.">
<p class="caption">Bidirectionality</p>
</div>
<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.
<p>User agents that support bidirectional text must apply the Unicode
bidirectional algorithm to every sequence of inline-level boxes uninterrupted
by any block boundary or
&ldquo;<a href="http://www.unicode.org/reports/tr9/#Bidirectional_Character_Types">bidi type B</a>&rdquo;
<dfn export>forced paragraph break</dfn>.
This sequence forms the <dfn export title="bidi paragraph">paragraph</dfn> unit
in the bidirectional algorithm.
<p>Two CSS properties, 'direction' and 'unicode-bidi',
provide explicit embedding, isolation, and override controls in the CSS layer.
Because the base directionality of a text depends on the structure and
semantics of the document, the 'direction' and 'unicode-bidi' properties
should in most cases be used only to map bidi information in the markup
to its corresponding CSS styles.
<strong>If a document language provides markup features to control
bidi, authors and users should use those features instead</strong> and not
specify CSS rules to override them.</p>
<p>In CSS,
the paragraph embedding level must be set
(following <a href="http://www.unicode.org/reports/tr9/#HL1">UAX9 clause HL1</a>)
according to the 'direction' property of the paragraph's containing block
rather than by the heuristic given in steps
<a href="http://www.unicode.org/reports/tr9/#P2">P2</a> and
<a href="http://www.unicode.org/reports/tr9/#P2">P3</a>
of the Unicode algorithm.
There is, however, one exception:
when the computed 'unicode-bidi' of the paragraph's containing block is ''plaintext'',
the Unicode heuristics in P2 and P3 are used as described in [[!UAX9]],
without the HL1 override.
<p>The HTML specifications ([[HTML401]], section 8.2, and [[HTML5]], section 10.3.5) define
bidirectionality behavior for HTML elements.</p>
<p class="note">Because HTML UAs can turn off CSS styling, we advise HTML
authors to use the HTML <code>dir</code> attribute and &lt;bdo&gt; element to
ensure correct bidirectional layout in the absence of a style sheet.</p>
<h3 id="direction">
Specifying Directionality: the 'direction' property</h3>
<pre class='propdef'>
Name: direction
Value: ltr | rtl
Initial: ltr
Applies to: all elements
Inherited: yes
Percentages: n/a
Media: visual
Computed value: specified value
Animatable: no
Canonical order: n/a
</pre>
<p>This property specifies the inline base direction or directionality
of any bidi paragraph, embedding, isolate, or override established by the box.
(See 'unicode-bidi'.) <!-- except plaintext -->
In addition, it informs 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 layout effects
that depend on the box's inline base direction.</p>
<p>Values for this property have the following meanings:</p>
<dl dfn-for=direction dfn-type=value>
<dt><dfn>ltr</dfn></dt>
<dd>Left-to-right directionality.</dd>
<dt><dfn>rtl</dfn></dt>
<dd>Right-to-left directionality.</dd>
</dl>
<p class="note">The 'direction' property has no effect on bidi reordering
when specified on inline boxes whose 'unicode-bidi' property's
value is ''normal'', because the box does not open an additional level
of embedding with respect to the bidirectional algorithm.</p>
<p>The value of the 'direction' property on the root element is also
propagated to the initial containing block and, together with the
'writing-mode' property, determines the document's principal writing
mode. (See <a href="#principal-writing-mode">below</a>.)
<p class="note">Note that the 'direction' 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 'direction'
property, when specified for table column boxes, 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 [[HTML401]], section 11.3.2.1.
<h3 id="unicode-bidi">
Embeddings and Overrides: the 'unicode-bidi' property</h3>
<pre class='propdef'>
Name: unicode-bidi
Value: normal | embed | isolate | bidi-override | isolate-override | plaintext
Initial: normal
Applies to: all elements, but see prose
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value
</pre>
<p>Normally (i.e. when 'unicode-bidi' is ''normal'')
an inline box is transparent to the unicode bidi algorithm;
content is ordered as if the box's boundaries were not there.
Other values of the 'unicode-bidi' property cause inline boxes
to create scopes within the algorithm,
and to override the intrinsic directionality of text.
<p>The following informative table summarizes the box-internal and
box-external effects of 'unicode-bidi':
<table class="data">
<caption>Effect of non-''normal'' values of 'unicode-bidi' on inline boxes</caption>
<colgroup span=2></colgroup>
<colgroup span=2></colgroup>
<thead>
<tr><th colspan=2 rowspan=2>
<th colspan=2 scope=rowgroup><abbr title="To surrounding contents, the box behaves as if its boundary were...">Outside</abbr>
<tr><th><abbr title="a strong character of the box's 'direction'.">strong</abbr>
<th><abbr title="a neutral character.">neutral</abbr>
</thead>
<tbody>
<tr><th rowspan=3 scope=colgroup><abbr title="Within the box, content is ordered as if...">Inside</abbr>
<th><abbr title="the box's boundaries were strong characters of the box's 'direction'.">scoped</abbr>
<td>''embed''
<td>''isolate''
<tr><th><abbr title="all text consisted of strong characters of the box's 'direction'.">override</abbr>
<td>''bidi-override''
<td>''isolate-override''
<tr><th><abbr title="the box were a standalone paragraph ordered using UAX9 heuristics.">plaintext</abbr>
<td>&mdash;
<td>''plaintext''
</tbody>
</table>
<p>Values for this property have the following (normative) meanings:</p>
<dl>
<dt><dfn value for=unicode-bidi>normal</dfn></dt>
<dd>The box does not open an additional level of embedding with
respect to the bidirectional algorithm. For inline boxes,
implicit reordering works across box boundaries.</dd>
<dt><dfn value for=unicode-bidi>embed</dfn></dt>
<dd>If the box is inline, this value creates a <dfn export>directional embedding</dfn>
by opening an additional level of embedding with respect to the bidirectional algorithm.
The direction of this embedding level is given by the 'direction'
property. Inside the box, reordering is done implicitly.
<p>Following clause <a href="http://www.unicode.org/reports/tr9/#HL3">HL3</a> [[!UAX9]],
this corresponds to inserting
a LRE (U+202A), for ''direction: ltr'',
or RLE (U+202B), for ''direction: rtl'',
at the start of the inline box
and a PDF (U+202C) at the end of the box.
<p class="note">This value has no effect on boxes that are not inline.
<dt><dfn value for=unicode-bidi>isolate</dfn></dt>
<dd>On an inline box, this <dfn export id=bidi-isolate title="bidi-isolate|bidi-isolated|bidi isolation|isolation">bidi-isolates</dfn> its contents.
This is similar to a directional embedding (and increases the embedding level accordingly)
except that each sequence of inline-level boxes
uninterrupted by any block boundary or <i>forced paragraph break</i>
is treated as an <dfn>isolated sequence</dfn>:
<ul>
<li>the content within the sequence is ordered
as if inside an independent paragraph
with the base directionality specified by the box's 'direction' property.
<li>for the purpose of bidi resolution in its containing bidi paragraph,
the sequence is treated as if it were a single Object Replacement Character (U+FFFC).
</ul>
In effect, neither is the content inside the box bidi-affected
by the content surrounding the box,
nor is the content surrounding the box bidi-affected by the
content or specified directionality of the box.
However, <i>forced paragraph breaks</i> within the box still create
a corresponding break in the containing paragraph.
<p>Following clause <a href="http://www.unicode.org/reports/tr9/#HL3">HL3</a> [[!UAX9]],
this corresponds to inserting
an LRI (U+2066), for ''direction: ltr'',
or RLI (U+2067), for ''direction: rtl'',
at the start of the inline box,
and a PDI (U+2069) at the end of the box. [[!UAX9]]
<p class="note">This value has no effect on boxes that are not inline.
<dt><dfn value for=unicode-bidi>bidi-override</dfn></dt>
<dd>This value puts the box's immediate inline content in a <dfn export>directional override</dfn>.
For an inline, this means that the box acts like a <i>directional embedding</i>
in the bidirectional algorithm,
except that reordering within it is strictly in sequence according to the
'direction' property; the implicit part of the bidirectional algorithm
is ignored.
For a block container, the override is applied
to an anonymous inline box that surrounds all of its content.
<p>Following clause <a href="http://www.unicode.org/reports/tr9/#HL3">HL3</a> [[!UAX9]],
this corresponds to inserting
an LRO (U+202D), for ''direction: ltr'',
or RLO (U+202E), for ''direction: rtl'',
at the start of the inline box
and a PDF (U+202C) at the end of the box. [[!UAX9]]
<dt><dfn value for=unicode-bidi>isolate-override</dfn></dt>
<dd>This combines the <i>isolation</i> behavior of ''isolate''
with the <i>directional override</i> behavior of ''bidi-override'':
to surrounding content, it is equivalent to ''isolate'',
but within the box content is ordered as if ''bidi-override'' were specified.
<p>Following clause <a href="http://www.unicode.org/reports/tr9/#HL3">HL3</a> [[!UAX9]],
for inline boxes this corresponds to inserting
an FSI (U+2068) followed by
an LRO (U+202D), for ''direction: ltr'',
or RLO (U+202E), for ''direction: rtl'' at the start of the box,
and a PDF (U+202C) followed by PDI (U+2069) at the end of the box. [[!UAX9]]
For other boxes, this value is exactly equivalent to ''bidi-override''.
<dt><dfn value for=unicode-bidi>plaintext</dfn></dt>
<dd><p>This value behaves as ''isolate'' except that for the purposes of
the Unicode bidirectional algorithm, the base directionality of each
of the box's <i>bidi paragraphs</i> (if a block container)
or <i>isolated sequences</i> (if an inline)
is determined by following the heuristic in rules P2 and P3
of the Unicode bidirectional algorithm
(rather than by using the 'direction' property of the box).
<p>Following cause <a href="http://www.unicode.org/reports/tr9/#HL3">HL3</a> [[!UAX9]],
for inline boxes this corresponds to inserting
an FSI (U+2068) at the start of the box,
and a PDI (U+2069) at the end of the box. [[!UAX9]]
</dl>
<p class=note>Because the 'unicode-bidi' property does not inherit,
setting ''bidi-override'' or ''plaintext'' on a block box will
not affect any descendant blocks. Therefore these values are best
used on blocks and inlines that do not contain any block-level
structures.
<p class=note>Note that 'unicode-bidi' does not affect the 'direction'
property even in the case of ''plaintext'', and thus does not affect
'direction'-dependent layout calculations.
<p>The final order of characters within each <i>bidi paragraph</i> 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.
<p>In this process, replaced elements with ''display: inline''
are treated as neutral characters,
unless their 'unicode-bidi' property is either ''embed'' or ''bidi-override'',
in which case they are treated as strong characters
in the 'direction' specified for the element.
All other atomic inline-level boxes are treated as neutral characters
always.</p>
<p>If an inline box is broken around a <i>bidi paragraph</i> boundary
(e.g. if split by a block or <i>forced paragraph break</i>),
then the <a href="http://www.unicode.org/reports/tr9/#HL3">HL3</a> bidi control codes assigned to the end of the box
are also added before the interruption
and the codes assigned to the start of the box are also added after it.
(In other words, any embedding levels, isolates, or overrides started by the box
are closed at the paragraph break and reopened on the other side of it.)
<div class="example">
<p>For example, where &lt;BR/&gt; is a <i>forced paragraph break</i>
the bidi ordering is identical between
<pre>&lt;para>...&lt;i1>&lt;i2>...&lt;BR/>...&lt;/i2>&lt;/i1>...&lt;/para></pre>
<p>and
<pre>&lt;para>...&lt;i1>&lt;i2>...&lt;/i2>&lt;i1>&lt;BR/>&lt;i1>&lt;i2>...&lt;/i2>&lt;/i1>...&lt;/para></pre>
<p>for all values of 'unicode-bidi' on inline elements &lt;i1&gt; and &lt;i2&gt;.
</div>
<p class="note">
Because the Unicode algorithm has a limit of 125 levels of embedding,
care should be taken not to use 'unicode-bidi'
with a value other than ''normal'' unless appropriate.
In particular, a value of ''inherit''
should be used with extreme caution. However, for elements that are,
in general, intended to be displayed as blocks, a setting of
''unicode-bidi: isolate'' is preferred to keep the element together
in case the 'display' is changed to ''inline''
(see example below).</p>
<h3 id="bidi-example">
Example of Bidirectional Text</h3>
<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.</p>
<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 below in logical backing store order.</p>
<pre class="xml-example">
&lt;section dir=rtl&gt;
&lt;para&gt;HEBREW1 HEBREW2 english3 HEBREW4 HEBREW5&lt;/para&gt;
&lt;para&gt;HEBREW6 &lt;emphasis&gt;HEBREW7&lt;/emphasis&gt; HEBREW8&lt;/para&gt;
&lt;/section&gt;
&lt;section dir=ltr&gt;
&lt;para&gt;english9 english10 english11 HEBREW12 HEBREW13&lt;/para&gt;
&lt;para&gt;english14 english15 english16&lt;/para&gt;
&lt;para&gt;english17 &lt;quote dir=rtl&gt;HEBREW18 english19 HEBREW20&lt;/quote&gt;&lt;/para&gt;
&lt;/section&gt;
</pre>
<p>Since this is arbitrary XML, the style sheet is responsible for
setting t 2B2 he writing direction. This is the style sheet:</p>
<pre>
/* Rules for bidi */
[dir=ltr] {direction: rtl; unicode-bidi: isolate; }
[dir=rtl] {direction: ltr; unicode-bidi: isolate; }
/* Rules for presentation */
section, para {display: block;}
emphasis {font-weight: bold;}
quote {font-style: italic;}
</pre>
<p>If the line length is long,
the formatting of this text might look like this:</p>
<pre class="ascii-art">
5WERBEH 4WERBEH english3 2WERBEH 1WERBEH
8WERBEH <b>7WERBEH</b> 6WERBEH
english9 english10 english11 13WERBEH 12WERBEH
english14 english15 english16
english17 <i title=''>20WERBEH english19 18WERBEH</i>
</pre>
<p>The first <code>&lt;section></code> element is a block with a right-to-left base direction,
the second <code>&lt;section></code> element is a block with a left-to-right base direction.
The <code>&lt;para></code>s are blocks that inherit the base direction from their parents.
Thus, the first two <code>&lt;para></code>s are read starting at the top right,
the final three are read starting at the top left.</p>
<p>The <code>&lt;emphasis></code> element is inline-level,
and since its value for 'unicode-bidi' is ''normal'' (the initial value),
it has no effect on the ordering of the text.
<p>The <code>&lt;quote></code> element, on the other hand,
creates an <i>isolated sequence</i> with the given internal directionality.
Note that this causes <samp>HEBREW18</samp> to be to the right of <samp>english19</samp>.
<p>If lines have to be broken, the same text might format 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 <i title=''>18WERBEH
<!-- -->20WERBEH english19</i>
</pre>
<p>Notice that because <samp>HEBREW18</samp> must be read before <samp>english19</samp>,
it is on the line above <samp>english19</samp>.
Just breaking the long line from the earlier formatting would not have worked.
<p>Note also that the first syllable from <samp>english19</samp>
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.
</div><!-- example -->
<h3 id="bidi-box-model">
Box model for inline boxes in bidirectional context</h3>
<p>Since bidi reordering can split apart and reorder text that is
logically contiguous, bidirectional text can cause an inline box
to be split and reordered within a line.
<p class="note">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), anonymous inline boxes may have to be created.</p>
<!-- CSS2.1 8.6 -->
<p>For each line box, UAs must take the fragments of each inline box
and render the margins, borders and padding in visual order (not logical order).
The <i>start</i>-most fragment on the first line box in which the box appears
has the <i>start</i> edge's margin, border, and padding;
and the end-most fragment on the last line box in which the box appears
has the <i>end</i> edge's margin, border, and padding.
For example, in the ''horizontal-tb'' writing mode:
<ul>
<li>When the parent's 'direction' property is ''ltr'',
the left-most box fragment on the first line box in which the box appears
has the left margin, left border and left padding,
and the right-most box fragment on the last line box in which the box appears
has the right padding, right border and right margin.
<li>When the parent's 'direction' property is ''rtl'',
the right-most fragment of the first line box in which the box appears
has the right padding, right border and right margin,
and the left-most fragment of the last line box in which the box appears
has the left margin, left border and left padding.
</ul>
<p>Analogous rules hold for vertical writing modes.</p>
<p class="note">The 'box-decoration-break' property can override this behavior
to draw box decorations on both sides of each fragment. [[!CSS3-BREAK]]
<h2 id="vertical-intro">
Introduction to Vertical Text</h2>
<p><em>This subsection is non-normative.</em></p>
<p>In addition to extensions to CSS2.1&rsquo;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 out
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 src="vert-horiz-comparison.png"
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."></p>
<p class="caption">Comparison of vertical and horizontal Japanese: iBunko application (iOS)</p>
</div>
<p class="note">For Chinese and Japanese lines are ordered either right
to left or top to bottom, while for Mongolian and Manchu lines are
ordered left to right.</p>
<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 src="vert-latin-layouts.png"
alt="A dictionary definition for &#x30F4;&#x30A3;&#x30EB;&#x30B9;
might write the English word 'virus' rotated 90&deg; clockwise,
but stack the letters of the initialisms 'RNA' and 'DNA' upright."></p>
<p class="caption">Examples of Latin in vertical Japanese: Daijirin Viewer 1.4 (iOS)
</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" id="fig-mac">
<p><img src="vert-number-layouts.png"
alt="An excerpt 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
&ldquo;for Mac 2011&rdquo;, where the date is rotated to
match the rotated Latin."></p>
<p class="caption">Mac Fan, December 2010, p.49</p>
</div>
<p>Layouts often involve a mixture of vertical and horizontal elements:
<div class="figure">
<p><img src="vert-horiz-combination.png"
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."></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.
<h3 id="block-flow">
Block Flow Direction: the 'writing-mode' property</h3>
<pre class='propdef'>
Name: writing-mode
Value: horizontal-tb | vertical-rl | vertical-lr
Initial: horizontal-tb
Applies to: All elements except table row groups, table column groups, table rows, and table columns
Inherited: yes
Percentages: n/a
Media: visual
Computed value: specified value
Animatable: no
Canonical order: n/a
</pre>
<p>This property specifies whether lines of text are laid out horizontally
or vertically and the direction in which blocks progress. Possible
values:</p>
<dl dfn-for=writing-mode dfn-type=value>
<dt><dfn>horizontal-tb</dfn></dt>
<dd>Top-to-bottom <i>block flow direction</i>.
The <i>writing mode</i> is horizontal.</dd>
<dt><dfn>vertical-rl</dfn></dt>
<dd>Right-to-left <i>block flow direction</i>.
The <i>writing mode</i> is vertical.</dd>
<dt><dfn>vertical-lr</dfn></dt>
<dd>Left-to-right <i>block flow direction</i>.
The <i>writing mode</i> is vertical.</dd>
</dl>
<p>The 'writing-mode' property specifies the <i>block flow direction</i>,
which determines the progression of block-level boxes in a block formatting
context; the progression of line boxes in a block container that contains
inlines; the progression of rows in a table; etc. By virtue of determining
the stacking direction of line boxes, the 'writing-mode' property also
determines whether the line boxes' orientation (and thus the <i>writing mode</i>)
is horizontal or vertical. The 'text-orientation' property then determines
how text is laid out within the line box.
<p>The <dfn export id="principal-writing-mode">principal writing mode</dfn> of the
document is determined by the 'writing-mode' and 'direction' values
specified on the root element. This writing mode is used, for example,
to determine the default page progression direction. (See [[CSS3PAGE]].)
Like 'direction', the 'writing-mode' value of the root element is also
propagated to the initial containing block and sets the block flow
direction of the initial block formatting context.
<p class="note">Note that the 'writing-mode' 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>If a box has a different block flow direction than its containing
block:
<ul>
<li>If the box has a specified 'display' of ''inline'', its 'display'
computes to ''inline-block''. [[!CSS21]]
<li>If the box has a specified 'display' of ''run-in'', its 'display'
computes to ''block''. [[!CSS21]]
<li>If the box is a block container, then it establishes a new block
formatting context.
</ul>
<p>The content of replaced elements do not rotate due to the writing mode:
images, for example, remain upright. However replaced content
involving text (such as MathML content or form elements) should match
the replaced element's writing mode and line orientation if the UA
supports such a vertical writing mode for the replaced content.
<div class="example">
<p>In the following example, two block 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"
src="horizontal.png" width="219" height="300" ></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"
src="vertical-rl.png" height="191" 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: vertical-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"
src="vertical-lr.png" height="191" width="300" ></p>
</div>
<div class="example">
<p>In the following example, some form controls are rendered inside
a block with ''vertical-rl'' writing mode. The form controls are
rendered to match the writing mode.
<pre>
<!-- -->&lt;style>
<!-- --> form { writing-mode: vertical-rl; }
<!-- -->&lt;/style>
<!-- -->...
<!-- -->&lt;form>
<!-- -->&lt;p>&lt;label>姓名&#x3000;&lt;input value="艾俐俐">&lt;/label>
<!-- -->&lt;p>&lt;label>语言&#x3000;&lt;select>&lt;option>English
<!-- --> &lt;option>français
<!-- --> &lt;option>فارسی
<!-- --> &lt;option>中文
<!-- --> &lt;option>日本語&lt;/select>&lt;/label>
<!-- -->&lt;/form></pre>
<p><img alt="Screenshot of vertical layout: the input element is
laid lengthwise from top to bottom and its contents
rendered in a vertical writing mode, matching the
labels outside it. The drop-down selection control
after it slides out to the side (towards the after
edge of the block) rather than downward as it would
in horizontal writing modes."
src="vertical-form.png"></p>
</div>
<div class="example">
<p>In this example, 'writing-mode' sets the list markers upright
using the ''::marker'' pseudo-element. Vertical alignment ensures
that longer numbers will still align with the right of the first
line of text. [[CSS3LIST]]
<pre>::marker { writing-mode: horizontal-tb;
<!-- --> vertical-align: text-top;
<!-- --> color: blue; }</pre>
<div class="figure">
<p><img alt="Diagram showing list markers of '1.', '2.', '3.' sitting
upright atop sideways vertical Latin list item text."
class="example" src="vertical-horizontal-list-markers.png">
<p class="caption">Example of horizontal list markers in a vertical list</p>
</div>
</div>
<h4 id="svg-writing-mode">
SVG1.1 'writing-mode' Values</h4>
<p>SVG1.1 [[!SVG11]] defines some additional values: ''lr'',
''lr-tb'', ''rl'', ''rl-tb'', ''tb'', and ''tb-rl''.
<p>These values are <em>deprecated</em> in any context except SVG1 documents.
Implementations that wish to support these values in the context of CSS
must treat them as follows:
<table class="data">
<thead>
<tr><th>SVG1/Obsolete</th> <th>CSS</th></tr>
</thead>
<tbody>
<tr><td>''lr''</td> <td rowspan=3>''horizontal-tb''</td></tr>
<tr><td>''lr-tb''</td></tr>
<tr><td>''rl''</td></tr>
<tr><td>''tb''</td> <td rowspan=2>''vertical-rl''</td></tr>
<tr><td>''tb-rl''</td></tr>
</tbody>
</table>
<p class="note">The SVG1.1 values were also present in an older revision
of the CSS 'writing-mode' specification, which is obsoleted by this
specification. The additional ''tb-lr'' value of that revision is
replaced by ''vertical-lr''.
<p>In SVG1.1, these values set the <dfn>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 <em>after</em> bidi reordering, and thus has no effect on the
interpretation of the 'direction' property (which is independent of
'writing-mode'). (See <a href="http://www.w3.org/TR/SVG/text.html#RelationshipWithBiDirectionality">Relationship
with bidirectionality</a>. [[!SVG11]])
<p class="note">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>
<h2 id="inline-alignment">
Inline-level Alignment</h2>
<p>When different kinds of inline-level content are placed together on a
line, the baselines of the content and the settings of the 'vertical-align'
property control how they are aligned in the transverse direction of the
line box. This section discusses what baselines are, how to find them,
and how they are used together with the 'vertical-align' property to
determine the alignment of inline-level content.
<h3 id="intro-baselines">
Introduction to Baselines</h3>
<p><em>This section is non-normative.</em></p>
<p>A <dfn>baseline</dfn> is a line along the <i>inline axis</i> of a line box
along which individual glyphs of text are aligned. Baselines guide the
design of glyphs in a font (for example, the bottom of most alphabetic
glyphs typically align with the alphabetic baseline), and they guide
the alignment of glyphs from different fonts or font sizes when typesetting.
<div class="figure">
<p><img alt="Picture of alphabetic text in two font sizes with the baseline and em-boxes"
width="480"
src="alphabetic-baseline-in-two-font-sizes.svg"></p>
<p class="caption">Alphabetic text in two font sizes with the baseline and em-boxes</p>
</div>
<p>Different writing systems prefer different baseline tables.</p>
<div class="figure">
<p><img alt="Latin prefers the alphabetic baseline, on top of which most
letters rest, though some have descenders that dangle below it.
Indic scripts are sometimes typeset with a hanging baseline,
< 685C /div>
since their glyph shapes appear to be hanging from a
horizontal line.
Han-based systems, whose glyphs are designed to fill a square,
tend to align on their bottoms."
src="script-preferred-baselines.gif"></p>
<p class="caption">Preferred baselines in various writing systems</p>
</div>
<p>A well-constructed font contains a <dfn>baseline table</dfn>, which
indicates the position of one or more baselines within the font's
design coordinate space. (The design coordinate space is scaled with
the font size.)
<div class="figure">
<p><img alt=""
src="baselines.gif"></p>
<p class="caption">In a well-designed mixed-script font, the glyphs are
positioned in the coordinate space to harmonize with one another
when typeset together. The baseline table is then constructed to
match the shape of the glyphs, each baseline positioned to match
the glyphs from its preferred scripts.</p>
</div>
<p>The baseline table is a property of the font, and the positions
of the various baselines apply to all glyphs in the font.
<p>Different baseline tables can be provided for alignment in
horizontal and vertical text. UAs should use the vertical
tables in vertical writing modes and the horizontal tables
otherwise.
<h3 id="text-baselines">
Text Baselines</h3>
<p>In this specification, only the following baselines are considered:
<dl>
<dt>alphabetic</dt>
<dd>The <dfn>alphabetic baseline</dfn>, which typically aligns with the
bottom of uppercase Latin glyphs.
</dd>
<dt>central</dt>
<dd>The <dfn>central baseline</dfn>, which typically crosses the center
of the em box. If the font is missing this baseline,
it is assumed to be halfway between the ascender (<i>over</i>)
and descender (<i>under</i>) edges of the em box.
</dd>
</dl>
<p>In vertical writing mode, the <i>central baseline</i> is used as the
dominant baseline when 'text-orientation' is ''mixed'' or ''upright''.
Otherwise the <i>alphabetic baseline</i> is used.
<p class="note">A future CSS module will deal with baselines in more
detail and allow the choice of other dominant baselines and alignment
options.</p>
<h3 id="replaced-baselines">
Atomic Inline Baselines</h3>
<p>If an <a href="http://www.w3.org/TR/CSS21/visuren.html#inline-boxes">atomic
inline</a> (such as an inline-block, inline-table, or replaced inline element)
is not capable of providing its own baseline information, then the
UA synthesizes a baseline table thus:
<dl>
<dt>alphabetic</dt>
<dd>The alphabetic baseline is assumed to be at the <i>under</i> margin edge.</dd>
<dt>central</dt>
<dd>The central baseline is assumed to be halfway between the
<i>under</i> and <i>over</i> margin edges of the box.
</dl>
<h3 id="baseline-alignment">
Baseline Alignment</h3>
<p>The <dfn>dominant baseline</dfn>
(which <a href="#text-baselines">can change</a> based on the writing mode)
is used in CSS for alignment in two cases:
<ul>
<li><strong>Aligning glyphs from different fonts within the same inline box.</strong>
The glyphs are aligned by matching up the positions of the dominant
baseline in their corresponding fonts.
<li><strong>Aligning a child inline-level box within its parent.</strong>
For the 'vertical-align' value of ''baseline'', child is aligned to
the parent by matching the parent's dominant baseline to the same
baseline in the child. (E.g. if the parent's dominant baseline is
alphabetic, then the child's alphabetic baseline is matched to the
parent's alphabetic baseline, even if the child's dominant baseline
is something else.)
For values of ''sub'', ''super'', ''&lt;length&gt;'', and
''&lt;percentage&gt;'', the baselines are aligned as for ''baseline'',
but the child is shifted according to the offset given by its
'vertical-align' value.
<div class="example">
<p>Given following sample markup:
<pre>&lt;p&gt;&lt;span class="outer"&gt;Ap &lt;span class="inner"&gt;<i title=''>ji</i>&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</pre>
<p>And the following style rule:
<pre>span.inner { font-size: .75em; }</pre>
<p>The baseline tables of the parent (<code>.outer</code>) and the child