Would you reconsider your Tufte CSS sidenotes?
TL;DR: Using “clever CSS tricks” for Tufte CSS, or sidenotes, is probably a bad idea, as inlining sidenotes as the official Tufte CSS does can cause trouble for browser reader modes or mobile devices.
This is an expansion of my rant in a comment on Lobsters about Tufte CSS. I think it might be helpful to have something you can link to, with screenshots/demonstrations of how things might fail. So here we go.
However, before we start, please note that this page is not designed for viewing on narrow screens like phones. So if you are reading on a mobile device, I would recommend scrolling through the post for a feeling of sidenotes, and then turning on Reading Mode (if your browser has one).1
I tested the page on Firefox and (Ungoogled) Chromium. If your browser supports Reading Mode but you can’t open this page with it, please let me know!
These two are footnote examples, by the way.
1. Tufte CSS Sidenotes/Margin Notes¶
Sidenotes are nice, and Tufte CSS beautifully demonstrates a way to incorporate sidenotes into the Web to be compatible with both wider views and narrower screens, with a little bit of CSS magic. 2
Like this! This is a sidenote.
Tufte CSS builds its sidenotes and margin notes upon inlined HTML elements plus a rather well-known CSS checkbox trick:
-
You write your sidenote inline, like this:
As it is one of the few styles that default to using serif fonts ( they use the ET Book font, a font designed by Dmitry Krasny, Bonnie Scranton, and Edward Tufte ), I love Tufte CSS nevertheless.
-
Then, you wrap your note up with a
spanelement with a label as the sidenote reference:As it is one of the few styles that default to using serif fonts
<label>...</label><span class="sidenote">( they use the ET Book font, a font designed by Dmitry Krasny, Bonnie Scranton, and Edward Tufte )</span>, I love Tufte CSS nevertheless. -
With
tufte.css, the note should now be extracted from its context by browsers’ layout engines, and displayed on the side, just like any sidenote does:As it is one of the few styles that default to using serif fonts ( they use the ET Book font, a font designed by Dmitry Krasny, Bonnie Scranton, and Edward Tufte ), I love Tufte CSS nevertheless.
Sidenotes are automatically numbered using CSS counters in Tufte CSS. (This page doesn’t do that, though.)
-
Since sidenotes take a significant portion of horizontal space, they don’t really fit on mobile screens or narrow browser windows:
You probably don’t want your text to get clamped to the left half of the already narrow screen:
As it is one of the few styles that default to using serif fonts ( sidenote ), I love Tufte CSS nevertheless.
Or, if you are reading on a rather narrow screen right now, you probably don’t want your text to look like this page. :p
Tufte CSS makes use of the checkbox CSS hack to make sidenotes collapsible on narrower screens:
As it is one of the few styles that default to using serif fonts ( they use the ET Book font, a font designed by Dmitry Krasny, Bonnie Scranton, and Edward Tufte ), I love Tufte CSS nevertheless.
(For the sake of demonstration, I didn’t style the checkbox. You may try toggling the checkbox to see how it controls the display of the “sidenote”.)
This sounds really good: mobile-friendly, JavaScript-less sidenotes! Also, arguably, sidenotes are actually better suited on the web than footnotes, as web pages are quite different from book pages, and the footnotes, if placed in the “footer” of a web page, can be a pain to navigate to.3 I’ve seen quite a few blog sites heavily using Tufte-CSS-like sidenotes and they all work pretty well… until they don’t.
Unless they provide links and backlinks to jump back and forth between footnotes and their references.
2. Inline Sidenotes Break Semantics¶
The main problem is that HTML does not really expect a less important, collapsible, floating, potentially display: block element to reside in a paragraph. And text selection, reader modes, screen readers, etc. all build on the same premise.
2.1. Non-intuitive text selection¶
Text selection can be non-intuitive with inline sidenotes:
As it is one of the few styles that default to using serif fonts They use the ET Book font, a font designed by Dmitry Krasny, Bonnie Scranton, and Edward Tufte. , I love Tufte CSS nevertheless.
The above showcases what text you will actually select if you drag your mouse from “serif fonts” to “Tufte CSS”. I’m not sure what most people would expect when they try to select (and maybe copy) from “serif fonts” to “Tufte CSS”, but I certainly don’t want the sidenote to be included, as the selected/copied text will be:
serif fonts They use the ET Book font, a font designed by Dmitry Krasny, Bonnie Scranton, and Edward Tufte. , I love Tufte CSS
It can certainly get more chaotic if you put more sentences or block elements into your sidenotes; or it may be less so, depending on whether you spend the time to tailor the sidenote clauses to their context.
2.2. Puzzling text flow¶
Reader modes4 (and M-x eww, if I may, or any other text-mode browsers) and screen readers follow more or less the same DOM-based logic. They ignore those fancy CSS stylings and lay out text as it appears in the DOM, just like our previous text selection example. This means what looks like a pretty sidenote might turn out to be disastrous:
In print, Tufte has used the proprietary Monotype BemboSee Tufte’s comment in the Tufte book fonts thread. font.
The above text copies and pastes (and also displays in Firefox Reader View) like this:5
In print, Tufte has used the proprietary Monotype BemboSee Tufte’s comment in the Tufte book fonts thread. font.
Yup, currently there is no space between “Bembo” and “See”.
And EWW displays it like:
In print, Tufte has used the proprietary Monotype Bembo[ ] See Tufte’s comment in the Tufte book fonts thread. font.
And TalkBack reads it (when opened in Firefox for Android) as follows:
In print, Tufte has used the proprietary Monotype Bembo _ one _ one _ space _ See Tufte’s comment in the _ Tufte book fonts _ link _ thread. _ font.
I’m not sure about TalkBack and other screen readers: to me, a sighted, English-as-a-second-language reader, inline sidenotes actually sound more “contextual” than sidenotes extracted into separate paragraphs. But as an Emacs user, I definitely wish these sidenotes worked better in text-mode browsers.
4. My Sidenotes¶
Astute readers might have noticed that there are two (or three?) kinds of notes on this page:
-
Fake sidenotes, for demonstration purposes only.
I didn’t bother implementing CSS counters for these notes, so they are always numbered “1”. Like this, I guess? Also, they don’t have backlinks.
- Footnote-based notes:
Like this! These footnotes are properly numbered and have backlinks.
The fake ones are indeed written in raw HTML, but the footnotes are directly generated from my Org-mode file, with a few workarounds to split up the footnote section. If you can convince your markup compiler to let you place the footnotes as you wish, then the following should generate the same footnotes-as-sidenotes for you:
-
Write your sidenotes as footnotes, and place them right below the paragraph that references them:
I'm sure this is also a CSS hack. [^1] [^1]: Feel free to roast me. :) Another paragraph. - Now that the DOM is semantically correct, we can use all kinds of CSS hacks to make the footnotes appear on the side.8 And then make sure the footnotes remain as non-
floatblocks of footnotes on mobile with media queries. - Enjoy!
However, as you might notice, other blog posts on this blog don’t actually use any sidenotes: there are only footnote blocks, whether you are on a mobile device or not.9 One of the reasons is that I don’t think I can make those sidenotes actually align with their references with CSS.10 But another reason is that I now think of “footnote blocks” as a way of manual “pagination” (or as lubricant, as a way to cheat when I’m too lazy to make two paragraphs logically coherent). I insert them where I see fit to insert a slight disruption, and just make sure they also look good and read smoothly in their textual, markup form, as plain-text files should.
I implemented this instead on another, more academically focused blog.
Also, unfortunately this blog has a sidebar (intentionally hidden on this page), which leaves very little space for sidenotes.