CSS Ruby Annotation Layout Module Level 1

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-ruby-1/
Latest published version:
https://www.w3.org/TR/css-ruby-1/
Previous Versions:
Test Suites:
https://w3c.github.io/i18n-tests/results/css-ruby
https://wpt.fyi/results/css/css-ruby/
Feedback:
CSSWG Issues Repository
Inline In Spec
Editors:
Elika J. Etemad / fantasai (Apple)
(Google)
Xidorn Quan (Mozilla)
Florian Rivoal (Invited Expert)
Suggest an Edit for this Spec:
GitHub Editor

Abstract

“Ruby”, a form of interlinear annotation, are short runs of text alongside the base text. They are typically used in East Asian documents to indicate pronunciation or to provide a short annotation. This module describes the rendering model and formatting controls related to displaying ruby annotations in CSS.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-ruby” in the title, like this: “[css-ruby] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list www-style@w3.org.

This document is governed by the 18 August 2025 W3C Process Document.

1. Introduction

1.1. What is ruby?

This subsection is not normative.

Ruby is the commonly-used name for a run of text that appears alongside another run of text (referred to as the “base”) and serves as an annotation or a pronunciation guide associated with that run of text.

Hiragana ruby annotations above each kanji in Japanese text
A run of Japanese text with phonetic ruby annotations indicating the pronunciation of each ideograph.

The following figures show two examples of Ruby, a simple case and one with more complicated structure.

In this example, a single annotation is used to annotate a base text consisting of multiple characters.
Example of ruby applied on top of a Japanese expression

Example of ruby used in Japanese (simple case)

In Japanese typography, this case is sometimes called taigo ruby (Japanese: 対語ルビ, i.e. per-word ruby) or group-ruby, because the annotation as a whole is associated with multi-character word (as a whole).

In this second example, two levels of annotations are attached to the base text: the hiragana characters on top refer to the pronunciation of each of the base kanji characters, while the words “Keio” and “University” on the bottom are give the English translation.
Example showing complex ruby with annotation text over and under the base characters

Complex ruby with annotation text over and under the base characters

Notice that to reflect the correct association of hiragana characters and their corresponding Kanji base characters, the spacing within the base-level text is adjusted. (This happens around the fourth Kanji character in the figure above, which has a three-character phonetic gloss.) To avoid variable spacing of the base text in the example above, the hiragana annotations can be styled as a merged annotation, which will look more like the group-ruby example earlier. However because the base-annotation pairings are recorded in the ruby structure, if the text breaks across lines, the annotation characters will stay correctly paired with their respective base characters.

In HTML, ruby structure and markup to represent it is described in the Ruby Markup Extension specification. This module describes the CSS rendering model and formatting controls relevant to ruby layout of such markup.

A more in-depth introduction to Ruby and its formatting can be found in the “What is Ruby“ article [QA-RUBY]. Extensive information about the main ways ruby has traditionally been formatted in Japanese can be found in JIS X-4051 [JIS4051] (in Japanese) and in “Ruby and Emphasis Dots” in Requirements for Japanese Text Layout [JLREQ] (in English and Japanese); Rules for Simple Placement of Japanese Ruby [SIMPLE-RUBY] also describes (in English) one possible approach for Japanese ruby formatting. “Interlinear annotations” in Requirements for Chinese Text Layout [CLREQ] describes the related practices for Chinese typography (in Chinese and English).

1.2. Module interactions

This module extends the inline box model of CSS Level 2 [CSS2] to support ruby.

None of the properties in this module apply to the ::first-line or ::first-letter pseudo-elements; however ruby-position can inherit through ::first-line to affect ruby annotations on the first line.

1.3. Value Definitions

This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & 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 CSS-wide keywords keywords as their property value. For readability they have not been repeated explicitly.

1.4. Diagram conventions

This subsection is not normative.

Many typographical conventions in East Asian typography depend on whether the character rendered is wide (CJK) or narrow (non-CJK). There are a number of illustrations in this document for which the following legend is used:

Symbolic wide-cell glyph representation
Wide-cell glyph (e.g. Han) that is the nth character in the text sequence. They are typically sized to 50% when used as annotations.
Symbolic narrow-cell glyph representation
Narrow-cell glyph (e.g. Roman) which is the nth glyph in the text sequence.

