DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • How to Verify Domain Ownership: A Technical Deep Dive
  • Make Static Sites Feel Dynamic With APIs Only (No Backend Needed)
  • Accessibility Basics for Building Telehealth Platforms With React Code Examples

Trending

  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • YAGNI in the Age of AI Coding
  • Should Developers Switch From SQLite to DuckDB?
  • SSRF Prevention in C#: Securing File Imports From User-Supplied URLs

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Languages
  4. Handling footnotes and references in HTML5

Handling footnotes and references in HTML5

By 
Axel Rauschmayer
·
Dec. 05, 11 · Interview
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
21.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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.

Requirements

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.
  • Lastly, things should degrade gracefully if JavaScript is switched off.

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?
    <p>
    <b>Shopkeeper</b>: <span title="Colloquial pronunciation of 'What do you'"
    >Watcha</span> mean, miss?
    <p>
    <b>Customer</b>: Uh, I'm sorry, I have a cold. I wish to make a complaint.
    <p>
    <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
    contradict people?
    <p> Norman: I don't. <sup><a href="#fn1" id="r1">[1]</a></sup>
    <p> Interviewer: You told me you did!
    ...
    <section>
     <p id="fn1"><a href="#r1">[1]</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>
    </section>

 

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:
    li:target {
        background-color: #BFEFFF;
    }
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 html_footnotes on GitHub and try it out online.

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: [1]

Activating the library: The library consists of CSS to style annotations and pointers and of JavaScript that post-processes the HTML so that less code has to be written.

    <link rel="stylesheet" href="footnotes.css" type="text/css">
    <script src="footnotes.js"></script>
Footnotes: 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.
    ...
    
    <h2>Footnotes</h2>

    <ol id="footnotes">
        <li>IIFE is an acronym for Immediately-Invoked Function Expression.</li>
        <li>The global scope is reified as an object in JavaScript.</li>
    </ol>
References: 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.
    JavaScript has many functional language constructs <a class="ptr">[1]</a>.
    For example: consult <a class="ptr">[2]</a> for an introduction to closures.
    ...
    
    <h2>References</h2>
    
    <ol id="references">
        <li><a href="http://en.wikipedia.org/wiki/Functional_programming"
        ><i>Functional programming</i></a>. In <i>Wikipedia</i>.
        Retrieved 2011-12-03.</li>
        
        <li>Douglas Crockford, <i>JavaScript: The Good Parts</i>.
        O’Reilly. 2008-05-16.</li>
    </ol>

Source: http://www.2ality.com/2011/12/footnotes.html

HTML

Opinions expressed by DZone contributors are their own.

Related

  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • How to Verify Domain Ownership: A Technical Deep Dive
  • Make Static Sites Feel Dynamic With APIs Only (No Backend Needed)
  • Accessibility Basics for Building Telehealth Platforms With React Code Examples

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook