CSS ruby-position Property

The CSS ruby-position property controls where ruby annotations appear relative to their associated base text.

Ruby annotations are small text labels used to provide pronunciation or explanatory information, particularly in East Asian writing systems. The ruby-position property allows annotations to appear on the over or under side of the base text, or alongside it using inter-character positioning.

ruby-position Syntax

The ruby-position property accepts a keyword specifying the placement of ruby annotations relative to their base text.

Basic Syntax

selector {
  ruby-position: over;
}

Available Values

ruby {
  ruby-position: over;
}
ruby {
  ruby-position: under;
}
ruby {
  ruby-position: inter-character;
}

CSS-Wide Keywords

ruby {
  ruby-position: initial;
}
ruby {
  ruby-position: inherit;
}
ruby {
  ruby-position: unset;
}
ruby {
  ruby-position: revert;
}
ruby {
  ruby-position: revert-layer;
}

The property does not accept lengths, percentages, or physical positioning keywords such as top, bottom, left, or right.

Property Values

Value Description
over Places the annotation on the over side of the base text. In horizontal writing, this is generally above the text. This is the initial value.
under Places the annotation on the under side of the base text. In horizontal writing, this is generally below the text.
inter-character Places annotations alongside base characters in an inter-character arrangement, commonly associated with Taiwanese Bopomofo annotations.
initial Resets the property to over.
inherit Uses the computed value from the parent element.
unset Inherits the value from the parent because the property is inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value over
Inherited Yes
Applies to Ruby annotation containers
Computed value As specified
Animation type Discrete
Percentages Not applicable

Valid Values

ruby {
  ruby-position: over;
}
ruby {
  ruby-position: under;
}
ruby {
  ruby-position: inter-character;
}

Invalid Values

ruby {
  ruby-position: top;
}
ruby {
  ruby-position: bottom;
}
ruby {
  ruby-position: left;
}
ruby {
  ruby-position: 10px;
}
ruby {
  ruby-position: over under;
}

The property accepts one supported placement keyword or a CSS-wide keyword. It does not accept physical direction keywords or multiple placement values.

How It Works

Ruby layout associates a base character or phrase with annotation text. The ruby-position property determines which side of the base text contains the annotation.

Basic Ruby Example

<ruby>
  漢字
  <rt>かんじ</rt>
</ruby>

The Japanese characters are the base text, while the hiragana annotation provides their pronunciation.

Positioning Above the Base

ruby {
  ruby-position: over;
}

In horizontal writing, the annotation appears above the base text.

Positioning Below the Base

ruby {
  ruby-position: under;
}

In horizontal writing, the annotation appears below the base text.

Positioning Beside the Base

ruby {
  ruby-position: inter-character;
}

In supported horizontal writing layouts, the annotation can appear beside the base character instead of above or below it.

Important Distinction

The ruby-position property controls annotation placement. It does not determine how annotation characters are distributed within their available inline space. That behavior is controlled by ruby-align.

Understanding Ruby Markup

HTML provides semantic elements for associating pronunciation or explanatory annotations with base text.

Element Purpose
<ruby> Creates a ruby annotation structure containing base text and associated annotations.
<rt> Contains the ruby annotation text.
<rp> Provides optional fallback parentheses for browsers that do not support ruby annotations.

Basic Ruby Markup

<ruby>
  日本語
  <rt>にほんご</rt>
</ruby>

The annotation provides the pronunciation of the Japanese word.

Ruby With Fallback Parentheses

<ruby>
  漢字
  <rp>(</rp>
  <rt>かんじ</rt>
  <rp>)</rp>
</ruby>

Browsers that support ruby layout display the annotation according to ruby formatting rules. Browsers without ruby support can display the fallback parentheses around the annotation.

Multiple Ruby Segments

<ruby>東<rt>とう</rt></ruby>
<ruby>京<rt>きょう</rt></ruby>

Each ruby element associates a base character with its corresponding pronunciation.

Applying a Shared Position

ruby {
  ruby-position: over;
}

This provides a consistent annotation position for ruby content throughout the document, unless a more specific rule overrides it.

Important Consideration

Use semantic ruby markup rather than manually positioning pronunciation text with absolute positioning. Native ruby layout preserves the association between the annotation and its base text.

over Value

The over value places ruby annotations on the over side of their associated base text.

CSS Example

ruby {
  ruby-position: over;
}

Horizontal Writing

In a horizontal writing mode, over generally places annotations above the base text.

Vertical Writing

In vertical writing, the over side depends on the writing mode. For example, in vertical-rl, the over side is generally to the right of the base text.

