The <ruby> element is used for group text with pronunciation annotations. You will run into it while reading other people’s HTML, and it is useful to know what job it does before copying the code.
What does <ruby> mean?
Group text with pronunciation annotations. The tag gives the browser a specific kind of content to work with. It is more helpful to choose a tag for its meaning than because of its default look.
Ruby is useful for East Asian readings and other short inline annotations.
A working HTML example
Here is a small example you can place in an HTML page and inspect in your browser:
<section>
<p><ruby>東京<rt>とうきょう</rt></ruby> means Tokyo.</p>
</section>
Reading the example
Find the <ruby> part first. Notice which elements are around it and how its content or attributes are connected to those other elements.
In this example, <ruby> appears alongside rt, rp. That context is often just as important as the element itself.
The browser builds its document from these relationships. Any CSS changes appearance, while interactive JavaScript behavior must be provided separately when the example includes it.
When should you use it?
Use <ruby> when you want to group text with pronunciation annotations. A sensible example of this on a real website is the markup shown above; it gives the browser and accessibility tools a clearer job to work with.
Common companions are rt, rp. Check the nesting requirements before moving the element into a different location.
Try it yourself
Annotate a two-character word and check the reading order.
Common Beginner Mistakes
- It is not intended to replace translations or long explanations.
- Picking
<ruby>only because it looks a certain way instead of checking what it means. - Forgetting to inspect the surrounding markup when an element does not behave as expected.
Key Takeaways
<ruby>helps group text with pronunciation annotations.- Ruby is useful for East Asian readings and other short inline annotations.
- Start with meaningful markup, then add styling or scripting only when the page needs it.