This post examines what options one has for handling footnotes and references in HTML. It then presents a library that helps you with handling them.
Handling footnotes and references comes with several requirements:
- On screen, one wants to show the footnote text as close as possible to the number pointing to the footnote. Whatever solution one chooses, it should also work on touch devices. Hence, a hover-only approach is not feasible.
- In print, footnotes should be shown, as well. Hence, a tooltip-only solution is not acceptable.
The HTML5 spec recommendations for footnotes
The HTML5 specification
gives several tips on how to format footnotes.
Short inline annotations: title attribute.
<b>Customer</b>: Hello! I wish to register a complaint. Hello. Miss?
<b>Shopkeeper</b>: <span title="Colloquial pronunciation of 'What do you'"
>Watcha</span> mean, miss?
<b>Customer</b>: Uh, I'm sorry, I have a cold. I wish to make a complaint.
<b>Shopkeeper</b>: Sorry, <span title="This is, of course, a lie.">we're
closing for lunch</span>.
Longer annotations: bidirectional linking via <a>:
<p> Announcer: Number 16: The <i>hand</i>.
<p> Interviewer: Good evening. I have with me in the studio tonight
Mr Norman St John Polevaulter, who for the past few years has been
contradicting people. Mr Polevaulter, why <em>do</em> you
<p> Norman: I don't. <sup><a href="#fn1" id="r1"></a></sup>
<p> Interviewer: You told me you did!
<p id="fn1"><a href="#r1"></a> This is, naturally, a lie,
but paradoxically if it were true he could not say so without
contradicting the interviewer and thus making it false.</p>
Wikipedia-style highlighting of the currently active footnote
The CSS pseudo-selector :target
allows you to style the HTML element whose ID is the same as the page fragment identifier:
Thus, if the page URL ends with #explanation
then the following list item would be highlighted:
<li id="explanation">It works like this: ...</li>
Using the html_footnotes library
You can download the files footnotes.html
from the project html_demos
on GitHub, you can also try out footnotes.html
Terminology: An annotation is either a footnote or a reference (citation). The markers in the main text referring to those annotations are called annotation pointers.
- A footnote pointer is a number written in parentheses. Example: (1)
- A reference pointer is a number written in square brackets. Example: 
<link rel="stylesheet" href="footnotes.css" type="text/css">
The library processes the HTML so that footnote pointers are formatted as superscript and become links that, when clicked on, display the text of the footnote inline.
You can use an IIFE<a class="ptr">(1)</a> to avoid the
global namespace<a class="ptr">(2)</a> being polluted.
<li>IIFE is an acronym for Immediately-Invoked Function Expression.</li>
Reference pointers are processed and become links. The library also adds IDs to the reference list items. Due to the appropriate CSS, a list item will be highlighted and scrolled to if one clicks on a pointer.
For example: consult <a class="ptr"></a> for an introduction to closures.
><i>Functional programming</i></a>. In <i>Wikipedia</i>.