If you don’t know what the HTML5 ruby element is, you might want to take a minute to first read the section about the ruby element in the HTML5 specification and/or the Wikipedia article on ruby characters. To quote from the HTML5 description of the ruby element:
The ruby element allows one or more spans of phrasing content to be marked with ruby annotations. Ruby annotations are short runs of text presented alongside base text, primarily used in East Asian typography as a guide for pronunciation or to include other annotations. In Japanese, this form of typography is also known as furigana.
I give a specific example further down, but for now I want to first say that the really great news about the ruby element is that last week Google Chrome developer Roland Steiner checked in a change (r50495, and see also related bug 28420) that adds ruby support to the trunk of the WebKit source repository, thus making the ruby feature available in WebKit nightlies and Chrome dev-channel releases.
A simple example
The following is a simple example of what you can do with the ruby element; make sure to view it in a recent nightly or dev-channel release. Note that the text is an excerpt from the source of a ruby-annotated online copy of the short story Run, Melos, Run by the writer Osamu Dazai, which I came across by way of Piro’s info page for his XHTML Ruby add-on for Firefox (and which I mention a bit more about further below).
きのうの豪雨で山の水源地は<ruby>氾濫<rp>(</rp> <rt>はんらん</rt><rp>)</rp></ruby>し、濁流 <ruby>滔々<rp>(</rp><rt>とうとう</rt><rp>)</rp> </ruby>と下流に 集り、猛勢一挙に橋を破壊し、どうどうと 響きをあげる激流が、<ruby>木葉微塵<rp>(</rp> <rt>こっぱみじん</rt><rp>)</rp></ruby>に<ruby>橋桁 <rp>(</rp><rt>はしげた</rt><rp>)</rp></ruby> を跳ね飛ばしていた。
If you don’t happen to have Japanese fonts installed, here’s a screenshot of the source for reference:

Notice that the actual annotative ruby text (which I’ve highlighted in yellow in the source just for the sake of emphasis) is marked up using the rt element as a child of the ruby element, and the text being annotated is the node that’s a previous sibling to that rt content as a child of the ruby element. The final new element in the mix is the rp element, which is simply a way to mark up the annotative ruby text with parenthesis, for graceful fallback in browsers that don’t support ruby.
So here’s the rendered view of that same text:
見よ、前方の川を。きのうの豪雨で山の水源地は氾濫し、濁流滔々と下流に集り、猛勢一挙に橋を破壊し、どうどうと響きをあげる激流が、木葉微塵に橋桁を跳ね飛ばしていた。
And here is a screenshot of how it should look in a recent nightly or dev-channel release:

Notice that the annotative ruby text is displayed above the ruby base it annotates. If you instead view this page in a browser that doesn’t support the ruby feature, you’ll see that the ruby text is just shown inline, in parenthesis following the ruby base it annotates. So the feature falls back gracefully in older browsers.
If you’re not accustomed to reading printed books and magazines and such in Japanese, you may be feeling underwhelmed by the example above. But for authors and developers and content providers in Japan who want to finally be able to use on the Web this very common feature of Japanese page layout from the print world, getting ruby support into WebKit is a huge win, and something to be very excited about.
Support in other browsers
Current versions of Microsoft Internet Explorer also have native support for ruby, and you can also get ruby support in Firefox by installing Piro’s XHTML Ruby add-on (and for more details, see his XHTML ruby add-on info page) — so we are well on the way to seeing the HTML5 ruby feature supported across a range of browsers.
November 13th, 2009 at 1:11 pm
Users who can’t wait to use this feature in Safari can use this custom stylesheet today:
/* Ruby text*/
ruby {
display:inline-table;
text-align:center;
border-collapse:collapse;
/* border collapse mechanism
will be used to adjust vertical alignment */
vertical-align:middle;
/* if ruby text contains text only
and there are two ruby annotations
(one placed above the base and one below)
then vertical centering roughly aligns baseline of
base with baseline of parent */
border-bottom:solid 0.75em transparent;
/* o.75em is height of ruby text (0.5000d7 1.2em = 0.6em)
plus space between baseline and text-bottom (about 0.15em)
this extra border is counter-weight used
to restore vertical centering broken
by presence of ruby text
(in case if there is only one ruby annotation,
if there are two annotations
then counter-weight is no longer
necessary and can be annihilated
using border collapse mechanism) */}
ruby > rt, rtc
{display:table-header-group;}
/* used to move first ruby
container above the base */
ruby > rb, rbc, ruby > rt + rt, rtc + rtc
{display:table-row;}
/* base and second ruby
are formatted as table-rows */
ruby > rt + rt, rtc + rtc
{border-bottom:hidden;}
/* if there are two annotations then extra
border is no longer necessary
and can be annihilated
using border collapse mechanism */
rb, rbc, rt, rtc
{white-space:nowrap;}
/* prohibits line breaks inside ruby text */
rtc > rt, rbc > rb
{display:table-cell;}
/* used to distribute annotations
in table like manner */
rtc > rt[rbspan]
{column-span:attr(rbspan);}
/* ruby text may span several cells */
ruby > rt, rtc
{font-size:0.5em;
line-height:1.2em;}
/* font-size of ruby text is reduced */
rp
{display:none;}
/* fallback markup is no longer necessary */
November 18th, 2009 at 11:47 am
Congratulations! Glad to see browsers start to implement this. I’m playing around with surf from suckless and pretty happy with Webkit. Look forward to seeing this feature show up in the distros’ package releases.
Oh, and thanks, Carl, for the style-sheet. The one I had working for Opera rendered funny with Webkit.