Default Behavior

over is the initial value of ruby-position.

When to Use over

Use this value for conventional ruby annotations that appear above text in horizontal writing or on the corresponding over side in vertical writing.

Important Consideration

The over value follows the writing mode rather than always referring to the physical top of the page.

under Value

The under value places ruby annotations on the opposite side from over.

CSS Example

ruby {
  ruby-position: under;
}

Horizontal Writing

In a horizontal writing mode, under places annotations below the base text.

Vertical Writing

In vertical writing, the under side follows the writing mode. In vertical-rl, annotations generally appear to the left of the base text.

When to Use under

Use this value when annotations should appear below the base text or on the corresponding under side of a vertical writing layout.

Combining With ruby-align

ruby {
  ruby-position: under;
  ruby-align: center;
}

The annotation is positioned on the under side and centered within its available alignment space, where supported.

Important Consideration

Annotation placement may affect line spacing. Allow enough room for the base text and annotation to remain readable without overlapping adjacent lines.

inter-character Value

The inter-character value requests an annotation arrangement beside individual base characters rather than the usual over or under placement.

CSS Example

ruby {
  ruby-position: inter-character;
}

Common Use

Inter-character ruby is associated with Taiwanese Bopomofo, also called Zhuyin, which uses phonetic symbols to indicate the pronunciation of Chinese characters.

HTML Example

<ruby lang="zh-Bopo">
  中
  <rt>ㄓㄨㄥ</rt>
</ruby>

CSS Example

ruby {
  ruby-position: inter-character;
}

Writing Mode Behavior

The inter-character arrangement is primarily intended for horizontal writing. In vertical writing modes, the specification treats this value like over.

Browser Support

Support for inter-character is limited. Some browsers may render the annotation using their normal ruby placement rather than an inter-character arrangement.

Important Consideration

Use this value only when the language and annotation system benefit from inter-character positioning. Test the result in the browsers used by your audience.

Ruby Position and Writing Modes

The ruby-position property uses logical placement values that follow the text's writing mode.

Writing Mode over under
horizontal-tb Above the base text Below the base text
vertical-rl Right of the base text Left of the base text
vertical-lr Left of the base text Right of the base text

Horizontal Writing Example

.horizontal-ruby {
  writing-mode: horizontal-tb;
  ruby-position: over;
}

The annotation appears above the base text.

Vertical Right-to-Left Writing

.vertical-ruby {
  writing-mode: vertical-rl;
  ruby-position: over;
}

The annotation appears on the right side of the vertical base text.

Vertical Left-to-Right Writing

.vertical-ruby {
  writing-mode: vertical-lr;
  ruby-position: over;
}

The annotation appears on the left side of the vertical base text.

Important Consideration

Because ruby placement is writing-mode aware, the same ruby-position declaration can produce different physical positions in horizontal and vertical layouts.

ruby-position Versus ruby-align

The ruby-position and ruby-align properties control different aspects of ruby formatting.

Property Purpose
ruby-position Controls which side of the base text contains the annotation.
ruby-align Controls how ruby content is aligned or distributed within its available inline space.

Positioning an Annotation

ruby {
  ruby-position: under;
}

This places the annotation on the under side of the base text.

Aligning an Annotation

ruby {
  ruby-align: center;
}

This centers ruby content within its available alignment space.

Combining Both Properties

ruby {
  ruby-position: under;
  ruby-align: center;
}

Where both properties are supported, the annotation is placed on the under side and its content is centered.

Important Distinction

Use ruby-position to choose the annotation's side and ruby-align to control alignment within the ruby segment.

ruby-position Example

The following example compares the over and under values using Japanese ruby annotations.

HTML Example

<div class="ruby-position-demo" lang="ja">
  <div class="ruby-example">
    <strong>ruby-position: over</strong>
    <ruby class="ruby-over">
      日本語
      <rt>にほんご</rt>
    </ruby>
  </div>
  <div class="ruby-example">
    <strong>ruby-position: under</strong>
    <ruby class="ruby-under">
      日本語
      <rt>にほんご</rt>
    </ruby>
  </div>
</div>

CSS Example

.ruby-position-demo {
  display: grid;
  gap: 15px;
}
.ruby-position-demo .ruby-example {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 25px;
  padding: 25px 20px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
}
.ruby-position-demo .ruby-example strong {
  min-width: 170px;
  font-size: 14px;
}
.ruby-position-demo ruby {
  font-size: 28px;
}
.ruby-position-demo rt {
  font-size: 12px;
}
.ruby-position-demo .ruby-over {
  ruby-position: over;
}
.ruby-position-demo .ruby-under {
  ruby-position: under;
}
Browser Result
ruby-position: over 日本語にほんご
ruby-position: under 日本語にほんご