The orientation which the above symbols assume in the diagrams corresponds to the orientation that the glyphs they represent are intended to assume when rendered by the user agent. Spacing between these characters in the diagrams is incidental, unless intentionally changed to make a point.

2. Ruby Box Model

The CSS ruby model is based on the W3C HTML5 Ruby Markup model and the XHTML Ruby Annotation Recommendation [RUBY]. In this model, a ruby structure consists of one or more ruby base elements representing the base (annotated) text, associated with one or more levels of ruby annotation elements representing the annotations. The structure of ruby is similar to that of a table: there are “rows” (the base text level, each annotation level) and “columns” (each ruby base and its corresponding ruby annotations).

Ruby structure arranged as a table,
		          the first “column” containing 上 in a base box with じょう centered below in an annotation box
		          and the second “column” containing 手 in a separate base box with ず centered below in another annotation box.
The Japanese compound word “上手” annotated with its pronunciation “じょうず”. Each syllable is associated individually with its base character.

Sets of consecutive bases and their consecutive annotations are grouped together into ruby segments. Within a ruby segment, a ruby annotation may span multiple ruby bases.

Ruby structure arranged as a table,
		          the first “column” containing 旧 in a base box with jiù centered above in an annotation box,
		          the second “column” containing 金 in a base box with jīn centered above in an annotation box,
		          the third “column” containing 山 in a base box with .shān centered above it in an annotation box,
		          and the name San Francisco centered below the entire phrase in an annotation box that spans all three “columns”.
The Chinese city name “旧金山” annotated with its pronunciation in Pinyin “jiùjīnshān” and its English name “San Francisco”. Each Pinyin syllable is associated individually with its base character, however the English name is associated with the name as a whole.

Note: In HTML, a single <ruby> element may contain multiple ruby segments. (In the XHTML Ruby model, a single <ruby> element can only contain one ruby segment.)

2.1. Ruby-specific display Values

For document languages (such as XML applications) that do not have pre-defined ruby elements, authors must map document language elements to ruby elements; this is done with the display property.

Name: display
New values: ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container

The following new display values assign ruby layout roles to an arbitrary element:

ruby
Specifies that an element generates a ruby container box. (Corresponds to HTML/XHTML <ruby> elements.)
ruby-base
Specifies that an element generates a ruby base box. (Corresponds to HTML/XHTML <rb> elements.)
ruby-text
Specifies that an element generates a ruby annotation box. (Corresponds to HTML/XHTML <rt> elements.)
ruby-base-container
Specifies that an element generates a ruby base container box. (Corresponds to XHTML <rbc> elements; generated as an anonymous box in HTML.)
ruby-text-container
Specifies that an element generates a ruby annotation container box. (Corresponds to HTML/XHTML <rtc> elements.)

Authors using a language (such as HTML) that supports dedicated ruby markup should use that markup rather than styling arbitrary elements (like <span>) with ruby display values. Using the correct markup ensures that screen readers and non-CSS renderers can interpret the ruby structures.

Note: Replaced elements with a display value of ruby-base, ruby-text, ruby-base-container, and ruby-text-container are treated as inline-level boxes, as per CSS Display 3 § 2.4 Layout-Internal Display Types: the table-* and ruby-* keywords; replaced elements with a display value of ruby or inline ruby behave according to their outer display type, as per CSS Display 3 § 2.1 Outer Display Roles for Flow Layout: the block, inline, and run-in keywords. (See also § 2.1.2 Non-Inline Ruby.)

2.1.1. The Ruby Formatting Context

Ruby containers are non-atomic inline-level boxes. Like regular inline boxes (see CSS Inline Layout 3 § 2 Inline Layout Model), they break across lines, and their containing block is the nearest block container ancestor. And just as the contents of an inline box participate in the same inline formatting context that contains the inline box itself, a ruby container and its base-level contents participate in the same inline formatting context that contains the ruby container itself.

