<pre class='metadata'>
Title: CSS Writing Modes Module Level 3
Shortname: css-writing-modes
Level: 3
Status: ED
Test Suite: http://test.csswg.org/suites/css-writing-modes-3_dev/nightly-unstable/
Work Status: Testing
Group: csswg
ED: https://drafts.csswg.org/css-writing-modes-3/
TR: https://www.w3.org/TR/css-writing-modes-3/
Previous Version: https://www.w3.org/TR/2019/REC-css-writing-modes-3-20191210/
Issue Tracking: Tracker http://www.w3.org/Style/CSS/Tracker/products/30
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Koji Ishii, Google, kojiishi@gmail.com, w3cid 45369
Former Editor: Shinyu Murakami, Antenna House, murakami@antenna.co.jp
Former Editor: Paul Nelson, Microsoft, paulnel@microsoft.com
Former Editor: Michel Suignard, Microsoft, michelsu@microsoft.com
Abstract: CSS Writing Modes Level 3 defines CSS support for various writing modes and their combinations, including left-to-right and right-to-left text ordering as well as horizontal and vertical orientations.
Ignored Terms: glyph orientation, *-left, *-right, *-top, *-bottom, text-combine-mode, root inline box, … message topic …, glyph-orientation-horizontal
Link Defaults: css2 (property) display/min-height/max-height/min-width/max-width/clip/left/right/bottom/top, css-text-3 (property) letter-spacing, css-text-decor-3 (property) text-decoration, svg2 (property) glyph-orientation-vertical/glyph-orientation-horizontal
Status Text: <div class=correction><a href="https://www.w3.org/Consortium/Process/#candidate-correction">Candidate corrections</a> are marked in the document.</div>
</pre>
<pre class=link-defaults>
spec:css2; type:property;
    text:float
    text:clear
    text:line-height
spec:css-text-3; type:dfn; text:character
spec:css-backgrounds-3; type:property; text:box-shadow
</pre>

