LEARNING OBJECTIVES ⌵
- Understand the typographic origins of Ruby annotations and their role in East Asian publishing.
- Implement semantic ruby markup using
<ruby>,<rt>(Ruby Text), and<rp>(Ruby Parentheses). - Differentiate between mono-ruby, group-ruby, and jukugo-ruby annotation structures.
- Control ruby visual positioning and alignment using modern CSS properties (
ruby-position,ruby-align). - Configure ruby markup to prevent screen reader double-pronunciation accessibility defects.
📖 The Mental Model & Story (Intuitive Foundation)
In 19th-century British printing, typesetters named standard metal font sizes after precious gemstones: 4.5-point was Diamond, 5-point was Pearl, 5.5-point was Agate (in the US) or Ruby (in the UK), and 6-point was Emerald.
Metal Type Sizes in 19th-Century Typography:
[ Diamond: 4.5pt ] [ Pearl: 5pt ] [ Ruby: 5.5pt ] [ Emerald: 6pt ]
▲
Small enough to float above base characters!
When Western printing technology was imported to Japan and China, publishers needed a way to print tiny phonetic pronunciation guides directly above complex logographic characters (Kanji / Hanzi). Japanese characters often have multiple context-dependent readings (such as kun'yomi vs on'yomi). Typesetters adopted the 5.5-point Ruby metal type to print these pronunciation aids (called Furigana in Japanese and Pinyin / Zhuyin in Chinese) floating directly above the base text.
Visual Ruby Typography (Japanese Furigana):
とうきょう
東 京 <-- Base text: Tokyo
Visual Ruby Typography (Chinese Pinyin):
běi jīng
北 京 <-- Base text: Beijing
HTML5 standardized this typographic tradition into native semantic elements.
Technical Deep Dive & Specifications
The WHATWG HTML5 Ruby Element Suite
The HTML standard defines three core elements that work together to construct phonetic annotations:
+-----------------------------------------------------------------------------------------+
| THE RUBY ELEMENT TRIAD |
+-----------------------------------------------------------------------------------------+
| ELEMENT | NAME | DESCRIPTION |
+---------+------------------+------------------------------------------------------------+
| <ruby> | Ruby Container | Wraps one or more base text characters and annotations. |
| <rt> | Ruby Text | Contains the small phonetic annotation text. |
| <rp> | Ruby Parenthesis | Fallback delimiter shown ONLY if the browser lacks ruby |
| | | rendering support (e.g., text browsers, legacy feeds). |
+-----------------------------------------------------------------------------------------+
Semantic Structure & Fallback Architecture
In modern browsers, <rt> automatically floats above (or beside) the base text at approximately 50% font size, and <rp> tags are completely hidden (display: none).
However, if an older browser, CLI browser (like Lynx), RSS feed aggregator, or screen reader does not support ruby layout, it falls back to displaying the content linearly. The <rp> elements appear to wrap the phonetic text in parentheses, preventing the text from becoming an unreadable garbled mess.
Standard HTML5 Ruby Markup:
<ruby>
漢<rp>(</rp><rt>かん</rt><rp>)</rp>
字<rp>(</rp><rt>じ</rt><rp>)</rp>
</ruby>
Browser with Ruby Support: Legacy Browser / Plain Text Fallback:
かん じ
漢 字 漢(かん)字(じ)
Ruby Tagging Patterns
1. Mono-Ruby (Character-by-Character Mapping) — Recommended
Each base character is paired with its individual phonetic annotation:
<ruby>
東<rp>(</rp><rt>とう</rt><rp>)</rp>
京<rp>(</rp><rt>きょう</rt><rp>)</rp>
</ruby>
Advantage: Enables fine-grained typography, natural wrapping across line ends, and precise alignment.
2. Group-Ruby (Whole-Word Mapping)
A single multi-character base string is paired with a compound annotation:
<ruby>
明日<rp>(</rp><rt>あした</rt><rp>)</rp>
</ruby>
Advantage: Useful for irregular readings (jukujikun) where individual kanji cannot be split neatly into syllables.
CSS Styling & Layout for Ruby
Modern CSS provides specialized properties to control ruby layout:
/* Position the annotation text relative to the base text */
ruby {
ruby-position: over; /* Default in horizontal text (floats above) */
/* ruby-position: under; /* Floats below the base text */
/* ruby-position: inter-character; /* Places annotation between characters (Bopomofo) */
}
/* Control horizontal justification of rt over base characters */
ruby {
ruby-align: space-around; /* Distributes phonetic letters evenly over kanji */
/* ruby-align: center; */
/* ruby-align: start; */
}
+-------------------------------------------------------------------------------+
| CSS RUBY POSITIONS |
+-------------------------------------------------------------------------------+
| ruby-position: over; ruby-position: under; Vertical Mode: |
| とうきょう 東 京 東 と |
| 東 京 とうきょう 京 う |
| き |
| ょ |
| う |
+-------------------------------------------------------------------------------+
Screen Reader & Accessibility Considerations
Without proper markup, screen readers may read both the base character and the phonetic annotation consecutively: "Kan-kanji-ji", causing confusion.
Modern assistive technologies with CJK support understand <ruby> and read only the <rt> phonetic pronunciation or the base text depending on the user's accessibility preferences. To ensure clean pronunciation across all legacy screen readers, maintain clean <rp> wrappers.
💻 Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 2 (
<html lang="ja">): Informs the browser that the primary language is Japanese, loading Japanese typographic font substitutions and CJK line-breaking rules. - Line 12 (
line-height: 2.2;): When working with ruby annotations, allocating extra vertical line height (at least2.0to2.5) is required so that<rt>text does not collide with text on the preceding line. - Lines 51–57 (
<ruby>新<rp>(</rp><rt>しん</rt><rp>)</rp>...): Implements mono-ruby. Each Kanji character (新,幹,線) is immediately followed by its fallback parenthesis ((), its phonetic pronunciation in Hiragana (しん), and its closing parenthesis ()). - Line 66 (
<div class="card chinese-ruby" lang="zh-Hans">): Overrides language context to Simplified Chinese. - Lines 70–75 (
<ruby>北<rp>(</rp><rt>běi</rt><rp>)</rp>...): Applies Pinyin tone marks (běi jīng) over the corresponding Hanzi characters. - Line 83 (
ruby-position: under;): Forces the phonetic text to render beneath the baseline of the kanji characters instead of on top.
Expected Browser Render Output
- In modern browsers, tiny red Hiragana readings (
しん,かん,せん) float neatly above their respective Kanji characters. - In Chinese sections, Pinyin with tone marks (
běi,jīng) hovers in blue above the characters北京. - In the third box,
ふじさんrenders below富士山. - Parentheses defined inside
<rp>are invisible in modern browsers.
🏋️ Hands-On Exercise
🎯 The Challenge: Interactive Japanese Flashcard
Scenario: You are developing an educational vocabulary flashcard component for an online Japanese language school. The flashcard displays the Japanese word for "Library" (図書館 - Toshokan). You must mark it up with full ruby phonetic annotations and fallback parentheses so language learners can study the pronunciation while maintaining full backward compatibility.
Instructions:
- Wrap the compound word
図書館in a<ruby>container. - Use mono-ruby markup to pair:
図with readingと書with readingしょ館with readingかん
- Enclose all
<rt>tags with opening and closing<rp>tags containing(and). - Add a second flashcard showing the Chinese word for "Teacher" (老师 - lǎoshī) with proper
lang="zh-Hans"and Pinyin annotations.
🏁 Starter Code Sandbox
⚠️ Common Pitfalls
- Omitting
<rp>Fallbacks: Writing<ruby>漢字<rt>かんじ</rt></ruby>without<rp>tags causes legacy feeds and text parsers to output漢字かんじ, creating an unreadable collision between base characters and pronunciation. - Insufficient
line-height: Ruby text extends outside the normal bounding box of a font. Defaultline-height: 1.2will cause ruby annotations to overlap or clip against the text line above. Always setline-height: 2.0or greater on paragraphs containing ruby. - Using Subscript/Superscript Instead of Ruby: Attempting to mock ruby with
<sup>or<sub>destroys accessibility semantics and breaks CJK character alignment.
💡 Pro Tips
- Use
user-select: noneon<rt>: When users highlight and copy text from a Japanese web article, they typically want only the base Kanji string (図書館), not the phonetic annotations. Applyingrt { user-select: none; }prevents copying duplicated syllables. - Vertical Text Support (
writing-mode: vertical-rl): In traditional Japanese vertical layouts,<rt>automatically floats to the right side of the character column according to W3C typographic specifications.
📌 Key Takeaways
- The HTML5 Ruby specification consists of
<ruby>(container),<rt>(ruby text), and<rp>(fallback parentheses). - Ruby annotations are used in Japanese (Furigana), Mandarin (Pinyin), and Taiwanese (Zhuyin/Bopomofo).
- Mono-ruby (character-by-character) is preferred over group-ruby for clean typesetting and responsive wrapping.
<rp>tags are automatically hidden by modern browsers and only display in legacy/unsupported environments.- Always increase
line-heightwhen using ruby markup to accommodate floating annotations without layout collisions. - --