<metaname="description"content="How I implement accessible footnotes, at least to the best of my ability. Written for 32-Bit Cafe's Community Code Jam #5.">
<metaproperty="og:description"content="How I implement accessible footnotes, at least to the best of my ability. Written for 32-Bit Cafe's Community Code Jam #5.">
<metaname="twitter:description"content="How I implement accessible footnotes, at least to the best of my ability. Written for 32-Bit Cafe's Community Code Jam #5.">
<pclass="article__info--desc">How I implement accessible footnotes, at least to the best of my ability. Written for 32-Bit Cafe's Community Code Jam #5.</p>
<pclass="center-text"><ahref="https://32bit.cafe/~xandra/events/codejam5/"class="inline-img"><imgsrc="/assets/images/articles/accessible-footnotes/32bitcafe-backtoschool.png"alt="32-Bit Cafe "Back to School" Code Jam button"></a></p>
<pclass="center-text">(32-Bit Cafe "Back to School" button made by <ahref="https://ribo.zone/">Loren</a>)</p>
<p><ahref="https://32bit.cafe/">32-Bit Cafe</a> is holding its fifth community code jam, titled <ahref="https://32bit.cafe/~xandra/events/codejam5/">"Back to School"</a>, from 4 to 17 August 2024. I have been looking forward to participating in 32-Bit Cafe's community code jam for the first time, so I am excited. This motivates me to finally write a how-to article I have been meaning to do for a while: how to implement accessible footnotes on Leilukin's Hub, or at least, I tried to do so to the best of my abilities.</p>
<p>On <ahref="https://discourse.32bit.cafe/">32-Bit Cafe's Discourse forum</a>, I made a <ahref="https://discourse.32bit.cafe/t/handling-citations-and-or-footnotes/1061/2?u=leilukin">post on 28 June 2024</a> in response to <ahref="https://solaria.neocities.org/">solaria</a>'s thread <ahref="https://discourse.32bit.cafe/t/handling-citations-and-or-footnotes/1061">"Handling Citations and/or Footnotes"</a> to share my methods of adding footnotes on my website. Now, I am writing an extended version of that post of mine in the form of this article, so I could share what I learned about web page footnotes on my website as well.</p>
<p>(Note: This article assumes a foundational familiarity with HTML and CSS)</p>
<p>Plagiarism.org <ahref="https://www.plagiarism.org/article/what-are-footnotes">defines footnotes</a> as notes placed at the bottom of a page, and what footnotes do is to cite references or comment on a designated part of the text above it.</p>
<p>My use case of footnotes is citing sources of information, particularly citing the same source multiple times on the same page when information from the same source is spread across my page. As of this writing, my website pages that use footnotes include the <ahref="https://leilukin.com/shrines/asummersend/trivia/">trivia page of my <cite>A Summer’s End — Hong Kong 1986</cite> shrine 1</a> and the <ahref="https://leilukin.com/shrines/cassettebeasts/facts/">facts page of my <cite>Cassette Beasts</cite> shrine</a>. You are free to look at the HTML and CSS for reference, including when you are reading this article as I am explaining how I implement the footnotes.</p>
<p>Footnotes are used both on print and on the web. However, maintaining footnotes on the web can be tedious, especially if you want to update a web page to add or remove them, since you will need to change the number references of existing footnotes.</p>
<divclass="heading-wrapper h2">
<h2id="attempted-to-use-css-counters">Attempted to Use CSS Counters</h2>
<p>When I was searching for how to implement accessible footnotes, I discovered <ahref="https://kittygiraudel.com/">Kitty Giraudel</a>'s article, <ahref="https://www.sitepoint.com/accessible-footnotes-css/">"Accessible Footnotes with CSS"</a> which teaches the method of using the combination of HTML <ahref="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby"><code>aria-describedby</code></a> attribute and <ahref="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_counter_styles/Using_CSS_counters">CSS counters</a> to add numbered references, to reduce the hassle of manually re-numbering all existing footnotes in case you want to update or reorder the references.</p>
<p>Her article also teaches adding a highlight background colour when heading to a footnote from a reference, as well as providing back links to head back to a reference from a footnote, by using the combination of the backlink Unicode icon (↩) and the HTML <code>aria-label</code> attribute with a value of “Back to content”. The uses of ARIA labels make footnotes more screen reader-friendly.</p>
<p>Furthermore, Kitty created the <ahref="https://github.com/KittyGiraudel/eleventy-plugin-footnotes">eleventy-plugin-footnotes plugin</a> for the static site generator <ahref="https://www.11ty.dev/">Eleventy</a>, and wrote a blog post about it, <ahref="https://kittygiraudel.com/2020/12/02/footnotes-in-11ty/">"Footnotes in 11ty"</a>. Since I already had begun to <ahref="/blog/posts/2024-04-21-april-2024-leilukins-hub-overhaul-with-eleventy">use Eleventy to build my website</a>, I tried Kitty's plugin.</p>
<p>Unfortunately, a known limitation of using CSS counter method to generate footnotes is <ahref="https://github.com/KittyGiraudel/eleventy-plugin-footnotes/issues/83">not being able to reference the same footnote multiple times</a>. As I want to be able to reference the same footnote more than once when I am citing sources on my shrine pages, I had to give up the plugin and look for an alternative.</p>
<divclass="heading-wrapper h2">
<h2id="starting-with-markdown-it-footnote-plugins-default-footnote-markup">Starting with markdown-it-footnote Plugin's Default Footnote Markup</h2>
<p>Kitty Giraudel's blog post about creating footnotes in Eleventy mentioned <ahref="https://github.com/markdown-it/markdown-it-footnote">markdown-it-footnote</a>, the footnotes plugin for <ahref="https://github.com/markdown-it/markdown-it">markdown-it</a> Markdown parser, which is integrated in Eleventy by default to convert Markdown to HTML. Kitty commented on the accessibility shortcomings of markdown-it-footnote in the blog post:</p>
<blockquote>
<p>[...]it’s not super accessible (let alone by default), even considering all the customisation options. That’s because the footnote references end up being numbers (e.g. [1]) which are meaningless when listed or tabbed through because devoid of their surrounding context.</p>
</blockquote>
<p>That said, since the plugin is customisable, I still wanted to give it a shot to see if I could make configurations to improve its accessibility, so I installed markdown-it-footnote and looked into the plugin's default HTML markup output.</p>
<p>Here is a sample of what the HTML markup output of markdown-it-footnote looks like:</p>
<preclass="language-html"tabindex="0"><codeclass="language-html"><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>p</span><spanclass="token punctuation">></span></span>This is a paragraph with the first footnote reference. <spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>sup</span><spanclass="token attr-name">class</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>footnote-ref<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>a</span><spanclass="token attr-name">href</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>#fn1<spanclass="token punctuation">"</span></span><spanclass="token attr-name">id</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>fnref1<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span>[1]<spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>a</span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>sup</span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>p</span><spanclass="token punctuation">></span></span>
<spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>p</span><spanclass="token punctuation">></span></span>Here is the second paragraph with the second footnote reference. <spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>sup</span><spanclass="token attr-name">class</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>footnote-ref<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>a</span><spanclass="token attr-name">href</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>#fn2<spanclass="token punctuation">"</span></span><spanclass="token attr-name">id</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>fnref2<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span>[2]<spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>a</span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>sup</span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>p</span><spanclass="token punctuation">></span></span>
<spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>p</span><spanclass="token punctuation">></span></span>This the third paragraph, but with a foootnote reference that points to the first footnote. <spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>sup</span><spanclass="token attr-name">class</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>footnote-ref<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>a</span><spanclass="token attr-name">href</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>#fn1<spanclass="token punctuation">"</span></span><spanclass="token attr-name">id</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>fnref1:1<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span>[1:1]<spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>a</span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>sup</span><spanclass="token punctuation">></span></span><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>p</span><spanclass="token punctuation">></span></span>
<li>Adding a footnote reference as a superscript by using the <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup"><code><sup></code></a> tag with numbers as the content.</li>
<li>Using a <code><hr></code> horizontal line element to separate the main body of the page and the footnote section;</li>
<li>Using the <code><ol></code> tag to render the footnotes as a numbered list;</li>
<li>Each footnote list item has an <code>id</code> attribute</li>
<li>If a footnote is referenced more than once, the additional footnote references are labelled with colons.</li>
</ul>
<p>(Note: the class names were added by markdown-it-footnote, but if you do not use it, you can rename the class name to whatever you want, and even if you use markdown-it-footnote, you can still change the class names if you want to go deep into it)</p>
<p>Next step is trying to improve this HTML markup by making it accessible.</p>
<divclass="heading-wrapper h2">
<h2id="make-markdown-it-footnotes-markup-more-accessible">Make markdown-it-footnote's Markup More Accessible</h2>
<p>As pointed out by Kitty Giraudel, labelling the footnote reference as mere numbers like [1] is an accessibility shortcoming, because these reference links become meaningless when being focused on by tabbing through the links, as these reference links would be devoid of context.</p>
<p>What I did to tackle this was changing the reference labels by adding a word "Footnote" to clarify that these links are for footnotes. For example, [1] becomes [Footnote #1], so when screen readers focus on a footnote reference link, it will be read out as "Footnote number one link".</p>
<p>Optionally, if you want your footnote labels to still display only numbers on screen, you can use a CSS class to <ahref="https://www.a11yproject.com/posts/how-to-hide-content/">visually hide</a> the extra characters in the footnote label. This <code>.visually-hidden</code> utility class is a useful tool in your arsenal for accessible web design, as it is often used to hide a content that you do not mean to show on screen, but you still want it to be read by assistive technology.</p>
<p>To make my footnote reference labels display only a number on screen, I use a <code>span</code> tag with <code>visually-hidden</code> as the value of the <code>class</code> attribute to wrap around "Footnote #", so on screen, [Footnote #1] is changed to [1].</p>
<p>Next step is adding an ARIA label to the footnote backlinks, by adding an <code>aria-label</code> attribute with "Back to reference #[Insert reference number]" as its value. For example:</p>
<p>As for the CSS, in addition to using the <code>.visually-hidden</code> utility class, I refer to Kitty Giraudel's <ahref="https://www.sitepoint.com/accessible-footnotes-css/">"Accessible Footnotes with CSS"</a> article to style the highlight background color when heading to a footnote from a reference.</p>
<divclass="heading-wrapper h2">
<h2id="configure-markdown-it-footnote-in-eleventys-configuration-file">Configure markdown-it-footnote in Eleventy's Configuration File</h2>
<p>(If you do not use Eleventy, you may skip this section)</p>
<p>My final step was to configure the markdown-it-footnote plugin, by editing Eleventy's configuration file (I named mine <code>eleventy.config.js</code>), so the plugin would render my accessible footnote HTML markup.</p>
<p>If you are a fellow Eleventy user, feel free to borrow my markdown-it-footnote configurations in your own. Make sure you install markdown-it-footnote first by keying in the installation command in the terminal:</p>
<p>As you likely have realised, footnotes are really tricky to implement on web pages, so you may be wondering: is there any alternative to footnotes?</p>
<p>For extra comments and tangents, by favourite approach is using HTML's details disclosure element with the <code><details></code> tag, with a <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary"><code><summary></code></a> element and a sibling element wrapping the content displayed when the disclosure is expanded.</p>
<p>I have been using the disclosure element for additional comments or information on this website, like in my blog post, <ahref="/blog/posts/2024-06-24-cassette-beasts-fanlisting-approved/">"My Cassette Beasts Fanlisting Application has been Approved"</a>. As for the styling, initially I indented the content inside the disclosure to differentiate the disclosure content from the rest of the content of the page, but recently I switched to adding top and bottom borders after being inspired by <ahref="https://starbreaker.org/">Starbreaker</a>'s website, who also has a post about footnotes, <ahref="https://starbreaker.org/blog/tech/footnotes-no-fun-to-create-either/index.html">"Footnotes: No Fun to Create, Either"</a>.</p>
<detailsclass="content-disclosure">
<summaryclass="content-disclosure__summary">More ways to use <code><details></code> and <code><summary></code> elements</summary>
<divclass="content-disclosure__content"><p><code><details></code> and <code><summary></code> have become among my favourite HTML elements due to how useful they are. In addition to extra comments and info, Leilukin's Hub has also used the elements for the following purposes:</p>
<li>Hiding spoilers, like in my <cite>Cassette Beasts</cite> shrine article, <ahref="/shrines/cassettebeasts/articles/cassette-beasts-more-than-a-pokemon-clone/">"How Cassette Beasts is Much More than a Pokémon Clone"</a></li>
<li>Content warnings, like in my <ahref="/shrines/asummersend/gallery/"><cite>A Summer’s End — Hong Kong 1986</cite> shrine's gallery page</a>, with its styling being inspired by another Kitty Giraudel's blog post, <ahref="https://kittygiraudel.com/2022/09/04/a-content-warning-component/">"A content warning component"</a></li>
<p>As for citing sources, the simplest way would be naming and linking to the source in the main text of your page, though it does mean you may end up repeating the title of the source if you want to attribute to it more than once on your page. This was once the approach of my shrine pages, though I found the pages looked rather cluttered, so I eventually chose to use markdown-it-footnote alongside Eleventy.</p>
<p>Creating and maintaining footnotes on web pages is tricky, so I hope my article about accessible footnotes is helpful if you want to create them.</p>
<p>I am still not completely certain if my method is the best, although I tried to the best of my abilities, so I am interested in hearing feedback for my way of implementing accessible footnotes.</p>