Progressive disclosure with HTML

Robin penned a little love letter to the details element. I agree. It is a joyous piece of declarative power.

That said, don’t go overboard with it. It’s not a drop-in replacement for more complex widgets. But it is a handy encapsulation of straightforward progressive disclosure.

Just last week I added a couple of more details elements to The Session …kind of. There’s a bit of server-side conditional logic involved to determine whether details is the right element.

When you’re looking at a tune, one of the pieces of information you see is how many recordings there of that tune. Now if there are a lot of recordings, then there’s some additional information about which other tunes this one gets recorded with. That information is extra. Mere details, if you will.

You can see it in action on this tune listing. Thanks to the details element, the extra information is available to those who want it, but by default that information is tucked away—very handy for not clogging up that part of the page.

<details>
<summary>There are 181 recordings of this tune.</summary>
This tune has been recorded together with
<ul>
<li>…</li>
<li>…</li>
<li>…</li>
</ul>
</details>

Likewise, each tune page includes any aliases for the tune (in Irish music, the same tune can have many different titles—and the same title can be attached to many different tunes). If a tune has just a handful of aliases, they’re displayed in situ. But once you start listing out more than twenty names, it gets overwhelming.

The details element rides to the rescue once again.

Compare the tune I mentioned above, which only has a few aliases, to another tune that is known by many names.

Again, the main gist is immediately available to everyone—how many aliases are there? But if you want to go through them all, you can toggle that details element open.

You can effectively think of the summary element as the TL;DR of HTML.

<details>
<summary>There are 31 other names for this tune.</summary>
<p>Also known as…</p>
</details>

There’s another classic use of the details element: frequently asked questions. In the case of The Session, I’ve marked up the house rules and FAQs inside details elements, with the rule or question as the summary.

But there’s one house rule that’s most important (“Be civil”) so that details element gets an additional open attribute.

<details open>
<summary>Be civil</summary>
<p>Contributions should be constructive and polite, not mean-spirited or contributed with the intention of causing trouble.</p>
</details>

Have you published a response to this? :

Responses

Arpit

@adactio Hey Jeremy, I really enjoyed reading your article. Thanks for sharing.

Also, it looks like you linked to the same tune (The Maid Behind The Bar) when you meant to compare it with some other tune.

# Posted by Arpit on Monday, April 17th, 2023 at 9:24am

3 Shares

# Shared by Sam Minnée on Saturday, April 15th, 2023 at 7:54am

# Shared by Martin Grubinger on Saturday, April 15th, 2023 at 8:57am

# Shared by Arpit on Monday, April 17th, 2023 at 9:33am

7 Likes

# Liked by Emma Builds 🚀 on Saturday, April 15th, 2023 at 7:54am

# Liked by Toby on Saturday, April 15th, 2023 at 8:22am

# Liked by Jono Ferguson on Saturday, April 15th, 2023 at 8:22am

# Liked by Martin Grubinger on Saturday, April 15th, 2023 at 8:57am

# Liked by Chris Taylor on Saturday, April 15th, 2023 at 8:57am

# Liked by Danilo Vega on Saturday, April 15th, 2023 at 10:33am

# Liked by Alan Dalton on Saturday, April 15th, 2023 at 11:30am

Related posts

Train coding

Generating a static copy of The Session from the comfort of European trains.

Preventing automated sign-ups

Here’s a bit of PHP I’m using on The Session.

Speculation rules

A performance boost in Chrome.

Installing progressive web apps

How I’m letting people know they can install The Session to their home screens.

Media queries with display-mode

I never would’ve known about the `display-mode` media feature if I hadn’t been writing about it.

Related links

abc to SVG | CSS-Tricks

Aw, this is so nice! Chris points to the way that The Session generates sheet music from abc text:

The SVG conversion is made possible entirely in JavaScript by an open source library. That’s the progressive enhancement part. Store and ship the basic format, and let the browser enhance the experience, if it can (it can).

Here’s another way of thinking of it: I was contacted by a blind user of The Session who hadn’t come across abc notation before. Once they realised how it worked, they said it was like having alt text for sheet music! 🤯

Tagged with

CSS { In Real Life } | I’ve Been Doing Blockquotes Wrong

It’s pretty easy to write bad HTML, because for most developers there are no consequences. If you write some bad Javascript, your application will probably crash and you or your users will get a horrible error message. It’s like a flashing light above your head telling the world you’ve done something bad. At the very least you’ll feel like a prize chump. HTML fails silently. Write bad HTML and maybe it means someone who doesn’t browse the web in exactly the same way as you do doesn’t get access to the information they need. But maybe you still get your pay rise and bonus.

So it’s frustrating to see the importance of learning HTML dismissed time and time again.

Tagged with

Building a robust frontend using progressive enhancement - Service Manual - GOV.UK

Oh, how I wish that every team building for the web would use this sensible approach!

Tagged with

HTML Web Components Can Have a Little Shadow DOM, As A Treat | Scott Jehl, Web Designer/Developer

This is an interesting thought from Scott: using Shadow DOM in HTML web components but only as a way of providing sort-of user-agent styles:

providing some default, low-specificity styles for our slotted light-dom HTML elements while allowing them to be easily overridden.

Tagged with

HTML Web Components Make Progressive Enhancement And CSS Encapsulation Easier! | CSS-Tricks

Three great examples of HTML web components:

What I hope is that you now have the same sort of epiphany that I had when reading Jeremy Keith’s post: HTML Web Components are an HTML-first feature.

Tagged with

Previously on this day

7 years ago I wrote The audience for Going Offline

A book about service workers that doesn’t assume any prior knowledge of JavaScript.

10 years ago I wrote 100 words 024

Day twenty four.

10 years ago I wrote Hope

Judicious hope.

19 years ago I wrote Dichotomy

Not everything is black and white.

20 years ago I wrote Mo betta selecta

Aaron Gustafson is one smart cookie.

20 years ago I wrote Fixed fashion

Slap your PayPal payment down for the latest issue of Design In Flight, the PDF magazine for design professionals and web developers.

22 years ago I wrote Safari Public Beta 2

There’s a new Public Beta of Safari available for download.

23 years ago I wrote The grocer's apostrophe

While I was in town earlier today, I spotted these stickers posted up on every available surface.