<style>
object { vertical-align: middle; }
.sidebar { float: right; background: #eee; border: solid gray; margin: 1em; }
@media (prefers-color-scheme: dark) { .sidebar { background: var(--borderedblock-bg, #eee); } }
.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;
}
pre.ascii-art {
  display: table; /* shrinkwrap */
  margin: 1em auto;
  line-height: normal;
}
</style>


<h2 id="intro">
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 <a>inline base direction</a> and <a>block flow direction</a>:

  <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="Text flowing left to right,
               Latin glyphs set upright,
               and lines stacked top to bottom"></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="Text flowing top to bottom,
               Latin glyphs tipped sideways to the right (rotated 90&deg; clockwise),
               and lines stacked left to right"></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="Text flowing left to right,
               Latin glyphs set upright,
               and lines stacked top to bottom"></a>
      <a href="diagrams/text-flow-vectors-rl.svg">
        <img src="diagrams/text-flow-vectors-rl.png" class="landscape"
          alt="Text flowing top to bottom,
               Latin glyphs tipped sideways to the right (rotated 90&deg; clockwise),
               and lines stacked right to left"></a>
      <p class="caption">Han-based writing modes
    </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>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>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 noexport>vertical block flow</dfn>
    (which is a downward or upward block flow)
    and <dfn noexport>horizontal block flow</dfn>
    (which is leftward or rightward block flow).
    To avoid confusion, CSS specifications avoid this latter set of terms.

  <p>The <dfn export>typographic mode</dfn> determines whether to use
    typographic conventions specific to vertical flow for <a>vertical scripts</a>
    (<dfn export>vertical typographic mode</dfn>)
    or to use the typographic conventions of [=horizontal writing modes=]
    (<dfn export>horizontal typographic mode</dfn>).
    This concept distinguishes vertical typesetting
    from rotated horizontal typesetting.

  <p>The 'text-orientation' component of the writing mode
    controls the <a>glyph orientation</a>
    in [=vertical typographic modes=],
    dictating whether a particular [=typographic character unit=]
    is [=typeset upright=] or [=typeset sideways=].

  <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 [[!CSS2]] sections 8.6 and 9.10.
  The interaction of its features
  with other text operations
  in setting lines of text
  is described in [[css-text-3#order]].

  <p>The <a>computed values</a> of the
  'writing-mode', 'direction', and 'text-orientation' properties
  (even on elements to which these properties themselves don't apply [[CSS-CASCADE-4]])
  are broadly able to influence the computed values of other, unrelated properties
  through calculations such as
  the computation of <a>font-relative lengths</a>
  or the cascade of <a href="http://www.w3.org/TR/css-logical-1/">flow-relative properties</a>
  which purposefully depend on the computed <a>writing mode</a>
  or on font metrics that can depend on the <a>writing mode</a>.

<h3 id="values">
Value Definitions and Terminology</h3>


  This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
  using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
  Value types not defined in this specification are defined in CSS Values &amp; Units [[!CSS-VALUES-3]].
  Combination with other CSS modules may expand the definitions of these value types.

  In addition to the property-specific values listed in their definitions,
  all properties defined in this specification
  also accept the <a>CSS-wide keywords</a> as their property value.
  For readability they have not been repeated explicitly.

  <p>Other important terminology and concepts used in this specification
  are defined in [[!CSS2]] and [[!CSS-TEXT-3]].

<span id="bidi"></span>
<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>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.

  <p class="note">
    The HTML specifications ([[HTML401]], section 8.2, and [[HTML/rendering#bidi-rendering]]) define
    bidirectionality behavior for HTML elements.</p>

  <p class="advisement">
    <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.

<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
  Computed value: specified value
  Animation type: not animatable
  Canonical order: n/a
  </pre>

  <p class="advisement">Because HTML UAs can turn off CSS styling,
    <strong>we recommend HTML authors to use the HTML <code>dir</code> attribute and &lt;bdo&gt; element</strong>
    to ensure correct bidirectional layout in the absence of a style sheet.
    <strong>Authors <em>should not</em> use 'direction' in HTML documents.</strong>

  <p>This property specifies the <a>inline base direction</a> 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="https://www.w3.org/TR/CSS2/tables.html">table</a> column layout,
    the direction of horizontal <a href="https://www.w3.org/TR/CSS2/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>This value sets <a>inline base direction</a> (bidi directionality)
     to <a>line-left</a>-to-<a>line-right</a>.
   <dt><dfn>rtl</dfn></dt>
   <dd>This value sets <a>inline base direction</a> (bidi directionality)
     to <a>line-right</a>-to-<a>line-left</a>.
  </dl>

  <p class="note">The 'direction' property has no effect on bidi reordering
    when specified on inline boxes whose 'unicode-bidi' value is ''unicode-bidi/normal'',
    because the box does not open an additional level
    of embedding with respect to the bidirectional algorithm.</p>

  <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
  Computed value: specified value
  Animation type: not animatable
  </pre>

  <p class="advisement">Because HTML UAs can turn off CSS styling,
    <strong>we recommend HTML authors to use the HTML <code>dir</code> attribute, &lt;bdo&gt; element,
    and appropriate distinction of text-level vs. grouping-level HTML element types</strong>
    to ensure correct bidirectional layout in the absence of a style sheet.
    <strong>Authors <em>should not</em> use 'unicode-bidi' in HTML documents.</strong>

  <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 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 lt="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 <a>forced paragraph break</a>
      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, <a>forced paragraph breaks</a> within the box still create
      a corresponding break in the containing paragraph.

      <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 <a>directional embedding</a>
      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.

    <dt><dfn value for=unicode-bidi>isolate-override</dfn></dt>
    <dd>This combines the <a>isolation</a> behavior of ''isolate''
      with the <a>directional override</a> 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.
      It effectively nests a <a>directional override</a> inside an <a>isolated sequence</a>.

    <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 <a>bidi paragraphs</a> (if a block container)
      or <a>isolated sequences</a> (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).
  </dl>

  <p>Following Unicode Bidirectional Algorithm clause HL3 [[!UAX9]],
  values other than ''normal''
  effectively insert the corresponding Unicode bidi control codes
  into the text stream at the start and end of the inline element
  before passing the paragraph to the Unicode bidirectional algorithm for reordering.
  (See [[#bidi-control-codes]].)

  <table class="data" id="bidi-control-codes-injection-table">
    <caption>Bidi control codes injected by 'unicode-bidi'
    at the start/end of ''display: inline'' boxes</caption>
    <colgroup span=1></colgroup>
    <colgroup span=2></colgroup>
    <colgroup span=2></colgroup>
    <thead>
      <tr><th rowspan=3 scope=col>'unicode-bidi' value
          <th colspan=4>'direction' value
      <tr>
          <th colspan=2>''ltr''
          <th colspan=2>''rtl''
      <tr>
          <th>start
          <th>end
          <th>start
          <th>end
    <tbody>
      <tr>
          <th scope=row>''normal''
          <td>&mdash;
          <td>&mdash;
          <td>&mdash;
          <td>&mdash;
      <tr>
          <th scope=row>''embed''
          <td>LRE (U+202A)
          <td>PDF (U+202C)
          <td>RLE (U+202B)
          <td>PDF (U+202C)
      <tr>
          <th scope=row>''isolate''
          <td>LRI (U+2066)
          <td>PDI (U+2069)
          <td>RLI (U+2067)
          <td>PDI (U+2069)
      <tr>
          <th scope=row>''bidi-override''*
          <td>LRO (U+202D)
          <td>PDF (U+202C)
          <td>RLO (U+202E)
          <td>PDF (U+202C)
      <tr>
          <th scope=row>''isolate-override''*
          <td>FSI,LRO (U+2068,U+202D)
          <td>PDF,PDI (U+202C,U+2069)
          <td>FSI,RLO (U+2068,U+202E)
          <td>PDF,PDI (U+202C,U+2069)
      <tr>
          <th scope=row>''plaintext''
          <td>FSI (U+2068)
          <td>PDI (U+2069)
          <td>FSI (U+2068)
          <td>PDI (U+2069)
    <tfoot>
      <tr>
          <td colspan=5>
          <small>* The LRO/RLO+PDF pairs are also applied
          to the <a>root inline box</a> of a <a>block container</a>
          if these values of 'unicode-bidi'
          were specified on the <a>block container</a>.</small>
  </table>

  <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 class=note>
    Because the Unicode algorithm has a limit of 125 levels of embedding,
    care should be taken not to overuse 'unicode-bidi' values other than ''normal''.
    In particular, a value of ''inherit''
    should be used with extreme caution in deeply nested inline markup.
    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 ''display/inline''
    (see example below).

<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 the writing direction. This is the style sheet:</p>

    <pre>
/* Rules for bidi */
[dir=rtl] {direction: rtl; unicode-bidi: isolate; }
[dir=ltr] {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 lt=''>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 <a>isolated sequence</a> 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 lt=''>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-algo">
Applying the Bidirectional Reordering Algorithm</h3>

  <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 lt="bidi paragraph">paragraph</dfn> unit
    in the bidirectional algorithm.

<h4 id="bidi-para-direction">
Bidi Paragraph Embedding Levels</h4>

  <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.

  <p>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.

<h4 id="bidi-control-codes">
CSS&ndash;Unicode Bidi Control Translation, Text Reordering</h4>

  <p>The final order of characters within each <a>bidi paragraph</a> is the
    same as if the bidi control codes had been added as described for 'unicode-bidi' (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 class="note">
    Note that bidi control codes in the source text are still honored,
    and might not correspond to the document tree structure.
    This can split inlines or interfere with bidi start/end control pairing
    in interesting ways.

<h4 id="bidi-atomic-inlines">
Bidi Treatment of Atomic Inlines</h4>

  <p>In this process, <a>replaced elements</a> 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.
    (This is so that, in case the replaced element falls back to rendering inlined text content,
    its bidi effect on the surrounding text is consistent with its replaced rendering.)

  <p>All other atomic inline-level boxes are treated as neutral characters
    always.</p>

<h4 id="bidi-embedding-breaks">
Paragraph Breaks Within Embeddings and Isolates</h4>

  <p>If an inline box is broken around a <a>bidi paragraph</a> boundary
    (e.g. if split by a block or <a>forced paragraph break</a>),
    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 <a>forced paragraph break</a>
    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">
    Note that this behavior is applied by CSS for CSS-declared bidi controls
    applied to the box tree;
    it does not apply to Unicode's bidi formatting controls,
    which are defined to terminate their effect at the end of the bidi paragraph.

<h4 id="bidi-box-model">
Reordering-induced Box Fragmentation</h4>

  <p>Since bidi reordering can split apart and reorder text
    that is logically contiguous,
    bidirectional text can cause an <a>inline box</a> containing such text
    to be split and its fragments reordered within a line.

<!-- CSS2.1 8.6 -->
  <p>For each line box, UAs must take the fragments of each inline box
    and assign the margins, borders, and padding in visual order (not logical order).
    The <a>start</a>-most fragment on the first line box in which the box appears
    has the <a>start</a> edge's margin, border, and padding;
    and the end-most fragment on the last line box in which the box appears
    has the <a>end</a> 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-modes">
Vertical Writing Modes</h2>

  <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.

<h3 id="vertical-intro">
Introduction to Vertical Writing</h3>

  <p><em>This subsection is non-normative.</em></p>

  <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="images/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="images/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="images/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="images/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, table columns, ruby base containers, ruby annotation containers
  Inherited: yes
  Percentages: n/a
  Computed value: specified value
  Animation type: not animatable
  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 <a>block flow direction</a>.
        Both the <a>writing mode</a> and the <a>typographic mode</a> are horizontal.</dd>
    <dt><dfn>vertical-rl</dfn></dt>
    <dd>Right-to-left <a>block flow direction</a>.
        Both the <a>writing mode</a> and the <a>typographic mode</a> are vertical.</dd>
    <dt><dfn>vertical-lr</dfn></dt>
    <dd>Left-to-right <a>block flow direction</a>.
        Both the <a>writing mode</a> and the <a>typographic mode</a> are vertical.</dd>
  </dl>

  <p>The 'writing-mode' property specifies the <a>block flow direction</a>,
    which determines the ordering direction of block-level boxes in a block formatting context;
    the ordering direction of line boxes in a block container that contains inlines;
    the ordering direction 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 <a>writing mode</a>)
    is horizontal or vertical.
    The 'text-orientation' property then determines how text is laid out within the line box.

  <p>The content of <a>replaced elements</a> do not rotate due to the writing mode:
    images and external content such as from <code>&lt;iframe></code>s, for example, remain upright,
    and the <a>default object size</a> of 300px&times;150px does not re-orient.
    However embedded 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="images/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="images/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="images/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 typographic 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="images/vertical-form.png"></p>
  </div>

  <p>If a box has a different 'writing-mode' value than its parent box
    (i.e. nearest ancestor without ''display: contents''):
  <ul>
   <li>If the box would otherwise become an <a>in-flow</a> box
     with a computed 'display' of ''display/inline'',
     its 'display' computes instead to ''inline-block''.
   <li>If the box is a <a>block container</a>,
     then it establishes an <a lt="independent formatting context">independent</a>
     <a>block formatting context</a>.
   <li>More generally, if its specified <a>inner display type</a> is ''flow'',
     then its computed <a>inner display type</a> becomes ''flow-root''. [[!CSS-DISPLAY-3]]
  </ul>

  <div class="note" id="embedded-svg-inheritance">
    <p>As all other inherited CSS properties do,
    the 'writing-mode' property inherits to SVG elements inlined
    (rather than linked) into the source document.
    This could cause unintentional side effects when, for example,
    an SVG image designed only for horizontal flow was embedded into a vertical flow document.

    <p>Authors can prevent this from happening by adding the following rule:
    <div class="example">
      <pre>svg { writing-mode: initial; }</pre>
    </div>
  </div>

<h4 id="svg-writing-mode">
Obsolete 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>obsolete</em> in any context except SVG1 documents
    and are therefore <em>optional</em> for non-SVG UAs.

<h5 id="svg-writing-mode-css" class="no-toc">
Supporting SVG1.1 'writing-mode' values in CSS syntax</h5>

  <p>UAs that wish to support these values in the context of CSS
    must compute them as follows:

  <table class="data">
    <caption>Mapping of Obsolete SVG1.1 'writing-mode' values to modern CSS</caption>
    <thead>
      <tr><th>Specified</th> <th>Computed</th></tr>
    </thead>
    <tbody>
      <tr><td>''lr''</td> <td rowspan=4>''horizontal-tb''</td></tr>
      <tr><td>''lr-tb''</td></tr>
      <tr><td>''rl''</td></tr>
      <tr><td>''rl-tb''</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 version 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''.

<h5 id="svg-writing-mode-markup" class="no-toc">
Supporting SVG1.1 'writing-mode' values in presentational attributes</h5>

  <p>In order to support legacy content with presentational attributes,
  and to allow authors to create documents that support older clients,
  SVG UAs must add the following style sheet rules to their default UA stylesheet:

  <pre highlight=css>
    @namespace svg "http://www.w3.org/2000/svg";
    svg|*[writing-mode=lr], svg|*[writing-mode=lr-tb],
    svg|*[writing-mode=rl], svg|*[writing-mode=rl-tb] {
      writing-mode: horizontal-tb; }
    svg|*[writing-mode=tb], svg|*[writing-mode=tb-rl] {
      writing-mode: vertical-rl; }
  </pre>

  <div class="note">
    Authors who wish to create forwards and backwards-compatible SVG content
    in CSS syntax can use the CSS forwards-compatible parsing rules to do so,
    e.g.

    <pre>svg|text { writing-mode: tb; writing-mode: vertical-rl; }</pre>
  </div>

<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 noexport>baseline</dfn> is a line along the <a>inline axis</a> 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="images/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,
                 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="images/script-preferred-baselines.gif"></p>
    <p class="caption">Preferred baselines in various writing systems</p>
  </div>

  <p>A well-constructed font contains a <dfn noexport>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="images/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 <a>typographic modes</a> 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 ideographic <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 (<a>over</a>)
      and descender (<a>under</a>) edges of the ideographic em box.
    </dd>
  </dl>

  <p>In vertical <a>typographic mode</a>, the <a>central baseline</a> is used as the
    dominant baseline when 'text-orientation' is ''mixed'' or ''upright''.
    Otherwise the <a>alphabetic baseline</a> 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="https://www.w3.org/TR/CSS2/visuren.html#inline-boxes">atomic
    inline</a> (such as an inline-block, inline-table, or replaced inline element)
    does not have a baseline,
    then the UA synthesizes a baseline table thus:

  <dl>
    <dt>alphabetic</dt>
    <dd>The alphabetic baseline is assumed to be at the <a>under</a> margin edge.</dd>
    <dt>central</dt>
    <dd>The central baseline is assumed to be halfway between the
    <a>under</a> and <a>over</a> margin edges of the box.
  </dl>

  <p class="note">The 'vertical-align' property in [[!CSS2]] defines the baseline of
    inline-table and inline-block boxes with some exceptions.

<h3 id="baseline-alignment">
Baseline Alignment</h3>

  <p>The <dfn noexport>dominant baseline</dfn>
    (which <a href="#text-baselines">can change</a> based on the <a>typographic mode</a>)
    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 ''vertical-align/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 ''vertical-align/sub'', ''vertical-align/super'', ''&lt;length&gt;'', and
      ''&lt;percentage&gt;'', the baselines are aligned as for ''vertical-align/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;ਜੀ&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
          (<code>.inner</code>) will not match up due to the font size difference.
          Since the dominant baseline is the alphabetic baseline, the child box
          is aligned to its parent by matching up their alphabetic baselines.
        <div class="figure">
          <p><img alt="" src="images/baseline-align-sizes.gif">
        </div>
      </div>

    <div class="example">
      <p>If we assign ''vertical-align: super'' to the <code>.inner</code>
        element from the example above, the same rules are used to align
        the <code>.inner</code> child to its parent; the only difference
        is in addition to the baseline alignment, the child is shifted to
        the superscript position.
      <pre>span.inner { vertical-align: super; font-size: .75em; }</pre>
      <div class="figure">
        <p><img alt="In this example, the resulting alignment is equivalent
                     to shifting the parent baseline table upwards by the
                     superscript offset, and then aligning the child's
                     alphabetic baseline to the shifted position of the
                     parent's alphabetic baseline."
                src="images/baseline-align-super.gif">
      </div>
    </div>
  </ul>

<h2 id="intro-text-layout">
Introduction to Vertical Text Layout</h2>

  <p>Each writing system has one or more native orientations. Modern scripts
    can therefore be classified into three orientational categories:</p>

  <dl>
    <dt><dfn>horizontal-only</dfn>
      <dd>Scripts that have horizontal, but not vertical, native orientation.
        Includes: Latin, Arabic, Hebrew, Devanagari
    <dt><dfn>vertical-only</dfn>
      <dd>Scripts that have vertical, but not horizontal, native orientation.
        Includes: Mongolian, Phags Pa
    <dt><dfn>bi-orientational</dfn>
      <dd>Scripts that have both vertical and horizontal native orientation.
        Includes: Han, Hangul, Japanese Kana
  </dl>

  <p>A <dfn>vertical script</dfn> is one that has a native vertical orientation:
    i.e. one that is either [=vertical-only=] or that is [=bi-orientational=].
    A <dfn>horizontal script</dfn> is one that has a native horizontal orientation:
    i.e. one that is either [=horizontal-only=] or that is [=bi-orientational=].
    (See <a href="#script-orientations">Appendix A</a> for a categorization of
    scripts by native orientation.)

  <div class="figure">
        <p><img alt="A Venn diagram of these distinctions would show two circles:
                     one labelled 'vertical', the other 'horizontal'. The overlapped
                     region would represent the bi-orientational scripts, while
                     horizontal-only and vertical-only scripts would occupy their
                     respective circles' exclusive regions."
                src="diagrams/script-orientations.png">
  </div>

  <p>In modern typographic systems, all glyphs are assigned a horizontal
    orientation, which is used when laying out text horizontally.
    To lay out vertical text, the UA needs to transform the text from its
    horizontal orientation. This transformation is the <dfn>bi-orientational
    transform</dfn>, and there are two types:

  <dl>
    <dt>rotate</dt>
      <dd>Rotate the glyph from horizontal to vertical
      <a href="diagrams/glyph-right.svg">
        <img src="diagrams/glyph-right.png" class="figure"
          alt="Rotate the glyph from horizontal to vertical"></a>

    <dt>translate</dt>
      <dd>Translate the glyph from horizontal to vertical
      <a href="diagrams/glyph-upright.svg">
        <img src="diagrams/glyph-upright.png" class="figure"
          alt="Translate the glyph from horizontal to vertical"></a>
  </dl>

  <p>Scripts with a native vertical orientation have an
    intrinsic [=bi-orientational transform=], which orients them correctly in
    vertical text: most CJK (Chinese/Japanese/Korean) characters translate,
    that is, they are always upright. Characters from other scripts,
    such as Mongolian, rotate.

  <p>Scripts without a native vertical orientation can be either rotated
    (set sideways) or translated (set upright): the transform used is a
    stylistic preference depending on the text's usage, rather than a
    matter of correctness.
    The 'text-orientation' property's ''mixed'' and ''upright'' values
    are provided to specify rotation vs. translation of [=horizontal-only=] text.

<h3 id="text-orientation">
Orienting Text: the 'text-orientation' property</h3>

  <pre class='propdef'>
  Name: text-orientation
  Value: mixed | upright | sideways
  Initial: mixed
  Applies to: all elements except table row groups, rows, column groups, and columns; and text
  Inherited: yes
  Percentages: n/a
  Computed value: specified value
  Animation type: not animatable
  Canonical order: n/a
  </pre>

  <p>This property specifies the orientation of text within a line.
    Current values only have an effect in vertical <a>typographic modes</a>:
    the property has no effect in horizontal <a>typographic modes</a>.

  <p>Values have the following meanings:</p>

  <dl dfn-for=text-orientation dfn-type=value>
    <dt><dfn>mixed</dfn></dt>
    <dd><p><a>Typographic character units</a> from horizontal-only scripts
      are <a href="#typeset-sideways">typeset sideways</a>,
      i.e. 90&deg; clockwise from their standard orientation in horizontal text.
      <a>Typographic character units</a> from vertical scripts
      are typeset with their intrinsic orientation.
      See <a href="#vertical-orientations">Vertical Orientations</a> for further details.
    <p>This value is typical for layout of dominantly vertical-script text.

    <dt><dfn>upright</dfn></dt>
    <dd><p><a>Typographic character units</a> from horizontal-only scripts
      are <a href="#typeset-upright">typeset upright</a>,
      i.e. in their standard horizontal orientation.
      <a>Typographic character units</a> from vertical scripts
      are typeset with their intrinsic orientation and shaped normally.
      See <a href="#vertical-orientations">Vertical Orientations</a> for further details.
      <p>This value causes the <a>used value</a> of 'direction' to be ''ltr'',
      and for the purposes of bidi reordering,
      causes all characters to be treated as strong LTR.

      Note: The <a>used value</a>, rather than the <a>computed value</a>,
      of 'direction' is influenced
      so that ''rtl'' can inherit properly
      into any descendants
      (such as the contents of a <a lt="horizontal writing mode">horizontal</a> inline-block)
      where this directional override does not apply.

    <dt><dfn>sideways</dfn></dt>
    <dd><p>Causes all text to be <a href="#typeset-sideways">typeset sideways</a>,
      as if in a horizontal layout, but rotated 90&deg; clockwise.
  </dl>

  <div class="figure" id="fig-text-orientation">
    <table class=data>
      <tr>
        <td>
          <img
            alt="text-orientation: mixed"
            src="images/text-orientation-vr.png" width="64" height="160" >
        </td>
        <td>
          <img
            alt="text-orientation: upright"
            src="images/text-orientation-up.png" width="64" height="160" >
        </td>
        <td>
          <img
            alt="text-orientation: sideways"
            src="images/text-orientation-sr.png" width="64" height="160" >
        </td>
      </tr>
      <tr>
        <td style="text-align:center">''mixed''</td>
        <td style="text-align:center">''upright''</td>
        <td style="text-align:center">''sideways''</td>
      </tr>
    </table>
    <p class="caption">'text-orientation' values ('writing-mode' is ''vertical-rl'')</p>
  </div>

  <p class="note">Changing the value of this property may affect inline-level alignment.
    Refer to <a href="#text-baselines">Text Baselines</a> for more details.</p>

  UAs may accept <dfn dfn-type=value dfn-for=text-orientation>sideways-right</dfn>
  as a value that computes to ''sideways''
  if needed for backward compatibility reasons.

  <div class="note">
    As of writing, major implementations do not support
    the automatic LTR treatment of RTL characters for ''upright'' typesetting.
    In such cases, authors may need to explicitly specify
    'unicode-bidi' and 'direction' as in the following example:
    <pre>
        .vertical-upright-hebrew {
            writing-mode: vertical-rl;
            text-orientation: upright;
            unicode-bidi: bidi-override;
            direction: ltr;
        }
    </pre>
  </div>

<h4 id='vertical-font-features'>
Vertical Typesetting and Font Features</h4>

  <p>When typesetting text in ''vertical-rl'' and ''vertical-lr'' modes,
  text is typeset either “upright” or “sideways” as defined below:

  <dl>
    <dt><dfn id='typeset-upright' lt="typeset upright | upright typesetting | typesetting upright" local-lt='upright' export>upright typesetting</dfn>
    <dd>
      <a>Typographic character units</a> are individually typeset upright
      in vertical lines with vertical font metrics.
      The UA must synthesize vertical font metrics for fonts that lack them.
      (This specification does not define heuristics for synthesizing such metrics.)
      Additionally, font features (such as alternate glyphs and other transformation)
      intended for use in vertical typesetting must be used.
      (E.g. the OpenType ''vert'' feature must be enabled.)
      Furthermore, characters from horizontal cursive scripts (such as Arabic)
      are shaped in their isolated forms when typeset upright.

      <p class="note">Note that even when typeset “upright”,
        some glyphs should appear rotated.
        For example, dashes and enclosing punctuation
        should be oriented relative to the <a>inline axis</a>.
        In OpenType, this is typically handled by glyph substitution,
        although not all fonts have alternate glyphs for all relevant codepoints.
        (East Asian fonts usually provide alternates for East Asian codepoints,
        but Western fonts typically lack any vertical typesetting features
        and East Asian fonts typically lack vertical substitutions for Western codepoints.)
        Unicode published draft data on which characters should appear sideways
        as the SVO property in <a href="http://www.unicode.org/reports/tr50/tr50-6.Orientation.txt">this data file</a>;
        however, this property has been abandoned for the current revision of [[!UAX50]].

      <p><a>Typographic character units</a> which are classified
      as <code>Tr</code> or <code>Tu</code> in [[!UAX50]]
      are expected to have alternate glyphs or positioning for typesetting upright in vertical text.
      In the case of <code>Tr</code> <a>characters</a>,
      if such vertical alternate glyphs are missing from the font,
      the UA <em>may wish to</em> [[!RFC6919]] (but is not expected to)
      synthesize the missing glyphs by <a href="#typeset-sideways">typesetting them sideways</a> etc.

    <dt><dfn id='typeset-sideways' lt="typeset sideways | sideways typesetting | typesetting sideways" local-lt='sideways' export>sideways typesetting</dfn>
    <dd>
      <a>Typographic character units</a> typeset as a run
      rotated 90&deg; clockwise from their upright orientation,
      using horizontal metrics and composition,
      and vertical typesetting features are not used.
      However, if the font has features meant to be enabled
      for sideways text that is typeset in vertical lines
      (e.g. to adjust brush stroke angles or alignment),
      those features are used.
      (An example of such a feature would be the proposed
      <a href="http://blogs.adobe.com/CCJKType/2013/08/tale-of-three-features.html"><code>vrtr</code> OpenType font feature</a>.)
  </dl>

<h4 id='vertical-orientations'>
Mixed Vertical Orientations</h4>

  <p>
    [[!UAX50]] defines the <code>Vertical_Orientation</code> property
    for the default glyph orientation of mixed-orientation vertical text.
    When 'text-orientation' is ''mixed'',
    the UA must determine the orientation of each <a>typographic character unit</a>
    by its <code>Vertical_Orientation</code> property:
    <a href="#typeset-upright">typesetting it upright</a>
    if its orientation property is <code>U</code>, <code>Tu</code>, or <code>Tr</code>;
    or <a href="#typeset-sideways">typesetting it sideways</a> (90&deg; clockwise from horizontal)
    if its orientation property is <code>R</code>.

  <p class="note">
    Note that UAX50 does not handle scripts that rotate -90&deg; in vertical contexts,
    so they will not be typeset correctly with ''mixed'' orientation.
    The ''sideways-lr'' value in <a href="http://www.w3.org/TR/css-writing-modes-4/">Level 4</a>, however,
    can correctly display such scripts.

  <p class="note">
    The OpenType ''vrt2'' feature, which is intended for mixed-orientation typesetting,
    is not used by CSS.
    It delegates the responsibility for orienting glyphs to the font designer.
    CSS instead dictates the orientation through [[!UAX50]]
    and orients glyphs by typesetting them sideways or upright as appropriate.

<!-- random notes
  Property to customize text-orientation (and line breaking class) of various
  characters (yes, the name is horrible, we need a better one):
    text-symbolize: latin ||
                    greek ||
                    cyrillic ||
                    letter-symbols || /* letterlike symbols and math letters */
                    arrows || /* and math relation operators?? */
                    currency || /* Sc */
                    rotate-symbols || /* other So */

  Do symbols NFC-fold to Latin/Greek? If so we might have a problem there.

  Roman numerals are poorly handled right now. If we make them upright, we
  get the right behavior in most cases. But as soon as you get to 13, you
  have a problem.
-->

<h4 id="glyph-orientation">
Obsolete: the SVG1.1 'glyph-orientation-vertical' property</h4>

  <pre class='propdef'>
  Name: glyph-orientation-vertical
  Value: auto | 0deg | 90deg | 0 | 90
  Initial: n/a
  Applies to: n/a
  Inherited: n/a
  Percentages: n/a
  Computed value: n/a
  Animation type: n/a
  Canonical order: n/a
  </pre>

  Some SVG user agents will need to process documents containing
  the obsolete SVG 'glyph-orientation-vertical' property,
  which was defined to accept an ''glyph-orientation-vertical/auto'' keyword
  as well as <<angle>> and <<integer>> values representing multiples of 90&deg;.
  While supporting this property is <em>optional</em>,
  UAs that do so must alias 'glyph-orientation-vertical'
  as a shorthand of 'text-orientation' as follows:

  <table class="data">
    <thead>
      <tr>
        <th>Shorthand 'glyph-orientation-vertical' value
        <th>Longhand 'text-orientation' value
    <tbody>
      <tr>
        <td>''glyph-orientation-vertical/auto''
        <td>''mixed''
      <tr>
        <td>''0deg''
        <td>''upright''
      <tr>
        <td>''0''
        <td>''upright''
      <tr>
        <td>''90deg''
        <td>''sideways''
      <tr>
        <td>''90''
        <td>''sideways''
  </table>

  UAs must ignore and treat as invalid
  any other values for the 'glyph-orientation-vertical' property;
  and treat as invalid the 'glyph-orientation-horizontal' property
  in its entirety.

  Note: The ''180deg'' and ''270deg'' values,
  the radian and gradian values,
  and the 'glyph-orientation-horizontal' property
  are not mapped because they have no known use cases
  nor significant amounts of dependent content,
  and are therefore not part of CSS,
  and have been likewise dropped from SVG.

<h2 id="abstract-box">
Abstract Box Terminology</h2>

  <p>CSS2.1 [[!CSS2]] defines the box layout model of CSS in detail,
    but only for the ''horizontal-tb'' writing mode. Layout is analogous
    in writing modes other than ''horizontal-tb''; however directional
    and dimensional terms in CSS2.1 must be abstracted and remapped
    appropriately.

  <p>This section defines abstract directional and dimensional terms and
    their mappings in order to define box layout for other writing modes,
    and to provide terminology for future specs to define their layout
    concepts abstractly. (The next section explains how to apply them to
    CSS2.1 layout calculations and how to handle
    <a href="#orthogonal-flows">orthogonal flows</a>.)
    Although they derive from the behavior of text, these abstract
    mappings exist even for boxes that do not contain any line boxes:
    they are calculated directly from the values of the 'writing-mode'
    and 'direction' properties.

  <p>There are three sets of directional terms in CSS:

  <dl export>
  <dt><dfn>physical</dfn>
    <dd>Interpreted relative to the page, independent of writing mode.
    The <dfn lt="physical direction">physical directions</dfn> are
    <dfn lt="physical left | left">left</dfn>,
    <dfn lt="physical right | right">right</dfn>,
    <dfn lt="physical top | top">top</dfn>, and
    <dfn lt="physical bottom | bottom">bottom</dfn>.
  <dt><dfn><a href="#logical-directions">flow-relative</a></dfn>
    <dd>Interpreted relative to the flow of content.
    The flow-relative directions are <a>start</a> and <a>end</a>,
    or <a>block-start</a>, <a>block-end</a>, <a>inline-start</a>, and <a>inline-end</a>
    if the dimension is also ambiguous.
  <dt><dfn><a href="#line-directions">line-relative</a></dfn>
    <dd>Interpreted relative to the orientation of the line box.
    The line-relative directions are <a>line-left</a>, <a>line-right</a>,
    <a>line-over</a>, and <a>line-under</a>.
  </dl>

  <p export>The <dfn>physical dimensions</dfn> are <dfn>width</dfn> and <dfn>height</dfn>,
    which correspond to measurements along the <dfn lt="x-axis|horizontal axis|horizontal-axis">x-axis</dfn>
    (<dfn>horizontal dimension</dfn>) and <dfn lt="y-axis|vertical axis|vertical-axis">y-axis</dfn> (<dfn>vertical dimension</dfn>),
    respectively. <a href="#abstract-axes">Abstract dimensions</a>
    are identical in both flow-relative and line-relative terms, so there
    is only one set of these terms.

  <figure id="abstract-ltr-tb">
    <img src="diagrams/sizing-ltr-tb.svg" width=460 height=280>
    <figcaption>Physical & flow-relative terms as applicable to typical English text layout</figcaption>
  </figure>
  <figure id="abstract-ttb-rl">
    <img src="diagrams/sizing-ttb-rl.svg" width=460 height=280>
    <figcaption>Physical & flow-relative terms as applicable to vertical Chinese text layout</figcaption>
  </figure>

  <p class="note">
    Note: [[CSS-FLEXBOX-1]] also defines <a href="https://www.w3.org/TR/css-flexbox/#box-model">flex-relative terms</a>,
    which are used in describing flex layout.


<h3 id="abstract-axes">
Abstract Dimensions</h3>

  <p>The <dfn export>abstract dimensions</dfn> are defined below:

  <dl export>
    <dt><dfn>block dimension</dfn></dt>
      <dd>The dimension perpendicular to the flow of text within a line, i.e.
        the <a>vertical dimension</a> in horizontal writing modes, and
        the <a>horizontal dimension</a> in vertical writing modes.</dd>
    <dt><dfn>inline dimension</dfn></dt>
      <dd>The dimension parallel to the flow of text within a line, i.e.
        the <a>horizontal dimension</a> in horizontal writing modes, and
        the <a>vertical dimension</a> in vertical writing modes.</dd>
    <dt><dfn lt="block axis | block-axis">block axis</dfn></dt>
      <dd>The axis in the block dimension,
      i.e. the <a>vertical axis</a> in horizontal writing modes
      and the <a>horizontal axis</a> in vertical writing modes.</dd>
    <dt><dfn lt="inline axis | inline-axis">inline axis</dfn></dt>
      <dd>The axis in the inline dimension, i.e. the <a>horizontal
        axis</a> in horizontal writing modes and the <a>vertical axis</a>
        in vertical writing modes.</dd>
    <dt><dfn lt="block size | block-size">block size</dfn>
    <dt id=extent><dfn>logical height</dfn>
      <dd>A measurement in the block dimension:
        refers to the physical height (vertical dimension) in horizontal writing modes,
        and to the physical width (horizontal dimension) in vertical writing modes.
    <dt><dfn lt="inline size | inline-size">inline size</dfn>
    <dt id=measure><dfn>logical width</dfn>
      <dd>A measurement in the inline dimension:
        refers to the physical width (horizontal dimension) in horizontal writing modes,
        and to the physical height (vertical dimension) in vertical writing modes.
  </dl>

<h3 id="logical-directions">
Flow-relative Directions</h3>

  <p>The <dfn export lt="flow-relative direction">flow-relative directions</dfn>,
    <a>block-start</a>, <a>block-end</a>, <a>inline-start</a>, and <a>inline-end</a>,
    are defined relative to the flow of content on the page.
    In an <abbr title="left-to-right">LTR</abbr>
    ''horizontal-tb'' writing mode, they correspond to the
    top, bottom, left, and right directions, respectively.
    They are defined as follows:

  <dl export>
  <dt><dfn lt="block start | block-start">block-start</dfn>
    <dd>The side that comes earlier in the <a>block flow direction</a>,
    as determined by the 'writing-mode' property:
    the physical top in ''horizontal-tb'' mode,
    the right in ''vertical-rl'', and the left in ''vertical-lr''.
  <dt><dfn lt="block end | block-end">block-end</dfn>
    <dd>The side opposite <a>block-start</a>.
  <dt><dfn lt="inline start | inline-start">inline-start</dfn>
    <dd>The side from which text of the inline base direction would start.
    For boxes with a used 'direction' value of ''ltr'', this means the <a>line-left</a> side.
    For boxes with a used 'direction'  value of ''rtl'', this means the <a>line-right</a> side.
  <dt><dfn lt="inline end | inline-end">inline-end</dfn>
    <dd>The side opposite <a>start</a>.
  </dl>

  <p>Where contextually unambiguous or encompassing both meanings,
    the terms <dfn export for=CSS lt="start | startmost">start</dfn>
    and <dfn export for=CSS lt="end | endmost">end</dfn>
    are used in place of <a>block-start</a>/<a>inline-start</a>
    and <a>block-end</a>/<a>inline-end</a>, respectively.

  <p class="note">Note that while determining the <a>block-start</a> and
    <a>block-end</a> sides of a box depends only on the 'writing-mode' property,
    determining the <a>inline-start</a> and <a>inline-end</a> sides of a box depends
    not only on the 'writing-mode' property but also the 'direction' property.</p>

<h3 id="line-directions">
Line-relative Directions</h3>

  <p>The <dfn export>line orientation</dfn> determines which side of a line
    box is the logical “top” (ascender side).
    It is given by the 'writing-mode' property.
    Usually the line-relative “top”
    corresponds to the <a>block-start</a> side, but this is not always the case:
    in Mongolian typesetting (and thus by default in ''vertical-lr'' writing
    modes), the line-relative “top” corresponds to the <a>block-end</a> side.
    Hence the need for distinct terminology.

  <div class="figure">
    <img src="images/mongolian-lr.jpg" alt="Mongolian mixed with English">
    <p class="caption">A primarily Mongolian document, such as the one above, is written in
    vertical lines stacking left to right, but lays its Latin text with
    the tops of the glyphs towards the right. This makes the text run in
    the same inline direction as Mongolian (top-to-bottom) and face the
    same direction it does in other East Asian layouts (which have vertical
    lines stacking right to left), but the glyphs' tops are facing the
    bottom of the line stack rather than the top, which in an English
    paragraph would be upside-down. (See this
    <a href="diagrams/text-flow-vectors-lr-reverse.svg">Diagram of Mongolian
    Text Layout</a>.)
  </div>

  <p>In addition to a line-relative “top” and “bottom” to map things like
    'vertical-align: top', CSS also needs to refer to a line-relative
    “left” and “right” in order to map things like ''text-align: left''.
    Thus there are four <dfn export lt="line-relative direction">line-relative directions</dfn>, which are
    defined relative to the <a>line orientation</a> as follows:

  <dl export>
  <dt><dfn>over</dfn> or <dfn id=line-over>line-over</dfn>
    <dd>Nominally the side that corresponds to the ascender side or “top”
      side of a line box. (The side overlines are typically drawn on.)
  <dt><dfn>under</dfn> or <dfn id=line-under>line-under</dfn>
    <dd>Opposite of <a>over</a>: the line-relative “bottom” or descender side.
    (The side underlines are typically drawn on.)
  <dt><dfn id=line-left>line-left</dfn>
    <dd>The line-relative "left" side of a line box,
    which is nominally the side from which <abbr title="left-to-right">LTR</abbr>
    text would start.
  <dt><dfn id=line-right>line-right</dfn>
    <dd>The line-relative "right" side of a line box,
    which is nominally the side from which <abbr title="right-to-left">RTL</abbr>
    text would start. (Opposite of <a>line-left</a>.)
  </dl>

  <p>See the <a href="#logical-to-physical">table below</a> for the exact
    mappings between physical and line-relative directions.

  <div class="figure">
    <a href="diagrams/line-orient-up.svg">
      <img src="diagrams/line-orient-up.png" class="landscape"
        alt="Line orientation compass"></a>
    <p class="caption">Line orientation in ''horizontal-tb''</p>
  </div>

  <div class="figure">
    <a href="diagrams/line-orient-right.svg">
      <img src="diagrams/line-orient-right.png" class="portrait"
        alt="Typical orientation in vertical"></a>
      <p class="caption">Line orientation in ''vertical-rl'' and ''vertical-lr''</p>
  </div>

  <div id="vertical-metrics" class="note">
    <div class="sidefigure">
      <p><img src="images/vertical-upright-baseline.svg"
        alt="Baseline of an upright glyph is drawn vertically from the top center"
        width=80>
      <p class="caption">Vertical baseline of an upright glyph
    </div>
    When ''text-orientation: upright'',
    the baseline is still vertical,
    and the vertical baseline in the font is used,
    or the vertical baseline is synthesized if the font does not provide.
  <p>
    Since the baseline is vertical,
    the definitions for ''mixed'' or ''sideways'' above still apply; i.e.,
    <a>line-over</a> is on right, and <a>line-under</a> is on left.
  <p>
    This is in line with font systems such as OpenType which
    defines the ascender on right and
    the descender on left in their vertical metrics.
  </div>

<h3 id="logical-to-physical">
Abstract-to-Physical Mappings</h3>

  <p>The following table summarizes the abstract-to-physical mappings
  (based on the <em>used</em> 'direction' and 'writing-mode'):

  <table class="complex data">
    <caption>Abstract-Physical Mapping</caption>
    <colgroup class="header"></colgroup>
    <colgroup span=6></colgroup>
    <thead>
      <tr>
        <th scope="row">'writing-mode'</th>
        <th colspan="2">''horizontal-tb''</th>
        <th colspan="2">''vertical-rl''</th>
        <th colspan="2">''vertical-lr''</th>
      </tr>
      <tr>
        <th scope="row">'direction'</th>
        <th>''ltr''</th>
        <th>''rtl''</th>
        <th>''ltr''</th>
        <th>''rtl''</th>
        <th>''ltr''</th>
        <th>''rtl''</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">block-size</th>
        <td colspan="2">height</td>
        <td colspan="4">width</td>
      </tr>
      <tr>
        <th scope="row">inline-size</th>
        <td colspan="2">width</td>
        <td colspan="4">height</td>
      </tr>
      <tr>
        <th scope="row">block-start</th>
        <td colspan="2">top</td>
        <td colspan="2">right</td>
        <td colspan="2">left</td>
      </tr>
      <tr>
        <th scope="row">block-end</th>
        <td colspan="2">bottom</td>
        <td colspan="2">left</td>
        <td colspan="2">right</td>
      </tr>
      <tr>
        <th scope="row">inline-start</th>
        <td>left</td>
        <td>right</td>
        <td>top</td>
        <td>bottom</td>
        <td>top</td>
        <td>bottom</td>
      </tr>
      <tr>
        <th scope="row">inline-end</th>
        <td>right</td>
        <td>left</td>
        <td>bottom</td>
        <td>top</td>
        <td>bottom</td>
        <td>top</td>
      </tr>
    </tbody>
    <tbody>
      <tr>
        <th scope="row">over</th>
        <td colspan="2">top</td>
        <td colspan="4">right</td>
      </tr>
      <tr>
        <th scope="row">under</th>
        <td colspan="2">bottom</td>
        <td colspan="4">left</td>
      </tr>
      <tr>
        <th scope="row">line-left</th>
        <td colspan="2">left</td>
        <td colspan="4">top</td>
      </tr>
      <tr>
        <th scope="row">line-right</th>
        <td colspan="2">right</td>
        <td colspan="4">bottom</td>
      </tr>
    </tbody>
  </table>

  Note: The <a lt="used value">used</a> 'direction'
  depends on the computed 'writing-mode' and 'text-orientation':
  in <a>vertical writing modes</a>,
  a 'text-orientation' value of ''text-orientation/upright''
  forces the used 'direction' to ''ltr''.

<h2 id="abstract-layout">
Abstract Box Layout</h2>

<h3 id="vertical-layout">
Principles of Layout in Vertical Writing Modes</h3>

  <p>CSS box layout in vertical writing modes is analogous to layout in
    the horizontal writing modes, following the principles outlined below:

  <p>Layout calculation rules (such as those in CSS2.1, Section 10.3)
     that apply to the horizontal dimension in horizontal writing modes
     instead apply to the vertical dimension in vertical writing modes.
     Likewise, layout calculation rules (such as those in CSS2.1, Section 10.6)
     that apply to the vertical dimension in horizontal writing modes
     instead apply to the horizontal dimension in vertical writing modes.
     Thus:
  <ul>
    <li><p>Layout rules that refer to the width use the height instead,
        and vice versa.
    <li><p>Layout rules that refer to the '*-left' and '*-right'
        box properties (border, margin, padding, positioning offsets)
        use '*-top' and '*-bottom' instead, and vice versa,
        mapping the horizontal writing-mode rules of CSS2.1
        into vertical writing-mode rules using the <a>flow-relative directions</a>.
        The side of the box these properties apply to doesn't change:
        only which values are inputs to which layout calculations changes.
        The 'margin-left' property still affects the lefthand margin, for example;
        however in a ''vertical-rl'' writing mode it takes part in margin collapsing
        in place of 'margin-bottom'.
    <li><p>Layout rules that depend on the 'direction' property to choose between
        left and right (e.g. overflow, overconstraint resolution, the initial
        value for 'text-align', table column ordering)
        are abstracted to the <a>start</a> and <a>end</a> sides
        and applied appropriately.</li>
  </ul>

  <div class="example">
    <p>For example, in vertical writing modes,
       table rows are vertical and table columns are horizontal.
      In a ''vertical-rl'' ''mixed'' ''rtl'' table,
      the first column would be on the bottom (the <a>inline-start</a> side),
      and the first row on the right (the <a>block-start</a> side).
      The table's 'margin-right' and 'margin-left' would collapse
      with margins before (on the right) and after (on the left) the table, respectively,
      and if the table had ''margin/auto'' values for 'margin-top' and 'margin-bottom'
      it would be centered vertically within its block flow.
    <div class="figure">
      <p><a href="diagrams/vertical-table.svg">
        <img alt="Diagram of a vertical-rl mixed rtl table in a
        vertical block formatting context, showing the ordering of rows,
        cells, and columns as described above."
              src="diagrams/vertical-table.png"></a>
      <p class="caption">Table in ''vertical-rl'' RTL writing mode</p>
    </div>

  </div>

  <p>For features such as text alignment, floating, and list marker positioning,
    that primarily reference the left or right sides of the line box or
    its longitudinal parallels and therefore have no top or bottom equivalent,
    the <a>line-left</a> and <a>line-right</a> sides
    are used as the reference for the left and right sides respectively.

  <p>Likewise for features such as underlining, overlining, and baseline alignment
    (the unfortunately-named 'vertical-align'), that primarily reference the
    top or bottom sides of the linebox or its transversal parallels and
    therefore have no left or right equivalent, the <a>line-over</a>
    and <a>line-under</a> sides are used as the reference for the
    top and bottom sides respectively.

  <p>The details of these mappings are provided below.

<h3 id="dimension-mapping">
Dimensional Mapping</h3>

<!--
  <p>Properties that are named in terms of the x and y axes are
    logical with respect to the block flow direction rather than absolute
    with respect to the page. Specifically:

  <ul>
    <li>The ''repeat-x'' keyword of 'background-repeat' tiles in the
      inline dimension of the element, which is not necessarily the
      horizontal dimension. [[!CSS2]] [[!CSS3BG]]
    <li>The ''repeat-y'' keyword of 'background-repeat' tiles in the
      block flow dimension of the element, which is not necessarily
      the vertical dimension. [[!CSS2]] [[!CSS3BG]]
    <li>The 'overflow-x' property controls overflow in the inline
      dimension of the element. [[!CSS3UI]]
    <li>The 'overflow-y' property controls overflow in the block
      flow dimension of the element. [[!CSS3UI]]
  </ul>
-->

  <p>Certain properties behave logically as follows:
  <ul>
    <li>The first and second values of the 'border-spacing' property
      represent spacing between columns and rows respectively, not
      necessarily the horizontal and vertical spacing respectively.
      [[!CSS2]]
    <li>The 'line-height' property always refers to the logical
      height. [[!CSS2]]
  </ul>

  <p>The height properties ('height', 'min-height', and 'max-height')
    refer to the physical height, and the width properties ('width',
    'min-width', and 'max-width') refer to the physical width. However,
    the rules used to calculate box dimensions and positions are logical.

  <p>For example, the calculation rules in
    <a href="https://www.w3.org/TR/CSS2/visudet.html#Computing_widths_and_margins">CSS2.1 Section 10.3</a>
    are used for the inline dimension measurements:
    they apply to the <a>inline size</a> (which could be either the physical width or physical height)
    and to the <a>inline-start</a> and <a>inline-end</a> margins, padding, and border.
    Likewise the calculation rules in
        <a href="https://www.w3.org/TR/CSS2/visudet.html#Computing_heights_and_margins">CSS2.1 Section 10.6</a>
    are used in the block dimension:
    they apply to the <a>block size</a>
    and to the <a>block-start</a> and <a>block-end</a> margins, padding, and border. [[!CSS2]]

  <p>As a corollary, percentages on the margin and padding properties,
    which are always calculated with respect to the containing block
    width in CSS2.1, are calculated with respect to the <em><a>inline size</a></em>
    of the containing block in CSS3.

<h3 id="orthogonal-flows">
Orthogonal Flows</h3>


  <div class="note">
    We appreciate feedback in general,
    but we are particularly interested in feedback
    on this particularly complicated section.
  </div>

  <p>When a box has a different 'writing-mode' from its
    containing block two cases are possible:

  <ul>
    <li>The two writing modes are parallel to each other. (For example,
      ''vertical-rl'' and ''vertical-lr'').</li>
    <li>The two writing modes are perpendicular to each other. (For
      example, ''horizontal-tb'' and ''vertical-rl'').</li>
  </ul>

  <p>
    When a box has a writing mode that is perpendicular to its containing block
    it is said to be in, or establish, an <dfn export lt="establish an orthogonal flow | orthogonal flow | orthogonal">orthogonal flow</dfn>.

  <p>
    To handle this case, CSS layout calculations are divided into
    two phases: sizing a box, and positioning the box within its flow.

  <ul>
    <li>
      In the sizing phase—calculating the width and height of the
      box—the dimensions of the box and the containing block
      are mapped to the <a>inline size</a> and <a>block size</a> and calculations are performed
      accordingly using the writing mode of
      the box establishing the <a>orthogonal flow</a>.
    <li>
      In the positioning phase—calculating the positioning offsets,
      margins, borders, and padding—the dimensions of the box and
      its containing block are mapped to the <a>inline size</a> and <a>block size</a>
      and calculations are performed according to the writing mode of the
      <em>containing block</em> of the box establishing the <a>orthogonal flow</a>.
  </ul>

  <p>Since ''margin/auto'' margins are resolved consistent with the containing
    block's writing mode, a box establishing an <a>orthogonal flow</a> can,
    once sized, be aligned or centered within its containing block just
    like other block-level boxes by using auto margins.

  <div class='example'>
    <div class="sidefigure">
      <p><img alt="Diagram of a vertical flow box appearing in between two horizontal flow boxes."
              src="images/orthogonal.svg"
              width=180>
      <p class="caption">An example of orthogonal flow</p>
    </div>

    <p>
      For example, if a vertical block is placed inside a horizontal block,
      then when calculating the physical height (which is the <a>inline size</a>)
      of the child block the physical height of the parent block is used
      as the child's containing block <a>inline size</a>,
      even though the physical height is the <a>block size</a>, not the <a>inline size</a>,
      of the parent block.

    <p>
      On the other hand,
      because the containing block is in a horizontal writing mode,
      the vertical margins on the child participate in margin-collapsing,
      even though they are in the <a>inline-axis</a> of the child,
      and horizontal auto margins will expand to fill the containing block,
      even though they are in the <a>block-axis</a> of the child.
  </div>

  <div class="note" id="orthogonal-shrink-to-fit">
    Note that this section requires that
    when a child box auto-sized in its block axis
    establishes an orthogonal flow,
    the used block size of the child
    is calculated to fit its content;
    and this resulting content-based size
    is used as input to the <a>inline-axis</a>
    [=min-content size=] and [=max-content size=] of the parent.
  <p>
    This means that when applying shrink-to-fit formula to a box
    such as an inline-block, float, or table-cell,
    if its child establishes an orthogonal flow,
    the calculation dependency must be changed so that
    the sizing phase of the child runs first and
    its used <a>block size</a> becomes an input to the <a>inline-size</a> shrink-to-fit formula of the parent.
  </div>

<h4 id="orthogonal-auto">
Available Space of Orthogonal Flows</h4>

  <p>It is common in CSS for a containing block to have a definite <a>inline size</a>,
    but not a definite <a>block size</a>.
    This typically happens in CSS2.1
    when a containing block has an ''height/auto'' height,
    for example: its width is given by the calculations in
    <a href="https://www.w3.org/TR/CSS2/visudet.html#blockwidth">10.3.3</a>,
    but its <a>block size</a> depends on its contents.
    In such cases the <a>available inline space</a> is defined
    as the <a>inline size</a> of the containing block;
    but the <a>available block space</a>,
    which would otherwise be the <a>block size</a> of the containing block,
    is infinite.

  <p>Putting a box in an <a>orthogonal flow</a> can result in the opposite:
    for the box’s <a>available block space</a> to be definite,
    but its <a>available inline space</a> to be indefinite.
    In such cases a percentage of the containing block’s <a>inline size</a> cannot be defined,
    and <a>inline axis</a> computations cannot be resolved.
    In these cases,
    an additional [=fallback size=] is used
    in place of the <a>available inline space</a>
    for calculations that require a definite <a>available inline space</a>:
    this size is the smallest of
    <ul>
      <li>the size represented by
          the containing block’s inner <a>max size</a> (if that is fixed)
          floored by its inner <a>min size</a> (if that is fixed)
      <li>the nearest ancestor <a>scrollport</a>’s inner size if that is fixed,
          else / capped by its inner <a>max size</a> if that is fixed,
          floored by its inner <a>min size</a> if that is fixed
          <!-- https://lists.w3.org/Archives/Public/www-style/2014Dec/0301.html -->
      <li>the initial containing block’s size
    </ul>

  <p>See [[!css-sizing-3]] for further details on CSS sizing terminology and concepts.

<h4 id="orthogonal-layout">
Auto-sizing Orthogonal Flow Roots</h4>

  The [=inline-axis=] [=automatic size=] of a [=block-level=] or [=block container=] [=orthogonal flow=]
  (i.e. the size used when its [=preferred size property=] is ''width/auto'')
  is calculating as its [=fit-content size=], i.e.
  <code>min([=max-content inline size=], max([=min-content inline size=], [=stretch-fit inline size=])</code>,
  where the [=available space=] used to calculate the [=stretch-fit inline size=] is
  either the size of the [=containing block=] if that is [=definite=],
  or else the [=fallback size=] as defined [[#orthogonal-auto|above]].

  The [=automatic sizing=] of orthogonal [=multi-column containers=]
  (in both axes)
  and of other [=display types=] not mentioned above
  is not defined in this specification.

  Note: See also <a href="https://www.w3.org/TR/css-writing-modes-4/#auto-multicol">CSS Writing Modes Level 4</a>.

<h4 id="orthogonal-pagination">
Fragmenting Orthogonal Flows</h4>

  <p><em>This section is informative.</em></p>

  <p>With regards to fragmentation, the rules in CSS2.1 still hold in
    vertical writing modes and orthogonal flows: break opportunities
    do not occur inside line boxes, only between them.
    UAs that support [[!CSS3COL]] may break in the (potentially zero-width)
    gap between columns, however.

  <p>Note that if content spills outside the pagination stream
    established by the root element, the UA is not required to print
    such content. Authors wishing to mix writing modes with long streams
    of text are thus encouraged to use CSS columns to keep all content
    flowing in the document's pagination direction.

  <div class="note">
    <p>In other words, if your document would require two scrollbars on
    the screen it probably won't all print. Fix your layout, e.g. by
    using <a href="https://www.w3.org/TR/css3-multicol/">columns</a> so
    that it all scrolls (and therefore paginates) in one direction if
    you want to make sure it'll all print. T-shaped documents tend not
    to print well.
  </div>

<h3 id="logical-direction-layout">
Flow-Relative Mappings</h3>

  <p>Flow-relative directions are calculated with respect to
    the writing mode of the <em>containing block</em> of the
    box and used to abstract layout rules related to the
    box properties (margins, borders, padding) and any properties
    related to positioning the box within its containing block
    ('float', 'clear', 'top', 'bottom', 'left', 'right', 'caption-side').
    For inline-level boxes, the writing mode of the <em>parent
    box</em> is used instead.
    (The left/right/top/bottom-named properties and values themselves are still mapped physically;
    with a special exception made for 'caption-side',
    whose ''caption-side/top''/''top-outside'' and ''caption-side/bottom''/''bottom-outside'' values
    are associated to the <a>block-start</a> and <a>block-end</a> sides of the table, respectively.)

  <p>For example, the margin that is dropped when a box's inline
    dimension is
    <a href="https://www.w3.org/TR/CSS2/visudet.html#blockwidth">over-constrained</a>
    is the end margin as determined by the writing mode of the
    containing block.

  <p>The <a href="https://www.w3.org/TR/CSS2/box.html#collapsing-margins">margin
    collapsing rules</a> apply exactly with the <em><a>block-start</a>
    margin</em> substituted for the top margin and the
    <em><a>block-end</a> margin</em> substituted for the bottom margin.
    Similarly the <a>block-start</a> padding and border are substituted
    for the top padding and border, and the <a>block-end</a> padding and
    border substituted for the bottom padding and border.
    Note this means only <a>block-start</a> and <a>block-end</a> margins ever collapse.

  <p>Flow-relative directions are calculated with respect to
    the writing mode of the box and used to abstract layout
    related to the box's contents:

  <ul>
    <li>The initial value of the 'text-align' property
      aligns to the <a>start</a> edge of the line box.
    <li>The 'text-indent' property indents from the <a>start</a>
      edge of the line box.
    <li>For tables, the ordering of columns begins on the <a>inline-start</a>
      side of the table, and the ordering of rows begins on the
      <a>block-start</a> side of the table.
  </ul>

<h3 id="line-mappings">
Line-Relative Mappings</h3>

  <p>The <a>line-relative directions</a> are
    <a>over</a>,
    <a>under</a>,
    <a>line-left</a>, and
    <a>line-right</a>.
    In an <abbr title="left-to-right">LTR</abbr> ''horizontal-tb'' writing mode,
    they correspond to the
    top, bottom, left, and right directions, respectively.

  <p>The <a>line-right</a> and <a>line-left</a> directions are calculated
    with respect to the writing mode of the box and used
    to interpret the <css>left</css> and <css>right</css> values of the
    following properties:
  <ul>
    <li>the 'text-align' property [[!CSS2]]
  </ul>

  <p>The <a>line-right</a> and <a>line-left</a> directions are calculated
    with respect to the writing mode of the <em>containing
    block</em> of the box and used to interpret the <css>left</css>
    and <css>right</css> values of the following properties:
  <ul>
    <li>the 'float' property [[!CSS2]]
    <li>the 'clear' property [[!CSS2]]
    <li>the 'caption-side' property [[!CSS2]]
  </ul>

  <p>The <a>over</a> and <a>under</a> directions are calculated with respect to
    the writing mode of the box and used to define the
    interpretation of the "top" (over) and "bottom" (under)
    sides of the line box as follows:

  <ul>
    <li>For the 'vertical-align' property,
      the "top" of the line box is its <a>over</a> edge;
      the "bottom" of the line box is its under edge.
      Positive length and percentage values
      shift the baseline towards the <a>line-over</a> edge. [[!CSS2]]
    <li>For the 'text-decoration' property,
      the underline is drawn on the <a>under</a> side of the text;
      the overline is drawn on the <a>over</a> side of the text. [[!CSS2]]
      <span class="note">Note that the CSS Text Decoration Module defines
      this in more detail and provides additional controls for
      controlling the position of underlines and overlines.
      [[CSS3-TEXT-DECOR]]</span>
  </ul>

<h3 id="physical-only">
Purely Physical Mappings</h3>

  <p>The following values are purely physical in their definitions
    and do not respond to changes in writing mode:

  <ul>
    <li>the <l spec=css-shapes-1>''rect()''</l> notation of the 'clip' property [[!CSS2]]
    <li>the background properties [[!CSS2]] [[!CSS3BG]]
    <li>the border-image properties [[!CSS3BG]]
    <li>the offsets of the 'box-shadow' and 'text-shadow' properties
  </ul>

<!--
<h3 id="html-attributes">HTML Attributes</h3>

  <p>This section defines the mapping of HTML presentational attributes
    in CSS. This section is normative for user agents supporting HTML
    in addition to the 'writing-mode' property. [[!HTML40]] [[!HTML5]]

  <h4 id="width-height-attributes">The <code>width</code> and <code>height</code> attributes</h4>

  <p>The HTML <code>width</code> and <code>height</code> attributes refer
    to the physical width and height for elements that that are replaced,
    i.e.
    <code>&lt;applet&gt;</code>,
    <code>&lt;embed&gt;</code>,
    <code>&lt;iframe&gt;</code>,
    <code>&lt;img&gt;</code>,
    <code>&lt;object&gt;</code>,
    <code>&lt;canvas&gt;</code>,
    and
    <code>&lt;video&gt;</code>

  <p>Form elements contain text, therefore their contents should be
    affected by writing mode, in which case these attributes refer to the
    <em>logical</em> width and height. The UA may, however, choose not
    to rotate nor flip these elements in vertical writing modes if it is not
    capable, and in that case, these attributes remain physical.</p>
    <p class="issue">when not to rotate form elements/MathML,
      should treat them as images (always upright)
      or to force writing-mode to always calculate to horizontal-tb?</p>

  <p>On table-related elements (<code>&lt;table&gt;</code>, <code>&lt;colgroup&gt;</code>,
    <code>&lt;col&gt;</code>, <code>&lt;tr&gt;</code>, <code>&lt;th&gt;</code>,
    <code>&lt;td&gt;</code>) the <code>width</code> and <code>height</code>
    attributes are always logical.

  <p>The <code>size</code> attribute of the <code>&lt;hr&gt;</code> element
    is also logical (refers to the logical height).

  <h4 id="alignment-attributes">Alignment, Float and Clear Attributes</h4>

  <p>The following attributes behave the same way as their corresponding
    CSS properties:</p>

  <ul>
    <li><code>align</code> as 'float' or 'text-align'</li>
    <li><code>clear</code> as 'clear'</li>
    <li><code>valign</code> as 'vertical-align'</li>
  </ul>

  <h4 id="spacing-attributes">Spacing Attributes</h4>

  <p>The following attributes are logical and, as margins, are logical
    with respect to the writing mode of the <em>parent</em> element.</p>

  <ul>
    <li><code>hspace</code> as inline-start and inline-end margins</li>
    <li><code>vspace</code> as block-start and block-end margins</li>
    <li>marginwidth</li>
    <li>marginheight</li>
  </ul>
-->

<h2 id="principal-flow">
The Principal Writing Mode</h2>

  <p>The <dfn export>principal writing mode</dfn> of the document
  is determined by the [=used value|used=] 'writing-mode', 'direction', and 'text-orientation' values
  of the root element.
  This writing mode is used, for example,
  to determine the direction of scrolling
  and the default <a>page progression</a> direction.

  <p>As a special case for handling HTML documents,
  if the root element has a <{body}> child element [[!HTML]]
  <ins cite="#correction-display-none-propagation">whose 'display' value is not ''none''</ins>,
  the [=used value=] of the of 'writing-mode' and 'direction' properties on root element
  are taken
  from the [=computed value|computed=] 'writing-mode' and 'direction'
  of the first such child element instead of from the root element's own values.
  The UA <em>may</em> also propagate the value of 'text-orientation' in this manner.
  Note that this does not affect the computed values of 'writing-mode', 'direction', or 'text-orientation'
  of the root element itself.

  Note: Using [=containment=] disables
  this special handling of the HTML <{body}> element.
  See the [[CSS-CONTAIN-1#contain-property]] for details.

  <div class=correction id=correction-display-none-propagation>
    <span class=marker>Candidate Correction 1:</span>
    Specify that the <{body}> element is ignored for determining the [=principal writing mode=]
    if it has ''display: none''.
    <a href="https://github.com/w3c/csswg-drafts/issues/3779">Issue 3779</a>
    <!-- Say that we have tests for this and point to them once we have tests for this. -->
  </div>

  Note: Propagation is done on used values rather than computed values
  to avoid disrupting other aspects of style computation,
  such as [=inheritance=],
  [[css-logical-1#box|logical property mapping logic]],
  or [[css-values-4#lengths|length value computation]].

<h3 id="icb">
Propagation to the Initial Containing Block</h3>

  <p>The <a>principal writing mode</a> is propagated to
  the <a>initial containing block</a>
  and to the viewport,
  thereby affecting the layout of the root element
  and the scrolling direction of the viewport.

<h3 id="page-direction">
Page Flow: the page progression direction</h3>

  <p>In [=paged media=] CSS classifies all pages as either left or right pages.
  The <a>page progression</a> direction (see [[CSS3PAGE]]),
  which determines whether the left or right page in a spread is first in the flow
  and whether the first page is by default a left or right page,
  depends on the <a>principal writing mode</a> as follows:

  <table class="data">
    <thead>
      <tr>
        <th><a>principal writing mode</a>
        <th><a>page progression</a>
    <tbody>
      <tr>
        <td>''horizontal-tb'' and ''ltr''
        <td>left-to-right
      <tr>
        <td>''horizontal-tb'' and ''rtl''
        <td>right-to-left
      <tr>
        <td>''vertical-rl''
        <td>right-to-left
      <tr>
        <td>''vertical-lr''
        <td>left-to-right
  </table>

  Note: Unless otherwise overridden,
  the first page of a document begins on the second half of a spread,
  e.g. on the right page in a left-to-right page progression.

<h2 id="text-combine">
Glyph Composition</h2>

<span id="text-combine-horizontal"></span>
<h3 id="text-combine-upright">
Horizontal-in-Vertical Composition: the 'text-combine-upright' property</h3>

  <pre class='propdef'>
  Name: text-combine-upright
  Value: none | all
  Initial: none
  Applies to: [=inline boxes=] and text
  Inherited: yes
  Percentages: n/a
  Computed value: specified keyword
  Animation type: not animatable
  Canonical order: n/a
  </pre>

  <p>This property specifies the combination of multiple <a>typographic character units</a>
    into the space of a single <a>typographic character unit</a>.
    If the combined text is wider than 1em, the UA must fit the contents within 1em, see below.
    The resulting composition is treated as a single upright glyph for the purposes of layout and decoration.
    This property only has an effect in vertical writing modes. Values have the following meanings:

  <dl>
    <dt><dfn value for=text-combine-upright>none</dfn>
    <dd>No special processing.</dd>

    <dt><dfn value for=text-combine-upright>all</dfn>
    <dd>Attempt to typeset horizontally
      all consecutive <a>typographic character units</a> within the box or text run
      such that they take up the space of a single <a>typographic character unit</a>
      within the vertical line box.
  </dl>

  <div class="example">
    <p>In East Asian documents, the ''text-combine-upright'' effect is often
      used to display Latin-based strings such as components of a date or
      letters of an initialism, always in a horizontal writing mode
      regardless of the writing mode of the line:</p>

    <div class="figure">
      <p><img alt="Diagram of tate-chu-yoko, showing the two digits of a date
                   set halfwidth side-by-side in a vertical column of text"
              src="images/tate-chu-yoko.png">
      <p class="caption">Example of horizontal-in-vertical <i lang="ja" lt=''>tate-chu-yoko</i></p>
    </div>

    <p>The figure is the result of the rules</p>
    <pre>
<!-- -->date span { text-combine-upright: all; }
    </pre>
    <p>and the following markup:</p>
    <pre>
<!-- -->&lt;date&gt;&#x5E73;&#x6210;&lt;span>20&lt;/span>&#x5E74;4&#x6708;&lt;span>16&lt;/span>&#x65E5;&#x306B;&lt;/date&gt;
    </pre>

    <p>In Japanese, this effect is known as <i lang="ja" lt=''>tate-chu-yoko</i>.
  </div>

  <p class="note">
    Future levels of CSS Writing Modes will introduce values
    to automatically detect commonly-affected sequences.
    For example, <a href="http://www.w3.org/TR/css-writing-modes-4/">CSS Writing Modes Level 4</a>
    introduces the ''text-combine-upright/digits'' value to combine sequences of digits.

<h4 id="text-combine-runs">
Text Run Rules</h4>

  <p>To avoid complexity in the rendering and layout,
    'text-combine-upright' can only combine plain text:
    consecutive <a>typographic character units</a>
    that are not interrupted by a box boundary.

  <p>However, because the property inherits,
    the UA should ensure that the contents of the box effecting the combination
    are not part of an otherwise-combinable sequence
    that happens to begin or end outside the box;
    if so, then the text is laid out normally,
    as if 'text-combine-upright' were ''text-combine-upright/none''.

  <div class="example">
    <p>For example, given the rule
    <pre>tcy { text-combine-upright: all; }</pre>
    <p>if the following markup were given:
    <pre>&lt;tcy&gt;12&lt;span>34&lt;/span>&lt;/tcy></pre>
    <p>no text would combine.
  </div>

<h4 id="text-combine-layout">
Layout Rules</h4>

  <p>When combining text as for ''text-combine-upright: all'',
    the glyphs of the combined text are <a>bidi-isolated</a>
    and composed horizontally
    (ignoring 'letter-spacing' and any forced line breaks,
    but using the specified font settings),
    similar to the contents of an ''inline-block'' box
    with a [=horizontal writing mode=] and a 'line-height' of ''1em''.
    Processing of [=document white space=] included in the combined text
    is not defined in this level.
    The effective size of the composition is assumed to be 1em square;
    anything outside the square is not measured for layout purposes.
    The UA should center the glyphs horizontally and vertically within the measured 1em square.

  <p>The baseline of the resulting composition must be chosen such that the square is centered
    between the text-over and text-under baselines of its parent inline box prior to any baseline alignment shift ('vertical-align').
    For bidi reordering, the composition is treated the same as a <a>typographic character unit</a> with ''text-orientation: upright''.
    For line breaking before and after the composition, it is treated as a regular inline with its actual contents.
    For other text layout purposes,
    e.g. emphasis marks, text-decoration, spacing,
    etc. the resulting composition is treated as a single glyph
    representing the Object Replacement Character U+FFFC.

<h4 id="text-combine-compression">
Compression Rules</h4>

  <p>The UA must ensure that the combined advance width of the composition
    fits within 1em by compressing the combined text if necessary.
    (This does not necessarily mean that the glyphs will fit within 1em,
    as some glyphs are designed to draw outside their geometric boundaries.)
    OpenType implementations <em>must</em> use width-specific variants
    (OpenType features <code>hwid</code>/<code>twid</code>/<code>qwid</code>;
    other glyph-width features such as <code>fwid</code> or <code>pwid</code> are not included)
    to compress text
    in cases where those variants are available for all <a>typographic character units</a> in the composition.
    Otherwise, the UA may use any means to compress the text,
    including substituting half-width, third-width, and/or quarter-width glyphs provided by the font,
    using other font features designed to compress text horizontally,
    scaling the text geometrically,
    or any combination thereof.

  <div class="example">
    <p>For example, a simple OpenType-based implementation might compress the text as follows:
    <ol>
      <li>Enable 1/<var>n</var>-width glyphs for combined text of <var>n</var> <a>typographic character units</a>
        (i.e. use OpenType <code>hwid</code> for 2 <a>typographic character units</a>, <code>twid</code> for 3 <a>typographic character units</a>, etc.)
        if the number of <a>typographic character units</a> &gt; 1.
        Note that the number of <a>typographic character units</a> &ne; number of Unicode codepoints!
      <li>If the result is wider than 1em, horizontally scale the result to 1em.
    </ol>
    <p>A different implementation that utilizes OpenType layout features
    might compose the text first with normal glyphs to see if that fits,
    then substitute in half-width or third-width forms as available and necessary,
    possibly adjusting its approach or combining it with scaling operations
    depending on the available glyph substitutions.
  </div>

  <p>In some fonts, the ideographic glyphs are given a compressed design
    such that they are 1em wide but shorter than 1em tall.
    To accommodate such fonts, the UA may vertically scale the composition
    to match the advance height of 水 U+6C34
    as rendered according to the specified font settings.
    In such a case the resulting composition assumes
    the advance height of 水 U+6C34 rather than 1em.
  <!-- 水 U+6C34 was chosen because it is a very basic character common to
    all Han-based scripts, so would have to appear in any usable ideographic
    font; and its shape is very full in both dimensions, so it would be
    unlikely to be shortened in a proportional font -->

<h5 id="text-combine-fullwidth">
Full-width Characters</h5>

  <p>In order to preserve typographic color when compressing the text to 1em,
    when the combined text consists of more than one <a>typographic character unit</a>,
    then any full-width <a>typographic character units</a>
    should first be converted to their non-full-width equivalents
    by reversing the algorithm defined for ''text-transform: full-width'' in [[!CSS-TEXT-3]]
    before applying other compression techniques.

  <p class="note">
    Properties that affect glyph selection,
    such as the <a property>font-variant</a> and <a property>font-feature-settings</a> properties defined in [[CSS3-FONTS]],
    can potentially affect the selection of variants for characters included in combined text runs.
    Authors are advised to use these properties with care when 'text-combine-upright' is also used.

Privacy Considerations {#priv}
==============================

  This specification introduces no new privacy leaks.

Security Considerations {#sec}
==============================

  This specification introduces no new security considerations
  beyond "implement it correctly".


<h2 class="no-num" id="changes">Changes</h2>

  See also <a href="https://www.w3.org/TR/2019/REC-css-writing-modes-3-20191210/#changes">list of changes during Candidate Recommendation</a>.

  <h3 class="no-num" id="changes-2019">
  Changes since the <a href="https://www.w3.org/TR/2019/REC-css-writing-modes-3-20191210/">December
  2019 CSS Writing Modes Module Level 4 Recommendation</a></h3>

  <ul class="informative">
    <li>Clarified that a ''display: none'' <{body}> element does not influence the [=principal writing mode=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/3779">Issue 3779</a>)
    <li>Updated “Applies to” line for the 'text-orientation' and 'text-combine-upright' properties
      to clarify that they apply to text
      (since certain effects like ''display: contents'' can strip the box itself).
    <li>
      Clarified that the [=central baseline=] is the [=ideographic central baseline=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/5177">Issue 5177</a>)
    <li>Reshuffled text in [[#intro]] and improved cross-linking.
  </ul>

<h2 class="no-num" id="acknowledgements">
Acknowledgements</h2>

<p>
L. David Baron,
Brian Birtles,
James Clark,
John Daggett,
Nami Fujii,
Daisaku Hataoka, Martin Heijdra, Laurentiu Iancu,
Richard Ishida,
Jonathan Kew,
Yasuo Kida, Tatsuo Kobayashi, Toshi Kobayashi,
Ken Lunde,
Shunsuke Matsuki,
Nat McCully, Eric Muller,
Paul Nelson, Kenzou Onozawa,
Chris Pratley,
Xidorn Quan,
Florian Rivoal,
Dwayne Robinson,
Simon Sapin,
Marcin Sawicki,
Dirk Schulze,
Hajime Shiozawa,
Alan Stearns,
Michel Suignard,
Takao Suzuki,
Gérard Talbot,
Masataka Yakura,
Taro Yamamoto,
Steve Zilles</p>

<h2 class="no-num" id="script-orientations">Appendix A:
Vertical Scripts in Unicode</h2>
  <p><em>This section is informative.</em></p>

  <p>This appendix lists the [=vertical-only=] and [=bi-orientational=] scripts in Unicode 6.0
    [[!UNICODE]] and their transformation from horizontal to vertical orientation.
    Any script not listed explicitly is assumed to be <a>horizontal-only</a>.
    The script classification of Unicode characters is given by [[!UAX24]].

  <table class="data">
    <caption>Vertical Scripts in Unicode</caption>
    <thead>
      <tr><th>Code	<th>Name                	<th>Transform (Clockwise)	<th>Vertical Intrinsic Direction
    </thead>
    <tbody>
      <tr><td>Bopo	<td>Bopomofo            	<th>0&deg;  	<th>ttb
      <tr><td>Egyp	<td>Egyptian Hieroglyphs	<th>0&deg;  	<th>ttb
      <tr><td>Hira	<td>Hiragana            	<th>0&deg;  	<th>ttb
      <tr><td>Kana	<td>Katakana            	<th>0&deg;  	<th>ttb
      <tr><td>Hani	<td>Han                 	<th>0&deg;  	<th>ttb
      <tr><td>Hang	<td>Hangul              	<th>0&deg;  	<th>ttb
      <tr><td>Merc	<td>Meroitic Cursive    	<th>0&deg;  	<th>ttb
      <tr><td>Mero	<td>Meroitic Hieroglyphs	<th>0&deg;  	<th>ttb
      <tr><td>Mong	<td>Mongolian           	<th>90&deg; 	<th>ttb
      <tr><td>Ogam	<td>Ogham               	<th>-90&deg;	<th>btt
      <tr><td>Orkh	<td>Old Turkic          	<th>-90&deg;	<th>ttb
      <tr><td>Phag	<td>Phags Pa            	<th>90&deg; 	<th>ttb
      <tr><td>Yiii	<td>Yi                  	<th>0&deg;  	<th>ttb
    </tbody>
  </table>

  <p><strong>Exceptions:</strong>
    For the purposes of this specification, all fullwidth (F) and wide (W) characters
    are treated as belonging to a vertical script,
    and halfwidth characters (H) are treated as belonging to a [=horizontal script=].
    [[!UAX11]]

  <p class="note">Note that for [=vertical-only=] characters (such as Mongolian and Phags Pa letters),
    the glyphs in the Unicode code charts are shown in their vertical orientation.
    In horizontal text, they are typeset in a 90&deg; counter-clockwise
    rotation from this orientation.

  <p class="note">
    Due to limitations in the current feature set of Unicode Technical Report 50 and CSS Writing Modes,
    vertical ''mixed'' typesetting cannot automatically handle either Ogham or Old Turkic.
    For these scripts, ''sideways-lr'' (in <a href="http://www.w3.org/TR/css-writing-modes-4/">CSS Writing Modes Level 4</a>) can be used to typeset passages.