However ruby containers also establish a ruby formatting context that builds further structure around their segment of the inline formatting context in order to host their annotations. Note: this formatting context is not an independent formatting context. Ruby bases, ruby annotations, ruby base containers, and ruby annotation containers are internal ruby boxes: like internal table elements, they have specific roles in ruby layout, and participate in their ruby container’s ruby formatting context. In addition to their role in the ruby formatting context, ruby bases simultaneously participate in the same base-level inline formatting context as the ruby container, while ruby annotations participate in separate annotation-level inline formatting contexts established by the ruby container.

As with the contents of inline boxes, the containing block for the contents of a ruby container (and all its internal ruby boxes) is the containing block of the ruby container. So floats, for example, are trapped by the ruby container’s containing block, not any of the ruby box types.

2.1.2. Non-Inline Ruby

If an element has an inner display type of ruby and an outer display type other than inline, then it generates two boxes: a principal box of the required outer display type type, and an inline-level ruby container. All properties specified on the element apply to the principal box (and if inheritable, inherit to the ruby container box). This allows styling the element as a block, while correctly maintaining the internal ruby structure.

Note: Absolute positioning or floating an element causes its display value to compute to a block-level equivalent. (See [CSS-DISPLAY-3] or [CSS2] section 9.7.) For the internal ruby display types, this causes their display value to compute to block.

2.2. Anonymous Ruby Box Generation

The CSS model does not require that the document language include elements that correspond to each of these components. Missing parts of the structure are implied through the anonymous box generation rules similar to those used to normalize tables. [CSS2]

  1. Inlinify block-level boxes: Any in-flow boxes directly contained by a ruby container, ruby base container, ruby annotation container, ruby base box, or ruby annotation box are “inlinified” per [CSS-DISPLAY-3]), and their display value computed accordingly, so that they contain only inline-level content. For example, the display property of an in-flow element with display: block parented by an element with display: ruby-text computes to inline-block.
  2. Generate anonymous ruby containers: Any consecutive sequence of improperly-contained ruby base containers, ruby annotation containers, ruby bases, and/or ruby annotations (and any intervening white space) is wrapped in an anonymous ruby container. For the purpose of this step:
  3. Wrap misparented inline-level content: Any consecutive sequence of text and inline-level boxes directly parented by a ruby container or ruby base container is wrapped in an anonymous ruby base. Similarly, any consecutive sequence of text and inline-level boxes directly parented by a ruby annotation container is wrapped in an anonymous ruby annotation. (For this purpose, misparented internal table elements are treated as inline-level content since, being parented by ruby boxes, they will be ultimately wrapped by an inline-level table wrapper box.)

    However, if an anonymous box so constructed contains only white space, it is considered intra-ruby white space and is either discarded or preserved as described below.

  4. Trim leading/trailing white space: Any intra-ruby white space that is not the sole in-flow child of its parent and is the first or last in-flow child of a ruby container, ruby annotation container, or ruby base container is removed, as if it had display: none
  5. Remove inter-level white space: Any intra-ruby white space whose immediately adjacent in-flow siblings match one of the patterns below is inter-level white space and is removed, as if it had display: none.
    Previous box Next box
    any ruby annotation container
    not ruby annotation ruby annotation
  6. Interpret intra-level white space: Any intra-ruby white space box whose immediately adjacent in-flow siblings match one of the patterns below is assigned the box type and subtype defined in the table below:
    Previous box Next box Box type Subtype
    ruby base ruby base ruby base inter-base white space
    ruby annotation ruby annotation ruby annotation inter-annotation white space
    ruby annotation or ruby annotation container ruby base or ruby base container ruby base inter-segment white space
    ruby base or ruby base container ruby base container
    ruby base container ruby base or ruby base container
    The intra-level white space boxes defined above are treated specially for pairing and layout. See below.
  7. Suppress line breaks: Convert all forced line breaks inside ruby annotations (regardless of white-space value) as defined for collapsible segment breaks in CSS Text Level 3 § 4.1.2.

    The goal of this is to simplify the layout model by suppressing any line breaks within ruby annotations. Alternatively we could try to define some kind of acceptable behavior for them.

  8. Generate anonymous level containers: Any consecutive sequence of ruby bases and inter-base white space (and not inter-segment white space) not parented by a ruby base container is wrapped in an anonymous ruby base container. Similarly, any consecutive sequence of ruby annotations and inter-annotation white space not parented by a ruby annotation container is wrapped in an anonymous ruby annotation container.

