An Exuberant Spoiler Design Utilizing the Details Element

An Exuberant Spoiler Design Utilizing the Details Element

1 Min Read

After reading Stefan Bauer’s intriguing idea for switching a video preview to an actual embedded video using a `

` element, it got me considering the potential of having a generic “toggle” in HTML. In CSS, we’ve long had the `:checked` pseudo selector, which has been extensively used to create interactive components on websites. It’s just a toggle, and creating toggles has continuously become simpler.

Furthermore, we no longer have to manipulate the structure as much to use that toggle. Previously, with only `:checked`, we needed to employ `:checked ~ .something-else` style selectors to achieve complex functionality. Now, it’s essentially unnecessary.

“`css
body:has(#toggle:checked) {
.something-else {

}
}
“`

This pattern also applies to `

` elements (toggles).

“`css
details {
&[open] {

}

body:has(&[open]) {
.something-else {

}
}
}
“`

It feels like we’re wielding a lot of power 😅.

This led me to think we could unveil another entire background (similar to a `::backdrop`) that envelops everything except the details (to draw significant attention to it, like a modal).

That’s enough creativity for a Wednesday.

You might also like