Categories
Websites

Super Simple Sidenotes

I never bothered to document how I do sidenotes because they’re basically a simplified version of other implementations. But several people have asked about them, so in the spirit of sharing, here are my Super Simple Sidenotes. No javascript, just html and css.

To figure these out, I referred to Gwern’s roundup of ways others had implemented sidenotes. I don’t recall exactly which implementation I adapted, but I believe mine are most similar to Matthew Buttrick’s, displayed on the right instead of the left.

My use case

I use asides for added commentary, not for references. They are often “color text” that in a formal piece of writing would absolutely get cut, but that allow me to express more personality without (overly) disrupting the writing. They’re often the kind of thing I’d lean over and whisper (I’m terrible to watch movies with πŸ˜…). Sometimes I use them for caveats or acknowledgments that I’m leaving something out. Basically, my sidenotes don’t demand rigor like an academic’s.

How my sidenotes work

  • They always display — no clicking required
  • They display in the right margin on desktop and inline on mobile / smaller screens
  • They are their own block element — an aside — rather than marked up text inside a paragraph
  • No links are involved, just the power of the reader’s cognition and cultural knowledge that the asterisk symbol indicates there is a note with more info somewhere

It’s just text, visually rendered in a way that denotes its superfluity to the main argument. I use semantic markup <aside> rather than purely decorative <span>. (ADDED 2/4: see Evan’s comment with some suggestions for markup that might be a better choice than <aside>!)

CSS

I added this code to the whole site in WordPress under “Customize” > “Additional CSS”.

The following lines style the sidenotes themselves. I’ve set them up with a semi-transparent background with rounded corners. The only thing you really need here is the display.

.sidenote {background: rgba(255, 255, 255, 0.25);
padding:0.5em 0.75em;
border-radius:9px;
font-size: 85%;
color: #6d6d6d;
list-style-type: none;
display: block;
}

Default lists are indented on my site, so this removes indentation of bullets inside of a sidenote (since they’re pretty skinny):

.sidenote ul {margin-left:0;margin-bottom:2rem;}

These lines apply a size to the sidenotes — I used existing media breakpoints from my theme — you do need to define a width:

@media all and (min-width:1250px) {
.sidenote {width:15em !important;}
}

@media all and (min-width:1000px) and (max-width:1249px) {
.sidenote {width:10em !important;}
}

These next lines position the sidenotes — the precise placement would depend on your layout*. The second line (li > aside.sidenote) controls the positioning of sidenotes within bullet points:

@media all and (min-width:1000px) {
.sidenote {position:absolute;
margin:-5em 0 0 calc(50% + 31rem) !important;
}
li > aside.sidenote {
margin:-5em 0 0 32em !important;
}
}

I set a negative top margin so the aside block would be pulled slightly higher alongside the paragraph above it.Β I needed the !important tag to override defaults in my theme.

@media all and (max-width:999px) {
.sidenote {
float: inherit;
position: inherit;
top:0;
width: calc(100%-4rem) !important;}
}

HTML

I insert sidenotes into a post by manually wrapping text in <aside class="sidenote"> </aside>. I use WordPress’s classic code editor, so I’m not sure exactly how this works in the block editor. I believe this could be turned into a shortcode like [sidenote], I haven’t bothered though.

If you don’t use asides anywhere else on your site, I think you could just style all asides that way so you don’t have to specify a class each time. I have multiple aside styles, so I can’t get away with that.

Considerations

Asides break paragraphs on mobile so must be inserted after a line break (not mid-paragraph). Since I prefer short paragraphs for readability, I’m fine with that tradeoff. I’ll use an asterisk to mark the reference point within a paragraph if needed. I think this wouldn’t be an issue if I had used spans instead of asides?

These are super simple, so they are not “smart” — if you put two sidenotes too close together, they will overlap on desktop*. My solution? Edit the text till they don’t, or combine multiple sidenotes into one <aside>, indicating the split with one * and two ** asterisk markers. This is a little sloppy but readers are smart, they’ll figure it out πŸ€·β€β™€οΈ I am more writer than coder, so I’d rather keep it simple and flex my writing muscles to fix any issues from “dumb” layout elements.

By Tracy Durnell

Writer and designer in the Seattle area. Reach me at [email protected] or @[email protected]. She/her.

8 replies on “Super Simple Sidenotes”

Great write-up, Tracy. Thanks for sharing!

I just wanted to shed a little light on a couple of things you said. Hope that’s ok.

“Asides break paragraphs on mobile…” The aside element is not actually permitted inside a paragraph in HTML. Paragraphs are only allowed to contain “flow content” and an aside is not flow content. So what browsers do if they find an aside inside a paragraph is end the paragraph, start the aside, and then the remaining text following the aside is just left outside of any HTML element (it’s just a text node). (You also probably end up with an empty paragraph tag after the text node.) Likely this was only obvious on mobile because you left the aside in the normal document flow, rather than pulling it to the side, but the underlying structure of the document is broken everywhere if you put an aside inside a paragraph.

The other thing I want to mention is that my friend Ben (https://benmyers.dev/) convinced me to switch from using an aside element to using a div with role=”note” on it instead. The reason being that an aside has an ARIA role of complementary, which is content that is related to the main text, **but can stand on its own, if separated**. Complementary elements on the page create landmarks for assistive technology, so that users can jump from landmark to landmark. Arguably, it doesn’t make much sense for someone to be jumping from side note to side note without the context of the preceding paragraph, which is why the note role is, perhaps, more appropriate. Notes are a “section whose content represents additional information or parenthetical context to the primary content it supplements.” Which might be more appropriate in your use case?

In any case, the distinction between the complementary and note roles is subtle, and not always clear cut (like a lot of ARIA). So please don’t think I’m trying to correct you, or argue that you should change your code. I only mention it because you seemed interested in using semantically appropriate HTML (and because I, personally, find this stuff interesting, and maybe you do too?).

Thank you for taking the time to share this Evan! I’m not a web dev and though I try to do the right thing accessibility-wise, I find keeping up with what “the right thing” is overwhelming. For whatever reason I particularly find ARIA confusing, so I appreciate your explanation of landmarks. Always more to learn! πŸ˜„πŸ« 

It feels like web writers shouldn’t have to figure out for themselves how to mark up a relatively common component of longer format writing (i.e. sidenotes, endnotes, footnotes). (I’m also still annoyed there’s no standard spoiler tag πŸ˜‚). The web, for as much as we treat it as well-worn in, still has a lot of basics to iron out. (I started reading The Gutenberg Parenthesis this week which highlights just how long it took after the printing press was developed for social changes / media changes to truly develop, and posed the question: what if we are still in the small changes stage of the web, and the big changes to society are yet to come? Not sure I’m sold, but an interesting framing.)

Glad I’m not the only one! Though it would be better if it were simpler πŸ˜‰

I think Meryl’s got a healthy philosophy there.

Some reviews sound like it gets into the weeds in the second part, but I’ve enjoyed the first part so far.

This looks super helpful! I’ve been interested in doing something like this, so I appreciate the writeup.

A funny thing happened: this page was linked from shellsharks.com’s β€œScrolls” newsletter and I went to put the link in my notes, it turned out I already had it there from when the post was first published! Guess it really is applicable.

Leave a Reply

Your email address will not be published. Required fields are marked *

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)