Once all ruby layout structures are properly parented, the UA can start to associate bases with their annotations.

Note: The UA is not required to create any of these anonymous boxes (or the anonymous empty intra-level white space boxes in § 2.3 Annotation Pairing) in its internal structures, as long as pairing and layout behaves as if they existed.

The following markup diagram representing the various boxes shows where intra-ruby white space is preserved or discarded:
<ruby>×<rbc>×<rb></rb><rb></rb>×</rbc><rtc>×<rt></rt><rt></rt>×</rtc><rbc>×<rb></rb></rtc>×</ruby>
where

2.3. Annotation Pairing

Annotation pairing is the process of associating ruby annotations with ruby bases. Each ruby annotation is associated with one or more ruby bases, and is said to span those bases. (A ruby annotation that spans multiple bases is called a spanning annotation.)

A ruby base can be associated with only one ruby annotation per annotation level. However, if there are multiple annotation levels, it can be associated with multiple ruby annotations.

Once pairing is complete, ruby columns are defined, each represented by a single ruby base and one ruby annotation (possibly an empty, anonymous one) from each interlinear annotation level in its ruby segment.

2.3.1. Segment Pairing and Annotation Levels

A ruby structure is divided into ruby segments, each consisting of a single ruby base container followed by one or more ruby annotation containers. Each ruby annotation container in a ruby segment represents one level of annotation for the base text: the first one represents the first level of annotation, the second one represents the second level of annotation, and so on. The ruby base container represents the base level. The ruby base container in each segment is thus paired with each of the ruby annotation containers in that segment.

In order to handle degenerate cases, some empty anonymous containers are assumed:

Inter-segment white space is effectively a ruby segment of its own.

2.3.2. Unit Pairing and Spanning Annotations

Within a ruby segment, each ruby base in the ruby base container is paired with one ruby annotation from each ruby annotation container in its ruby segment.

If a ruby annotation container contains only a single, anonymous ruby annotation, then that ruby annotation is paired with (i.e. spans across) all of the ruby bases in its ruby segment.

Otherwise, each ruby annotation is paired, in document order, with the corresponding ruby base in that segment. If there are not enough ruby annotations in a ruby annotation container, the remaining ruby bases are paired with anonymous empty annotations inserted at the end of the ruby annotation container. If there are not enough ruby bases, any remaining ruby annotations pair with empty, anonymous bases inserted at the end of the ruby base container.

If an implementation supports ruby markup with explicit spanning (e.g. XHTML Complex Ruby Annotations), it must adjust the pairing rules to pair spanning annotations to their bases appropriately.

Intra-level white space does not participate in standard annotation pairing. However, if the immediately-adjacent ruby bases or ruby annotations are paired

The following diagram shows the pairing of regular base and annotation boxes as well as the pairing of intra-ruby white space (represented as ws):
|[  s p a n n i n g   a n n o t a t i o n ]|
|[ a1 ]|[ws]|[ a2 ]|[  ]|[ a3 ]|[ws]|[ a4 ]|
|[ b1 ]|[ws]|[ b2 ]|[ws]|[ b3 ]|[  ]|[ b4 ]|

Blue brackets ([ ]) represent base boxes, red brackets ([ ]) represent annotation boxes, gray bars (|) represent the limits of ruby columns, [ws] represents intra-ruby white space, and [] represents an empty anonymous base or annotation automatically generated to pair with intra-ruby white space in another level. Ruby containers, base containers, and annotation containers are omitted.

2.4. Hiding Annotations: visibility: collapse and auto-hidden ruby

A ruby annotation whose visibility is collapse is a hidden annotation. Additionally, if a ruby annotation has the exact same text content as its base, it is automatically hidden (auto-hidden) by the UA.

Hiding a ruby annotation does not affect annotation pairing. However the hidden annotation is not visible, and it has no impact on layout other than to separate adjacent sequences of ruby annotation boxes within its level, as if they belonged to separate segments and the hidden annotation’s base were not a ruby base but an intervening inline.

Auto-hiding allows correct inlined display of annotations for Japanese words that are a mix of kanji and hiragana. For example, the word 振り仮名 should be inlined as

振り仮名(ふりがな)

