Displaying Furigana/Pinyin on a Website
Sometimes, when displaying East Asian/CJK characters on websites, there may be instances where we need to provide small annotations on the top of certain characters in order to show people how to pronounce them in a certain language, be it Hanyu Pinyin in Mandarin Chinese, Furigana in Japanese, or Jyutping in Cantonese, such as showing the readers how to pronounce our names that involve such characters properly.
The proper terminology for such little annotations is called 'ruby characters' (also known as 'ruby text' or simply 'ruby').
How do we achieve this when we are building our own websites then?
The <ruby> element1
Enter the <ruby> HTML element. By wrapping the characters, along with the annotations that we want to include on top of, within the <ruby> tag, we can add ruby text on webpages.
In raw HTML, the standard practice is to also include fallback open and close parantheses that are wrapped with <rp> tags and wrap the annotations with <rt> tags. The structure of the HTML code will then look like this...
<ruby>
人 <rp>(</rp><rt>nin</rt><rp>)</rp>
間 <rp>(</rp><rt>gen</rt><rp>)</rp>
</ruby>
...whereas the CSS code may look something like this2.
ruby {
font-size: 4em;
ruby-align: center; /* Ruby text alignment */
}
Here is the result of the code above3.
Some more examples: my name in different languages
That's basically it (for more platform-specific information, see footnote)! To further demonstrate its use cases, here are some examples showing how my Chinese name, 陳智恆 (written in Traditional Chinese characters), is pronounced in different languages.
Mandarin Chinese (Hanyu Pinyin)
Mandarin Chinese (Bopomofo)
Cantonese (Jyutping)
Hokkien (Peh-oe-ji)
Hakka (Phak-fa-su)4
Japanese (Katakana, in On'yomi)
The corresponding romajis:-
- チン: chin
- チ: chi
- コウ: kou
Bonus: my official English name
Fun fact: my official English name is actually a transcription of the pronunciation of my Chinese name in Hokkien!