From MDN web docs:
The element behaves like an inline element and lays out its content according to the ruby formatting model. It behaves like the corresponding HTML elements.
You can use it together with display: ruby-base;
and display:ruby-text
, which similarly act like <rb>
and <rt>
.
To see an example on how all of these could be used:
body {
font-size: 2em;
}
ruby {
ruby-position: above;
}
.ruby {
display: ruby;
}
p.ruby>span:nth-child(odd) {
display: ruby-base;
}
p.ruby>span:nth-child(even) {
display: ruby-text;
}
<p>
<ruby>
<rb>漢</rb>
<rb>字</rb>
<rb>が</rb>
<rb>難</rb>
<rb>しい</rb>
<rp>(</rp>
<rt>kan</rt>
<rt>ji</rt>
<rt>ga</rt>
<rt>muzuka</rt>
<rt>shii</rt>
<rp>)</rp>
</ruby> !
</p>
<p class="ruby">
<span>漢</span>
<span>kan</span>
<span>字</span>
<span>ji</span>
<span>難</span>
<span>muzuka</span>
<span>しい</span>
<span>shii</span>
<span>!</span>
</p>