Should We Even Have :closed? | CSS-Tricks
These articles are AI-generated summaries. Please check the original sources for full details.
Should We Even Have :closed?
The CSSWG has deferred the :closed pseudo-class, leaving developers to use :not(:open) instead. This decision stems from debates over readability and specificity in 2025.
Why This Matters
While :not(:open) technically achieves the same result as :closed, it risks matching elements that aren’t open/closeable, introducing edge-case bugs. The CSSWG prioritized clarity and flexibility, acknowledging that :closed could return if consensus shifts. However, maintaining readable code often favors explicit selectors over negated ones, especially in complex stylesheets.
Key Insights
- “CSSWG deferred :closed in 2025, citing lack of consensus” (CSS-Tricks, 2025)
- “Use
:not(:open)as a workaround, but avoid applying it to non-toggleable elements” (Tab Atkins, 2022) - “Bramus notes
:read-onlywas defined as:not(:read-write)and successfully shipped” (WHATWG, 2024)
Working Example
/* Styles for open <details> element */
details:open {
background: lightblue;
color: darkred;
}
/* Styles for closed <details> element using :not(:open) */
details:not(:open) {
background: lightgray;
color: black;
}
Practical Applications
- Use Case: Style
<details>elements based on their open/closed state using:not(:open)as a fallback. - Pitfall: Applying
:not(:open)to elements like<div>(which lack open/close states) may inadvertently trigger styles.
References:
Continue reading
Next article
TamperedChef Malware Campaign Exploits Fake Installers for Persistent Access
Related Content
Thank You (2025 Edition) | CSS-Tricks
CSS-Tricks saw 20 million unique views in 2025, a 23% drop attributed to Google’s AI summaries in search results.
Future CSS: The Potential of `:drag` and `::dragged-image?`
The CSSWG proposes a `:drag` pseudo-class to simplify styling during drag-and-drop interactions, potentially eliminating the need for JavaScript.
Building Scrollytelling Experiences with CSS Scroll-Snap Events and Scroll-Driven Animation
Lee Meyer demonstrates how to utilize emergent Chromium-based scroll-snap events and scroll-state queries to create complex, interactive scrollytelling experiences.