and therefore marked up as

<ruby>
  <rb></rb><rb></rb><rb></rb><rb></rb>
  <rp>(</rp><rt></rt><rt></rt><rt></rt><rt></rt><rp>)</rp>
</ruby>

However, when displayed as ruby, the “り” should be hidden

Hiragana annotations for 振り仮名 appear, each pronunciation above its kanji base character.

Hiragana ruby for 振り仮名. Notice there is no hiragana annotation above , since it is already in hiragana.

The Japanese word in this example is composed of three kanji characters, one of which is taught in first grade, while the other two are more advanced. (Characters colored to show base-pair correspondences.)
<ruby><rb><rb><rb><rt>こん<rt class=easy>ちゅう<rt></ruby>
昆虫記, with phonetic annotations on all three characters.
			     Because the middle annotation is wider than its base,
			     space has been introduced around the base character
			     to prevent its annotation from colliding with the adjacent annotations.
Fully annotated three-character word

Although some readers might need pronunciation guidance on all three characters, for other audiences it is more appropriate to hide the annotation on the easier character. Applying visibility: collapse enables this hiding:

昆虫記, with phonetic annotations centered over
			          the first and last characters.
Middle annotation as visibility: collapse

The hiding behavior of visibility: collapse differs from visibility: hidden—​which makes the annotation invisible, but does not remove its impact on layout:

昆虫記, with phonetic annotations on the first and last characters.
			     Over the second one, even though no annotation is showing,
			     space is reserved as if to hold it,
			     which pushes the base characters apart.
Middle annotation as visibility: hidden

It also differs from display: none because visibility: collapse preserves pairing relationships, whereas display: none removes the box from the tree entirely, disturbing the pairing of any annotations after it:

昆虫記, with mispaired phonetic annotations:
			     the annotation for the second character having been removed,
			     the annotation for the third character is displayed over the second one.
Middle annotation as display: none

When the computed value of ruby-merge on the annotation container is merge, hiding is disabled. When that value is auto, the user agent may decide whether to disable hiding of its annotations, but it is recommended to enable hiding if the user agent’s layout algorithm produces the results similar to separate.

The content comparison for auto-hiding takes place prior to white space collapsing (white-space) and text transformation (text-transform) and ignores elements (considers only the textContent of the boxes).

Note: Future levels of CSS Ruby may add controls for auto-hiding, but in this level it is always forced.

2.5. White Space Collapsing

As discussed in § 2.2 Anonymous Ruby Box Generation, white space within a ruby structure is discarded:

For example, the following markup will display without any spaces:
<ruby>
  <rb></rb><rb></rb>
  <rt>とう</rt><rt>きょう</rt>
  <rtc><rt></rt><rt>kyō</rt></rtc>
</ruby>

Between ruby segments, between ruby bases, and between ruby annotations, however, white space is not discarded, and is maintained for rendering as inter-base, inter-annotation, or inter-segment white space. (See Interpret intra-level white space, above.)

The rules preserving white space allow ruby to be used with space-separated scripts such as Latin. For example,
<ruby>
  <rb>W</rb><rb>W</rb><rb>W</rb>
  <rt>World</rt> <rt>Wide</rt> <rt>Web</rt>
</ruby>

They also ensure that annotated white space is preserved. For example,

<ruby>
  <rb>Aerith</rb><rb> </rb><rb>Gainsborough</rb>
  <rt>エアリス</rt><rt></rt><rt>ゲインズブール</rt>
</ruby>

Where undiscarded white space is collapsible, it will collapse across adjacent boxes in each line box following the standard white space processing rules [CSS-TEXT-3]. Annotations in separate ruby segments or separated by hidden annotations are not considered adjacent; however all base-level content (including inter-character annotations, which are treated as atomic inlines) is. For collapsible white space between ruby segments (inter-segment white space), the contextual text for determining segment break transformations is thus given by the ruby bases on either side, not necessarily the text on either side of the white space in source document order (which could include interlinear annotations).

Note: The white space processing rules cause a white space sequence containing a segment break (such as a line feed) to collapse to nothing between Han and Kana characters. This means that Chinese and Japanese ruby can safely use white space for indentation of ruby markup. For example, the following markup will display without any spaces:
<ruby><rt>おく</rt><rt>ない</rt><rt>きん</rt><rt>えん</rt>
</ruby>

