brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the CSS :open pseudo-class styles a details, dialog or select while it is open

Css
~/tips/tip-css-open-pseudo-class

details:open > summary {

One selector covers open details, dialogs and dropdown pickers.

Styling an open details element always meant details[open], an attribute selector. There is now a pseudo-class that also covers elements whose open state is not an attribute, like a select with its picker showing.

details:open > summary {
  font-weight: 600;
}
select:open {
  outline: 2px solid #0b6bcb;
}
/* older browsers */
details[open] > summary {
  font-weight: 600;
}

:open matches details and dialog when they are open, and select and input elements while their picker is showing (a dropdown list, a date picker, a color picker). That last part is new: there was no way to style a select differently while its list was open.

For details and dialog it is mostly a nicer spelling of the attribute selector. I like it because it reads as a state, the same way :checked does.

It is recent: Chrome 133, Firefox 136 and Safari 26.5. Since an unknown pseudo-class makes the whole rule invalid, do not combine it in one selector list with the fallback. Keep details[open] as a separate rule, as above, until older versions are gone. Popovers have their own :popover-open, and :open does not match those.

Further reading: MDN: :open

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link