The first example places the annotation above the base text. The second requests placement below the base text.

If the browser does not support the under value, the annotation may remain in its default position above the base text.

Changing the Default Position

.ruby-position-demo ruby {
  ruby-position: under;
}

This requests under-side placement for all ruby annotations in the example.

Adding Centered Alignment

.ruby-position-demo ruby {
  ruby-align: center;
}

Where supported, this centers the annotation content within its available inline space without changing its selected side.

Browser Compatibility Note

The over and under values have broader support than inter-character, but implementation details can still vary. Test the example in the browsers you intend to support.

Accessibility Considerations

Ruby annotations can improve comprehension by providing pronunciation and explanatory information while preserving the original text.

Use Semantic Ruby Markup

Use <ruby> and <rt> to associate annotations with their base text.

Identify the Language

Use the lang attribute when appropriate so browsers and assistive technologies can identify the language of the content.

Maintain Readable Annotations

Ensure annotation text remains legible at normal and increased zoom levels.

Avoid Overlapping Lines

Annotations placed above or below text can affect line spacing. Check that adjacent lines do not overlap.

Preserve the Base Text

Do not replace the original characters with pronunciation text. Ruby annotations should supplement the base text.

Consider Assistive Technology Support

Screen readers may announce ruby annotations differently. Test important pronunciation content with relevant assistive technologies.

Important Consideration

The ruby-position property changes visual placement only. The semantic relationship between base text and annotation comes from the HTML markup.

Common Mistakes

Using Physical Direction Keywords

ruby {
  ruby-position: top;
}

Use over or under rather than physical direction keywords.

Confusing ruby-position With ruby-align

The ruby-position property controls which side contains the annotation. It does not control the distribution of annotation characters.

Using Length Values

ruby {
  ruby-position: 10px;
}

The property accepts placement keywords, not lengths or percentages.

Expecting Identical Results in Every Browser

Support for ruby positioning values varies, particularly for inter-character.

Ignoring Writing Modes

The over and under values follow the writing mode rather than always referring to the physical top and bottom.

Using Nonsemantic Annotation Markup

Manually positioning pronunciation text can lose the semantic association between base characters and their annotations.

Forgetting Language Information

Providing appropriate language information helps browsers and assistive technologies interpret pronunciation content.

Ignoring Line Spacing

Ruby annotations can affect the space required between lines. Test layouts with longer annotations and increased text sizes.

Important Considerations

Keep the following points in mind when using ruby-position:

  • It controls the placement of ruby annotations relative to base text.
  • Its initial value is over.
  • The property is inherited.
  • It applies to ruby annotation containers.
  • over places annotations on the over side of the base text.
  • under places annotations on the under side of the base text.
  • inter-character requests annotation placement beside base characters.
  • Inter-character positioning is associated with Taiwanese Bopomofo annotations.
  • The property does not accept lengths or percentages.
  • Physical keywords such as top and bottom are invalid.
  • Ruby placement follows the text's writing mode.
  • In horizontal writing, over generally means above the text.
  • In horizontal writing, under generally means below the text.
  • In vertical writing, annotations can appear beside the base text.
  • The ruby-align property controls alignment within the ruby segment.
  • The ruby-position and ruby-align properties can be used together.
  • The <ruby> element establishes ruby markup.
  • The <rt> element contains annotation text.
  • The <rp> element can provide fallback parentheses.
  • Semantic ruby markup preserves the association between base text and annotations.
  • Ruby annotations are commonly used for pronunciation guidance.
  • Language attributes help identify the annotation language.
  • Browser support for individual placement values varies.
  • Unsupported values may be ignored by the browser.
  • Annotation placement can affect line spacing.
  • Test ruby layouts at increased zoom levels and in target browsers.

Browser Support

The CSS ruby-position property has Limited availability and is not supported consistently across all major browsers.

The over and under values are supported in several modern browsers. The inter-character value has more limited support and may be ignored or rendered using the browser's default ruby placement.

For current compatibility information, visit Can I Use? and search for ruby-position.

Use semantic HTML ruby markup so annotations remain meaningful when the requested CSS positioning is unsupported.

Specifications

The ruby-position property is defined in CSS Ruby Annotation Layout Module Level 1.

CSS Ruby Annotation Layout Module Level 1

The specification defines annotation placement relative to ruby base text and explains how positioning interacts with writing modes.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: ruby-position