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:
See Firefox Reader View for clutter-free web pages and Use reading mode in Chrome for example.
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.
3. Buttons Are … Tempting¶
Call me addicted or whatever. Sorry for the troll. Please read on. 🥲 But I find buttons … really tempting. Part of it might come from a bit of a fear of missing out, as this comment on Lobsters argues (emphasis mine):
Footnotes are always a mandatory disruption to the flow of reading, because readers can’t tell up front whether a footnote is worth the effort or not. Like when reading on paper, a footnote should always be in view and never require interaction, so it can be read with just a glance. …
So, when I think clicking on a button might reveal more content, I click on it.
…
…
…
Now, please tell me, did you notice that “⊕” checkbox label? If so, did you click on it at first sight? Well, at least for me, I would: I can’t tell whether a footnote is worth the effort or not, so I just un-collapse it to see what it is. Sometimes, I unfortunately catch a glimpse of the very suspicious-looking symbol even before I start reading the paragraph, and have to hold back my thirst for click-click-clicks.
Also, the “⊕” symbol might be quite confusing. I mean, I wouldn’t expect an XOR or direct sum symbol there, but I also wouldn’t think of it as a hint for collapsed content: for me, it’s typically used for collapsible lists, generally located over the left margin and definitely never inlined.
And… sometimes it’s even worse, as nice people may considerately make the symbol even larger so that it can be more mobile-friendly. I actually planned to make this button do nothing. But that would be too much of a troll. 🥲 And, oh dear, how can I ever resist clicking on this juicy, squishy button?
And this is when I usually reach for Reader Mode, which, as discussed above, doesn’t really work with inline sidenotes.
Anyway, this clicking, whether tempting or not, is quite against the philosophy of Tufte CSS in my opinion:
-
Tufte CSS styles links with only underlines and no special colors, because:
Blue text, while also a widely recognizable clickable-text indicator, is crass and distracting.
-
It favors sidenotes over footnotes, because:
Sidenotes are like footnotes, except they don’t force the reader to jump their eye to the bottom of the page, but instead display off to the side in the margin.
Collapsed sidenotes, likewise, don’t force the reader to move their eyes. Instead, now they require the reader to move their fingers. And with certain styling, they can be as distracting as blue links.
Tufte CSS also explains the collapsible design:
The goal is to present related but not necessary information such as asides or citations as close as possible to the text that references them. At the same time, this secondary information should stay out of the way of the eye, not interfering with the progression of ideas in the main text.
But when sidenotes are collapsed, they are nowhere to be seen and can’t be “as close as possible”; when they are expanded, they do interrupt the text flow.
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.
Comments