However, white space that does not contain a segment break does not collapse completely away, so this markup will display with a space between the first and second ruby pairs:

<ruby><rt>おく</rt><rt>ない</rt><rt>きん</rt><rt>えん</rt>
</ruby>

3. Ruby Layout

When a ruby structure is laid out, its base level is initially laid out on the line exactly as if its ruby bases were a regular sequence of inline boxes and the ruby container a regular inline box wrapped around it.

If a ruby container has any inter-character annotations, they are laid out into the base level as detailed in § 3.2 Inter-character Ruby Layout. Subsequently, the base container is sized and interlinear annotations are laid out as detailed in § 3.1 Interlinear Ruby Layout.

As in other CSS layout models, relative positioning, transforms, and other graphical effects apply after this layout of the boxes.

3.1. Interlinear Ruby Layout

Interlinear ruby annotations within a level are initially laid out as if they were inline boxes participating in the same inline formatting context, effectively establishing a line box for that level of annotation in the ruby container. Annotations and bases are aligned to each other by adjusting their spacing as described below.

3.1.1. Inline-axis Interlinear Layout

In the inline axis, interlinear ruby annotations are aligned with respect to their ruby base boxes in accordance with their annotation container’s ruby-merge value.

When ruby-merge is separate, each ruby column is sized to the widest content (ruby base or ruby annotation) in that column. In the case of spanning annotations (whether actually spanning or pretending to span per ruby-merge: merge), if the content of a spanning annotation would be wider than the columns that it spans, then the difference is distributed equally among the spanned columns. If a ruby segment contains multiple spanning annotations, this distribution of additional space is performed starting with the spanning annotations that span the least number of bases, and then in increasing number of bases spanned. Each ruby base and ruby annotation is then sized to exactly span its column(s).

Note: If there are multiple annotations in different levels spanning the same number of bases that overlap but do not coincide, the distribution of space is undefined. Note this is not possible with HTML markup, but can happen in markup languages with explicit spanning such as in [RUBY].

If any ruby annotation in an annotation container with ruby-merge: auto is wider than its base, then ruby annotations in that annotation container may extend outside of their column(s). When they do, their influence on the measure of the columns they intersect is up to the user agent, provided that the ruby segment is made wide enough to fit all its content.

Inter-character annotations are interleaved between columns: they factor into measurement of annotations that span both adjacent columns, but are not included in either column and are never affected by the sizing or positioning of interlinear annotations.

Within each base and annotation box, how the extra space is distributed when its content is narrower than the measure of the box is specified by its ruby-align property.

The following diagrams illustrate these rules, covering typical situations as well as a few more complex ones. In each case, base boxes and annotation boxes are assumed to have ruby-align: center, while annotation containers are assumed to have ruby-align: space-between.

Blue brackets ([ ]) represent base boxes, red brackets ([ ]) represent annotation boxes, and gray bars (|) represent the limits of ruby columns. Ruby containers, base containers, and annotation containers are omitted.

Separate / non-spanning:
|[  a1  ]|[  a2  ]|[annotation-3]|
|[base 1]|[base 2]|[   base 3   ]|

Boxes within each column are sized to match the widest box of that column. The value of ruby-align on each base box and annotation box is used to distribute the extra space in each box.

Spanning (short):
|[  a1  ]|[   short span  ]|
|[base 1]|[base 2]|[base 3]|

When a spanning annotation is shorter than the spanned bases, there is no extra space to distribute to these bases. Extra space within the spanning annotation is distributed according to ruby-align on that annotation box, as for non spanning ones.

Spanning (long):
|[  a1  ]|[spanning annotation]|
|[base 1]|[ base 2 ]|[ base 3 ]|

When the spanning annotation is longer than the spanned base boxes, the extra space is distributed equally between them.

Merged (short):
|[merged        annotation]|
|[base 1]|[base 2]|[base 3]|

A merged annotation behaves similarly to a spanning one, except that distribution of any extra space in it is determined by the value of ruby-align on the annotation container, not on any of its annotation boxes.

