{"id":3350,"date":"2021-01-24T19:48:57","date_gmt":"2021-01-24T18:48:57","guid":{"rendered":"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/"},"modified":"2021-01-24T19:48:57","modified_gmt":"2021-01-24T18:48:57","slug":"ruby-html-footnotes","status":"publish","type":"post","link":"https:\/\/tomayac.com\/wordpress\/2021\/01\/24\/ruby-html-footnotes\/","title":{"rendered":"&lt;ruby&gt; HTML footnotes"},"content":{"rendered":"\n\t\t\t<p>It is sometimes surprising to me to see what kind of use cases HTML has a\ndedicated element for. Something that comes to mind is\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/output\"><code>&lt;output&gt;<\/code><\/a>,\na container element into which a site or app can inject the results of a\ncalculation or the outcome of a user action. For another use case that is\narguably more common and which is also the topic of this blog post, HTML has\nnothing specific to offer:\n<ruby tabindex=\"0\"><strong>footnotes<\/strong><rt><strong>Footnotes<\/strong> are notes at the\nfoot of the page while endnotes are collected under a separate heading at the\nend of a chapter, volume, or entire work. Unlike footnotes,\n<strong>endnotes<\/strong> have the advantage of not affecting the layout of the\nmain text, but may cause inconvenience to readers who have to move back and\nforth between the main text and the endnotes.<\/rt><\/ruby>.<\/p>\n<h2 id=\"footnotes-in-html%2C-then-and-now\">Footnotes in HTML, then and now <a class=\"direct-link\" href=\"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/#footnotes-in-html%2C-then-and-now\">\u2693<\/a><\/h2>\n<p>Despite several\n<a href=\"https:\/\/www.w3.org\/Search\/Mail\/Public\/advanced_search?keywords=&amp;hdr-1-name=subject&amp;hdr-1-query=footnote+footnotes&amp;hdr-2-name=from&amp;hdr-2-query=&amp;hdr-3-name=message-id&amp;hdr-3-query=&amp;period_month=&amp;period_year=&amp;index-grp=Public__FULL&amp;index-type=t&amp;type-index=www-html&amp;resultsperpage=20&amp;sortby=date-asc\">proposals<\/a>\nto deal with footnotes at the language level,\n<a href=\"https:\/\/www.w3.org\/MarkUp\/html3\/\">HTML\u00a03.0 Draft<\/a> was the last version of\nHTML that offered the <a href=\"https:\/\/www.w3.org\/MarkUp\/html3\/footnotes.html\"><code>FN<\/code><\/a>\nelement. It was designed for footnotes, and when practical, footnotes were to be\nrendered as pop-up notes. You were supposed to use the element as in the code\nsample below (the inconsistent character casing <em>sic<\/em>).<\/p>\n<pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>DL<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>DT<\/span><span class=\"token punctuation\">><\/span><\/span>Hamlet:<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>DT<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>DD<\/span><span class=\"token punctuation\">><\/span><\/span><br>    You should not have believed me, for virtue cannot so<br>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>a<\/span> <span class=\"token attr-name\">href<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>#fn1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span>inoculate<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>a<\/span><span class=\"token punctuation\">><\/span><\/span> our old stock but we shall<br>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>a<\/span> <span class=\"token attr-name\">href<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>#fn2<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span>relish of it<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>a<\/span><span class=\"token punctuation\">><\/span><\/span>. I loved you not.<br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>DD<\/span><span class=\"token punctuation\">><\/span><\/span><br><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>DT<\/span><span class=\"token punctuation\">><\/span><\/span>Ophelia:<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>DT<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>DD<\/span><span class=\"token punctuation\">><\/span><\/span>I was the more deceived.<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>DD<\/span><span class=\"token punctuation\">><\/span><\/span><br><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>DT<\/span><span class=\"token punctuation\">><\/span><\/span>Hamlet:<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>DT<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>DD<\/span><span class=\"token punctuation\">><\/span><\/span><br>    Get thee to a nunnery. Why wouldst thou be a breeder of sinners? I am myself<br>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>a<\/span> <span class=\"token attr-name\">href<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>#fn2<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span>indifferent honest<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>a<\/span><span class=\"token punctuation\">><\/span><\/span> ...<br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>DD<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>DL<\/span><span class=\"token punctuation\">><\/span><\/span><br><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>fn<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>fn1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span>inoculate<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span> - graft<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>fn<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>fn<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>fn2<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span>relish of it<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span> - smack of it (our old sinful nature)<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>fn<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>fn<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>fn3<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span>indifferent honest<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span> - moderately virtuous<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>fn<\/span><span class=\"token punctuation\">><\/span><\/span><\/code><\/pre>\n<p>The current HTML Living Standard (snapshot from January\u00a022, 2021) remarks\nthat HTML does not have a dedicated mechanism for marking up footnotes and\n<a href=\"https:\/\/html.spec.whatwg.org\/multipage\/semantics-other.html#footnotes\">recommends<\/a>\nthe following options for footnotes. For short inline annotations, the <code>title<\/code>\nattribute could be used.<\/p>\n<pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>Customer<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>: Hello! I wish to register a complaint. Hello. Miss?<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>Shopkeeper<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>:<br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>span<\/span> <span class=\"token attr-name\">title<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>Colloquial pronunciation of <span class=\"token punctuation\">'<\/span>What do you<span class=\"token punctuation\">'<\/span><span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span>Watcha<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>span<\/span><span class=\"token punctuation\">><\/span><\/span> mean,<br>  miss?<br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>Customer<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>: Uh, I'm sorry, I have a cold. I wish to make a complaint.<br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>Shopkeeper<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>b<\/span><span class=\"token punctuation\">><\/span><\/span>: Sorry,<br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>span<\/span> <span class=\"token attr-name\">title<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>This is, of course, a lie.<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span>we're closing for lunch<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>span<\/span><span class=\"token punctuation\">><\/span><\/span>.<br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><\/code><\/pre>\n<p>Using <code>title<\/code> comes with an important downside, though, as the spec rightly\nnotes.<\/p>\n<blockquote>\n<p>Unfortunately, relying on the <code>title<\/code> attribute is currently discouraged as\nmany user agents do not expose the attribute in an accessible manner as\nrequired by this specification (e.g. requiring a pointing device such as a\nmouse to cause a tooltip to appear, which excludes keyboard-only users and\ntouch-only users, such as anyone with a modern phone or tablet).<\/p>\n<\/blockquote>\n<p>For longer annotations, the <code>a<\/code> element should be used, pointing to an element\nlater in the document. The convention is that the contents of the link be a\nnumber in square brackets.<\/p>\n<pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span>Announcer: Number 16: The <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span>hand<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>i<\/span><span class=\"token punctuation\">><\/span><\/span>.<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br>  Interviewer: Good evening. I have with me in the studio tonight Mr Norman St<br>  John Polevaulter, who for the past few years has been contradicting people. Mr<br>  Polevaulter, why <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>em<\/span><span class=\"token punctuation\">><\/span><\/span>do<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>em<\/span><span class=\"token punctuation\">><\/span><\/span> you contradict people?<br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br>  Norman: I don't. <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>sup<\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>a<\/span> <span class=\"token attr-name\">href<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>#fn1<span class=\"token punctuation\">\"<\/span><\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>r1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span>[1]<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>a<\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>sup<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span>Interviewer: You told me you did! ...<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>section<\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>fn1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span><br>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>a<\/span> <span class=\"token attr-name\">href<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>#r1<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span>[1]<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>a<\/span><span class=\"token punctuation\">><\/span><\/span> This is, naturally, a lie, but paradoxically if it<br>    were true he could not say so without contradicting the interviewer and thus<br>    making it false.<br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>section<\/span><span class=\"token punctuation\">><\/span><\/span><\/code><\/pre>\n<p>This approach is what most folks use today, for example,\n<a href=\"https:\/\/infrequently.org\/2020\/09\/the-pursuit-of-appiness\/#fnref-the-pursuit-of-appiness-1\">Alex Russell<\/a>\nor the\n<a href=\"https:\/\/docs.google.com\/document\/d\/e\/2PACX-1vRoZ2f7zuM362x3VzU0qs2WRH4tybO8Mf0Ybbf1PV83aYPJF9azkubMTvfpcKNj62jhGsdT5SCzWPcN\/pub?embedded=true#ftnt_ref1\">HTML export<\/a>\nof Google Docs documents.<\/p>\n<h2 id=\"the-ruby-element\">The <code>ruby<\/code> element <a class=\"direct-link\" href=\"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/#the-ruby-element\">\u2693<\/a><\/h2>\n<p>The other day, I came across a\n<a href=\"https:\/\/twitter.com\/justmarkup\/status\/1352528677892972545\">tweet<\/a> by\n<a href=\"https:\/\/justmarkup.com\/\">Michael Scharnagl<\/a>, whose website and Twitter handle\nare aptly named <em>Just Markup<\/em> and who runs a Twitter campaign this year called\n<a href=\"https:\/\/twitter.com\/hashtag\/HTMLElementInATweet?src=hash&amp;ref_src=twsrc%5Etfw\"><code>#HTMLElementInATweet<\/code><\/a>:<\/p>\n<blockquote><p lang=\"en\" dir=\"ltr\">Day 22: &lt;ruby&gt;<br><br>Represents small annotations <br><br>\u2139\ufe0f The term ruby originated as a unit of measurement used by typesetters, representing the smallest size that text can be printed on newsprint while remaining legible. <br><br><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/ruby\">developer.mozilla.org\/en-US\/docs\/Web\u2026<\/a> <br><br><a href=\"https:\/\/twitter.com\/hashtag\/HTMLElementInATweet?src=hash&amp;ref_src=twsrc%5Etfw\">#HTMLElementInATweet<\/a><\/p>&mdash; Michael Scharnagl (@justmarkup) <a href=\"https:\/\/twitter.com\/justmarkup\/status\/1352528677892972545?ref_src=twsrc%5Etfw\">January 22, 2021<\/a><\/blockquote>\n<p>I had heard about\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/ruby\"><code>ruby<\/code><\/a> in the\npast, but it was one of these elements that I tend to look up and forget\nimmediately. This time, for some reason, I looked closer and even consulted the\n<a href=\"https:\/\/html.spec.whatwg.org\/multipage\/text-level-semantics.html#the-ruby-element\">spec<\/a>.<\/p>\n<blockquote>\n<p>The <code>ruby<\/code> element allows one or more spans of phrasing content to be marked\nwith ruby annotations. Ruby annotations are short runs of text presented\nalongside base text, primarily used in East Asian typography as a guide for\npronunciation or to include other annotations. In Japanese, this form of\ntypography is also known as <em>furigana<\/em>.<\/p>\n<\/blockquote>\n<blockquote>\n<p>The <code>rt<\/code> element marks the ruby text component of a ruby annotation. When it\nis the child of a <code>ruby<\/code> element, it doesn't represent anything itself, but\nthe <code>ruby<\/code> element uses it as part of determining what <em>it<\/em> represents.<\/p>\n<\/blockquote>\n<p>You are supposed to use it like so.<\/p>\n<pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>ruby<\/span><span class=\"token punctuation\">><\/span><\/span> \u660e\u65e5 <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>rp<\/span><span class=\"token punctuation\">><\/span><\/span>(<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>rp<\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>rt<\/span><span class=\"token punctuation\">><\/span><\/span>Ashita<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>rt<\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>rp<\/span><span class=\"token punctuation\">><\/span><\/span>)<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>rp<\/span><span class=\"token punctuation\">><\/span><\/span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>ruby<\/span><span class=\"token punctuation\">><\/span><\/span><\/code><\/pre>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/ruby\">MDN docs<\/a>\ndescribe the <code>ruby<\/code> element as follows.<\/p>\n<blockquote>\n<p>The HTML <code>&lt;ruby&gt;<\/code> element represents small annotations that are rendered\nabove, below, or next to base text, usually used for showing the pronunciation\nof East Asian characters. It can also be used for annotating other kinds of\ntext, but this usage is less common.<\/p>\n<\/blockquote>\n<blockquote>\n<p>The term <em>ruby<\/em> originated\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Agate_(typography)\">as a unit of measurement used by typesetters<\/a>,\nrepresenting the smallest size that text can be printed on newsprint while\nremaining legible.<\/p>\n<\/blockquote>\n<p>Hmm \ud83e\udd14, this sounds like it could fit the footnotes use case. So I went and\ntried my luck in creating <code>ruby<\/code> HTML footnotes.<\/p>\n<h2 id=\"using-ruby-for-footnotes\">Using <code>ruby<\/code> for footnotes <a class=\"direct-link\" href=\"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/#using-ruby-for-footnotes\">\u2693<\/a><\/h2>\n<p>The markup is straightforward, all you need are\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/ruby\"><code>ruby<\/code><\/a> for the\nfootnote, and\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/rt\"><code>rt<\/code><\/a> for the\nfootnote text. I like that the footnote is just part of the flow text, so I do\nnot need to mentally switch context when writing. I also do not have to manually\nnumber my footnotes and come up with and remember the value of <code>id<\/code>s. Another\nsmall advantage is that footnotes are not part of copied text, so when you copy\ncontent from my site, you do not end up with &quot;text\u2009[2] like this&quot;. The snippet\nbelow shows the markup of a footnote.<\/p>\n<pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>body<\/span> <span class=\"token attr-name\">tabindex<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>0<span class=\"token punctuation\">\"<\/span><\/span><span class=\"token punctuation\">><\/span><\/span><br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br>    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec consectetur<br>    dictum fermentum. Vivamus non fringilla dolor, in scelerisque massa. Quisque<br>    mattis elit quam, eu hendrerit diam ultricies ut. Nunc sit amet velit<br>    posuere, malesuada diam in, congue diam. Integer quis venenatis velit. Donec<br>    quis nunc<br>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>ruby<\/span> <span class=\"token attr-name\">tabindex<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=<\/span><span class=\"token punctuation\">\"<\/span>0<span class=\"token punctuation\">\"<\/span><\/span><br>      <span class=\"token punctuation\">><\/span><\/span>vel purus<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>rt<\/span><br>        <span class=\"token punctuation\">><\/span><\/span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>rt<\/span><span class=\"token punctuation\">><\/span><\/span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>ruby<\/span><br>    <span class=\"token punctuation\">><\/span><\/span><br>    maximus dictum. Sed nec tempus odio. Vestibulum et lobortis ante. Duis<br>    blandit pulvinar lectus non sollicitudin. Nulla non imperdiet diam. Fusce<br>    varius ultricies sapien id pretium. Praesent ut pellentesque massa. Nunc eu<br>    tellus hendrerit risus maximus porta. Maecenas in molestie erat.<br>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>p<\/span><span class=\"token punctuation\">><\/span><\/span><br><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>body<\/span><span class=\"token punctuation\">><\/span><\/span><\/code><\/pre>\n<p>The CSS to make the automatic footnote numbering work is based on a\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Lists_and_Counters\/Using_CSS_counters\">CSS counter<\/a>.\nThe <code>rt<\/code> is styled in a way that it is not displayed by default, and only gets\nshown when the <code>ruby<\/code>'s <code>:after<\/code>, which holds the footnote number, is focused.\nFor this to function properly, it is important to make the <code>&lt;ruby&gt;<\/code> element\nfocusable by setting\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Global_attributes\/tabindex#content:~:text=tabindex%3D%220%22,-means\"><code>tabindex=&quot;0&quot;<\/code><\/a>.\nOn mobile devices, the <code>body<\/code> needs to be focusable as well, so the footnote can\nbe closed again by clicking\/tapping anywhere in the page. The <code>rt<\/code> element can\ncontain\n<a href=\"https:\/\/html.spec.whatwg.org\/multipage\/dom.html#phrasing-content-2\">phrasing content<\/a>,\nso links and images are all fine. Another thing to remember is to make sure the\n<code>rt<\/code> element remains visible on <code>:hover<\/code>, so links can be clicked even when the\n<code>ruby<\/code> element loses focus. I have moved the CSS <code>display<\/code> value of <code>rt<\/code> into a\nCSS custom property, so I could easily play with different values. The CSS below\nis all it takes to make the footnotes work.<\/p>\n<pre class=\"language-css\"><code class=\"language-css\"><span class=\"token comment\">\/* Behavior *\/<\/span><br><br><span class=\"token comment\">\/* Set up the footnote counter and display style. *\/<\/span><br><span class=\"token selector\">body<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">counter-reset<\/span><span class=\"token punctuation\">:<\/span> footnotes<span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/* Make footnote text appear as `inline-block`. *\/<\/span><br><span class=\"token selector\">ruby<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">--footnote-display<\/span><span class=\"token punctuation\">:<\/span> inline-block<span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/* Display the actual footnote [1]. *\/<\/span><br><span class=\"token selector\">ruby:after<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">counter-increment<\/span><span class=\"token punctuation\">:<\/span> footnotes<span class=\"token punctuation\">;<\/span><br>  <span class=\"token comment\">\/* The footnote is separated with a thin space. \ud83e\udd13 *\/<\/span><br>  <span class=\"token property\">content<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">'\u2009['<\/span> <span class=\"token function\">counter<\/span><span class=\"token punctuation\">(<\/span>footnotes<span class=\"token punctuation\">)<\/span> <span class=\"token string\">']'<\/span><span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/* Remove the focus ring. *\/<\/span><br><span class=\"token selector\">ruby:focus<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">outline<\/span><span class=\"token punctuation\">:<\/span> none<span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/* Display the footnote text. *\/<\/span><br><span class=\"token selector\">ruby:focus rt<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token function\">var<\/span><span class=\"token punctuation\">(<\/span>--footnote-display<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/* Hide footnote text by default. *\/<\/span><br><span class=\"token selector\">rt<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> none<span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/**<br> * Make sure the footnote text remains visible,<br> * so contained links can be clicked.<br> *\/<\/span><br><span class=\"token selector\">rt:hover<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token function\">var<\/span><span class=\"token punctuation\">(<\/span>--footnote-display<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p>The following CSS snippet determines the look and feel of the footnotes.<\/p>\n<pre class=\"language-css\"><code class=\"language-css\"><span class=\"token comment\">\/* Look and feel *\/<\/span><br><br><span class=\"token comment\">\/* Footnote text styling. *\/<\/span><br><span class=\"token selector\">rt<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">background-color<\/span><span class=\"token punctuation\">:<\/span> #eee<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">color<\/span><span class=\"token punctuation\">:<\/span> #111<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">padding<\/span><span class=\"token punctuation\">:<\/span> 0.2rem<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">margin<\/span><span class=\"token punctuation\">:<\/span> 0.2rem<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">max-width<\/span><span class=\"token punctuation\">:<\/span> 30ch<span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/* Images in footnote text styling. *\/<\/span><br><span class=\"token selector\">rt img<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">width<\/span><span class=\"token punctuation\">:<\/span> 100%<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">height<\/span><span class=\"token punctuation\">:<\/span> auto<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">display<\/span><span class=\"token punctuation\">:<\/span> block<span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><br><br><span class=\"token comment\">\/* Footnote styling *\/<\/span><br><span class=\"token selector\">ruby:after<\/span> <span class=\"token punctuation\">{<\/span><br>  <span class=\"token property\">color<\/span><span class=\"token punctuation\">:<\/span> red<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">cursor<\/span><span class=\"token punctuation\">:<\/span> pointer<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">font-size<\/span><span class=\"token punctuation\">:<\/span> 0.75rem<span class=\"token punctuation\">;<\/span><br>  <span class=\"token property\">vertical-align<\/span><span class=\"token punctuation\">:<\/span> top<span class=\"token punctuation\">;<\/span><br><span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p>Something I could not get to work (yet) is to make the <code>rt<\/code>'s CSS <code>position<\/code> to\nbe <code>absolute<\/code>. I got the best results so far by making the <code>rt<\/code> an inline block\nby setting the CSS property <code>--footnote-display: inline-block<\/code>. I am well aware\nof <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/ruby-align\"><code>ruby-align<\/code><\/a>\nand\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/ruby-position\"><code>ruby-position<\/code><\/a>.\nThe former does not have great browser support at the moment but seems relevant,\nand the latter seems to have no effect when I change the <code>display<\/code> value of <code>rt<\/code>\nto anything other than the UA stylesheet default, which is <code>block<\/code>. If you\nmanage to get it to work such that footnote texts open inline, floating right\nunder the footnote and not affecting the surrounding paragraph text, your help\nwould be very welcome. I also still need to look into supporting printable\nfootnotes. If you are interested, you can reach me and\n<a href=\"https:\/\/twitter.com\/search?q=from%3A%40tomayac%20url%3Ahttps%3A%2F%2Fblog.tomayac.com%2F2021%2F01%2F24%2Fruby-html-footnotes%2F&amp;src=typed_query&amp;f=live\">discuss this idea on Twitter<\/a>.<\/p>\n<h2 id=\"demo\">Demo <a class=\"direct-link\" href=\"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/#demo\">\u2693<\/a><\/h2>\n<p>I have enabled <code>ruby<\/code> footnotes right on my <ruby tabindex=\"0\">blog <rt>This is\nthe second footnote, the other is at the <a href=\"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/#top\">top<\/a>.<\/rt><\/ruby>, but you can\nalso play with a standalone <a href=\"https:\/\/ruby-footnotes.glitch.me\/\">demo<\/a> on Glitch\nand remix its\n<a href=\"https:\/\/glitch.com\/edit\/#!\/ruby-footnotes?path=style.css%3A18%3A11\">source code<\/a>.<\/p>\n<div class=\"glitch-embed-wrap\" style=\"height: 420px; width: 100%;\">\n  <iframe src=\"https:\/\/glitch.com\/embed\/#!\/embed\/ruby-footnotes?path=style.css&previewSize=100\" title=\"ruby-footnotes on Glitch\" style=\"height: 100%; width: 100%; border: 0;\" loading=\"lazy\">\n  <\/iframe>\n<\/div>\n<p>\u26a0\ufe0f Please note that this is not production ready. Support seems decent on Blink\/WebKit-based\nbrowsers, but <a href=\"https:\/\/github.com\/tomayac\/blogccasion\/issues\/27\">not so great<\/a> on Gecko-based\nbrowsers like Firefox. I have opened an <a href=\"https:\/\/github.com\/w3c\/csswg-drafts\/issues\/5891\">Issue<\/a>\nwith the CSS Working Group to hear their opinion on the idea.<\/p>\n<h2 id=\"other-approaches\">Other approaches <a class=\"direct-link\" href=\"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/#other-approaches\">\u2693<\/a><\/h2>\n<p>The &quot;standards nerd and technology enthusiast&quot;\n<a href=\"https:\/\/shkspr.mobi\/blog\/about\/\">Terence Eden<\/a> proposed to use <code>details<\/code> in a\nblog post titled\n<a href=\"https:\/\/shkspr.mobi\/blog\/2020\/12\/a-terrible-way-to-do-footnotes-in-html\/\">A (terrible?) way to do footnotes in HTML<\/a>.\nNext, <a href=\"https:\/\/www.quirksmode.org\/about\/\">Peter-Paul Koch<\/a>, web developer,\nconsultant, and trainer, runs a side project named\n<a href=\"https:\/\/www.quirksmode.org\/blog\/archives\/2020\/10\/side_project_th.html\">The Thidrekssaga and footnotes<\/a>\nwhere for the <a href=\"https:\/\/www.quirksmode.org\/ths\/\">current iteration of the site<\/a>\nhe just notes that his &quot;<em>implementation of footnotes is mostly shit<\/em>&quot;. If you\nhave yet another approach apart from what is listed here and above, please\n<a href=\"https:\/\/twitter.com\/search?q=from%3A%40tomayac%20url%3Ahttps%3A%2F%2Fblog.tomayac.com%2F2021%2F01%2F24%2Fruby-html-footnotes%2F&amp;src=typed_query&amp;f=live\">reach out<\/a>\nand I am happy to add it. And as I wrote before, I am looking for help from CSS\nexperts to make <code>rt<\/code> positioned absolutely. Sorry for the nerd-snipe.<\/p>\n\n\t\t\t<p>\n\t\t\t\t<img alt=\"Thomas Steiner\" width=\"32\" height=\"32\" src=\"https:\/\/blog.tomayac.com\/feed.php?dl=https%3A%2F%2Fblog.tomayac.com%2F2021%2F01%2F24%2Fruby-html-footnotes%2F&dp=%2F2021%2F01%2F24%2Fruby-html-footnotes%2F&dt=%3Cruby%3E%20HTML%20footnotes\" alt=\"\">\n\t\t\t\t<br\/>This post appeared first on <a href=\"https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/\">https:\/\/blog.tomayac.com\/2021\/01\/24\/ruby-html-footnotes\/<\/a>.\n\t\t\t<\/p>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\t\t\tIt is sometimes surprising to me to see what kind of use cases HTML has a<br \/>\ndedicated element for. Something that comes to mind is<br \/>\n&lt;output&gt;,<br \/>\na container element into which a site or app can inject the results of a<br \/>\ncalculation or the outcome of &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"intlwemo_wallet_address":"","footnotes":""},"categories":[],"tags":[],"class_list":["post-3350","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/posts\/3350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3350"}],"version-history":[{"count":10,"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/posts\/3350\/revisions"}],"predecessor-version":[{"id":3400,"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/posts\/3350\/revisions\/3400"}],"wp:attachment":[{"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tomayac.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}