<ruby> Ruby annotation

Small annotations above or beside text, mostly for East Asian pronunciation.

<ruby> puts small annotations next to base text. Most of the time they give the pronunciation of Chinese, Japanese or Korean characters. Inside the element, the base text comes first, followed by <rt> elements that hold the annotation.

Optional <rp> elements add fallback brackets for very old browsers that cannot display ruby. Every current browser supports it.

The ruby element in the HTML Living Standard (opens in a new tab) has detailed examples for Japanese and Chinese. The annotation itself lives in an rt element.

Syntax

<ruby>base<rt>annotation</rt></ruby>

When to use it

<ruby> puts a reading aid right next to the text: furigana over kanji in Japanese learning materials or children's books, pinyin over Chinese characters, zhuyin in Taiwanese texts, or a pronunciation guide over a hard word in any language.

If the explanation can wait, a tooltip-style abbr or text in brackets is simpler. If you are teaching a term, dfn with a sentence is clearer. Choose ruby when the annotation must be visible at the same moment as the base text.

Decide how to group. Mono ruby gives each character its own rt; group ruby puts one rt over a whole word when the reading cannot be split by character. Some older guides use rb and rtc elements; those are obsolete in the Living Standard, so write the base text directly followed by rt. Ruby text also adds height above the line, so give such paragraphs a larger line-height.

Live example

Edit the code and watch the preview.

<p style="font-size:2em"><ruby>&#x6F22;<rp>(</rp><rt>kan</rt><rp>)</rp>&#x5B57;<rp>(</rp><rt>ji</rt><rp>)</rp></ruby></p>

More examples

Pinyin for Chinese

Each Chinese character gets its own pinyin reading in an rt element. The tone marks are written as numeric character references, and lang tells the browser the text is Chinese.

<p lang="zh" style="font-size:2em;line-height:2"><ruby>&#x4F60;<rt>n&#x1D0;</rt>&#x597D;<rt>h&#x1CE;o</rt></ruby></p>
<p>(Translation: hello)</p>

Mono ruby versus group ruby

The Japanese word for Tokyo is annotated two ways. The first gives each character its own reading; the second places one reading over the whole word. rp adds brackets for browsers without ruby support.

<p lang="ja" style="font-size:2em;line-height:2"><ruby>&#x6771;<rp>(</rp><rt>&#x3068;&#x3046;</rt><rp>)</rp>&#x4EAC;<rp>(</rp><rt>&#x304D;&#x3087;&#x3046;</rt><rp>)</rp></ruby></p>
<p lang="ja" style="font-size:2em;line-height:2"><ruby>&#x6771;&#x4EAC;<rp>(</rp><rt>&#x3068;&#x3046;&#x304D;&#x3087;&#x3046;</rt><rp>)</rp></ruby></p>

Tip: Each annotation goes in rt, right after its base text.

Browser support

Basic ruby with rt and rp works in all current browsers; Firefox added it in version 38. Finer layout control through CSS, such as ruby-position and ruby-align, is less consistent. Check the ruby annotation support table (opens in a new tab) before relying on advanced features.

Accessibility

Screen readers handle ruby unevenly and sometimes read both the base and the annotation. Set the correct lang attribute so the characters at least get pronounced properly. How lang affects pronunciation is explained in the W3C note Understanding Language of Parts (opens in a new tab).

Common mistakes

Wrong

<ruby><rt>kan</rt>&#28450;</ruby>

Right

<ruby>&#28450;<rt>kan</rt></ruby>

The rt annotation has to follow the base text it describes.

Frequently asked questions

What is ruby text in HTML?

Small runs of text placed above or beside base text, usually to show how East Asian characters are pronounced. Furigana in Japanese and pinyin in Chinese are the familiar examples. In HTML you wrap the base text in <ruby> and put each annotation in an <rt> element right after the characters it describes. Furigana and other uses are explained in Wikipedia's article on ruby characters (opens in a new tab).

Do I still need the rp tag?

Not really, but it does no harm. <rp> provides fallback parentheses for browsers without ruby support, so the annotation shows up as text in brackets. Every current browser supports ruby and hides rp content. It still keeps the text readable when it is copied or shown without CSS.

Related text elements

<p>One paragraph of text.<br>Breaks the line inside text, as in a postal address or a poem.<hr>A change of topic between paragraphs, drawn as a horizontal line.<pre>Shows text exactly as typed, spaces and line breaks included.<blockquote>A longer quotation from another source, set apart as its own block.<div>A generic block box with no meaning, for grouping and styling.<span>A generic inline wrapper with no meaning, for styling part of a line of text.<strong>Text that is important, serious or urgent. Shown in bold by default.<em>Stress emphasis that changes what a sentence means. Italic by default.<b>Makes text stand out without adding importance, as with keywords. Bold by default.<i>Text in another voice: foreign words, terms, thoughts, ship names. Italic.<u>Text with an unspoken annotation, such as a flagged spelling error.<s>Content that is no longer accurate or relevant, drawn crossed out.<mark>Highlighted text, like a marker pen, showing relevance in the current context.<small>Side comments and fine print, like copyright lines or legal notes.<sub>Subscript text, set below the line, as in H2O.<sup>Superscript text, set above the line, as in exponents or 1st.<code>A fragment of computer code, set in a monospace font.<kbd>Keys or text the user should press or type.<samp>Sample output from a program or a computer system.<var>A variable in math or in code. Italic by default.<q>A short quotation inside a sentence. The browser adds the quote marks.<cite>The title of a creative work: a book, film, song, game or article.<abbr>An abbreviation or acronym, with an optional expansion in title.<dfn>Marks the term that the surrounding sentence or paragraph defines.<time>Marks a date, time or duration and gives it a machine-readable value.<data>Ties visible content to a machine-readable value.<del>Text that was removed from the document. Struck through by default.<ins>Text that was added to the document. Underlined by default.<wbr>A spot where the browser may break a long word if it has to.<bdi>Isolates text of unknown direction, such as user names.<bdo>Forces a text direction and overrides the normal bidi algorithm.<rt>The small reading or note in a ruby annotation.<rp>Fallback brackets around ruby text, shown only where ruby is unsupported.