Several levels, with spanning annotation:
|[   a1   ]|[ annotation-2 ]|[   a3   ]|
|[long annotation spanning all content]|
|[ base 1 ]|[    base 2    ]|[ base 3 ]|
|[  xx  ]|[annotation spanning bases]|
|[  a1  ]|[ annotation-2 ]|[   a3   ]|
|[base 1]|[    base 2    ]|[ base 3 ]|

In these two examples with multiple levels, each column is sized to its longest content, and spanning annotations that are still longer than the sum of the columns that they span grow them further, adding to each equally.

Several levels, with multiple spanning annotations:
|[   xx   ]|[  annotation spanning bases  ]|
|[   a1   ]|[  annotation-2  ]|[    a3    ]|
|[lengthy annotation spanning base content]|
|[ base 1 ]|[     base 2     ]|[  base 3  ]|

When there are multiple spanning annotations, those that span fewest bases are processed first. In this case, the green one, which spans two bases, is processed before the orange one, which spans three. Changing this order would change the distribution of space.

To help identify which spanning annotation is responsible for which extra spacing, in this diagram the color of the text in each spanning annotation is matched with the background color of spacing it adds to other boxes.

3.1.2. Block-axis Interlinear Layout

Define the extent to which vertical-align affects these ruby boxes. See Issue 4987.

Each base container is then sized and positioned to contain exactly all of its ruby bases’ margin boxes—​and all their associated inter-character ruby annotation margin boxes, if any—​as well as the base and annotation containers of any descendant ruby containers also participating in this inline formatting context. (If a base container has no in-flow content, it is sized and positioned as if it contained a single empty ruby base.)

Each interlinear annotation container is sized and positioned to contain exactly all of its ruby annotations’ margin boxes as well as the base and annotation containers of any descendant ruby containers also participating in this annotation level’s inline formatting context. (If an annotation container has no in-flow content, it is sized and positioned as if it contained a single empty ruby annotation.) These annotation containers are then stacked outward over or under (depending on ruby-position) their corresponding base container, without any intervening space, thus determining the block-axis positioning of the ruby annotations with respect to their ruby bases.

Should block-axis margins collapse? This makes layout more robust, but is inconsistent with how inlines behave along the inline-axis.

3.2. Inter-character Ruby Layout

Inter-character annotations have special layout. Inter-character ruby annotation boxes are spliced into and measured as part of the layout of the base level. Each ruby annotation is inserted to the right of the ruby base it is paired with; a spanning inter-character annotation is placed after the rightmost of all the bases that it spans. Inter-character ruby annotations are laid out exactly like inline blocks, except as described below.

Note: As per the definition of inter-character, inter-character annotations always have a vertical-rl writing-mode, and only exist in horizontal ruby containers.

Each ruby annotation is placed immediately to the right of the relevant ruby base, before any inter-base white space (or inter-segment white space). If multiple inter-character ruby annotation boxes are placed against the same ruby base, their margin boxes are stacked rightwards without intervening space, in increasing level order.

If the automatic height of the ruby annotation box’s content area would be shorter than the height of the content box of the ruby base after which it is placed, its content box height is increased to match that height exactly.

The alignment of the ruby annotation box depends on the ruby-align property on the ruby annotation:

The ruby annotation container box of an inter-character annotation is sized and placed so that its content box coincides exactly with that of the ruby base container box.

Note: The size and position of inter-character ruby annotation container boxes has no effect on layout. The above definition is merely so that programmatically inquiring about them produces deterministic results.

For the purpose of alignment and column sizing (as discussed in § 3 Ruby Layout), inter-character ruby annotations are not considered to be part of the same column as the base to with they are attached; rather, they effectively form a column of their own.

3.3. Styling Ruby Boxes

Ruby bases and ruby containers are treated as inline boxes, and all properties that apply to inline boxes, unless otherwise specified, also apply to them in the same way. However, the line-relative shift values of vertical-align (top, bottom) must be ignored (treated as zero).

All properties that apply to inline boxes, unless otherwise specified, also apply to ruby annotations in the same way, except line-height, which does not apply. Also, the line-relative shift values of vertical-align (top, bottom) must be ignored (treated as zero).

Neither the margin, padding, and border properties nor any of the properties that do not apply to inline boxes apply to base containers or