Skip to main content

HTML Tags

HTML Ruby Annotations: <ruby>, <rt> and <rp>

Learn how the HTML <ruby>, <rt>, and <rp> elements create pronunciation and explanatory annotations with fallback punctuation.

Ruby annotations put small text above or next to characters, usually to show how to pronounce them. They are common in Japanese and Chinese, where a reader may not know a character. ruby wraps it all, rt holds the small text, and rp adds brackets for old browsers.

The name comes from old British printing, where "ruby" was the name of a very small type size.

Syntax

html

<ruby>
  漢
  <rp>(</rp>
  <rt>kan</rt>
  <rp>)</rp>
</ruby>
  • <ruby> holds the base text and its annotation.
  • <rt> (ruby text) is the small annotation, here the pronunciation "kan".
  • <rp> (ruby parenthesis) holds brackets that only show in browsers without ruby support, so the text reads "漢(kan)" instead of "漢kan".

All three use only the global attributes, such as class, id and lang.

Example

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Ruby Annotation Example</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      padding: 30px;
    }

    ruby {
      font-size: 2rem;
    }

    rt {
      color: #007a96;
      font-size: 0.55em;
    }
  </style>
</head>
<body>
  <h1>Japanese Ruby Annotation</h1>

  <p>
    <ruby>
      漢<rp>(</rp><rt>kan</rt><rp>)</rp>
      字<rp>(</rp><rt>ji</rt><rp>)</rp>
    </ruby>
    means "Chinese characters."
  </p>
</body>
</html>

The two characters 漢字 appear large, each with its pronunciation in small blue letters above it, followed by "means Chinese characters".

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Good to know

  • Annotate each character separately, as in the example, so the pronunciation sits over the right one.
  • The annotation does not have to be pronunciation. It can be a short translation or meaning.
  • Add lang="ja" (or the right language) on the page or element, so fonts and screen readers handle it correctly.
  • Style the small text with rt { font-size: 0.5em; }, and its position with the CSS ruby-position property.

HTML Ruby Annotations: <ruby>, <rt> and <rp> exercises

Annotate a character

Show the character 漢 with the reading kan above it.

Result

Check your answer to see it here.