Show and hide, a section that opens in place and a group row in a list.
<details class="cap-disclosure">
<summary>Why is example.com marked degraded?</summary>
<div class="cap-disclosure-body">
<p>Its median response over the last hour is 2.4 seconds, more than three times its median over the week (0.6 seconds).</p>
</div>
</details>
<details class="cap-disclosure" open>
<summary>What the watcher checks</summary>
<div class="cap-disclosure-body">
<p>Every five minutes it asks each site's health route for its commit, and whether its database and queue respond.</p>
<p>A site with no health route is asked for its home page; a 200 from there counts as alive and nothing more.</p>
</div>
</details>
Sections that open one at a time
<details class="cap-disclosure" name="limits" open>
<summary>Worker requests</summary>
<div class="cap-disclosure-body"><p>100,000 a day on the free plan. Resets at 00:00 UTC.</p></div>
</details>
<details class="cap-disclosure" name="limits">
<summary>D1 rows read</summary>
<div class="cap-disclosure-body"><p>5 million a day on the free plan. At the limit, reads fail until the reset.</p></div>
</details>
<details class="cap-disclosure" name="limits">
<summary>KV writes</summary>
<div class="cap-disclosure-body"><p>1,000 a day on the free plan. At the limit, the watcher cannot save its pass.</p></div>
</details>
Group row, collapsed, with its count
<div class="cap-group" data-cap="disclosure">
<button type="button" class="cap-group-toggle" aria-expanded="false" aria-controls="notices-rows"><span class="cap-group-label">Notices</span><span class="cap-sr-only">, </span><span class="cap-group-count">4</span></button>
<ul class="cap-group-rows" id="notices-rows" hidden>
<li>api: 3 dependency updates waiting, none urgent</li>
<li>docs: a reviewer's flag has waited 2 days</li>
<li>web: the TLS certificate renews in 21 days</li>
<li>blog: no backup reported yet</li>
</ul>
</div>
<details class="cap-disclosure">
<summary>A summary under the pointer</summary>
<div class="cap-disclosure-body"><p>The row takes the raised tint.</p></div>
</details>
<details class="cap-disclosure">
<summary>A summary being pressed</summary>
<div class="cap-disclosure-body"><p>The row takes the sunken tint.</p></div>
</details>
Accordion variant (shadcn's flat look), comfortable density
<div data-density="comfortable" id="accordion-specimen">
<details class="cap-disclosure" data-variant="accordion" name="faq" open>
<summary>Is it accessible?</summary>
<div class="cap-disclosure-body"><p>Yes. It is a native details element, so it works with a keyboard and a screen reader.</p></div>
</details>
<details class="cap-disclosure" data-variant="accordion" name="faq">
<summary>Is it animated?</summary>
<div class="cap-disclosure-body"><p>The panel grows and shrinks where the browser can animate to auto height, and only when motion is allowed.</p></div>
</details>
<details class="cap-disclosure" data-variant="accordion" name="faq">
<summary>Can it be styled?</summary>
<div class="cap-disclosure-body"><p>It takes its sizes from the density tokens.</p></div>
</details>
</div>
Card variant (a questions list), one open at a time
<ul id="card-specimen" style="display: grid; gap: var(--space-4); margin: 0; padding: 0; list-style: none">
<li><details class="cap-disclosure" data-variant="card" name="card-faq" open>
<summary>Does it change my billing settings?</summary>
<div class="cap-disclosure-body"><p>No. It reads the account and changes nothing.</p></div>
</details></li>
<li><details class="cap-disclosure" data-variant="card" name="card-faq">
<summary>Can I cancel anytime?</summary>
<div class="cap-disclosure-body"><p>Yes, from the settings page.</p></div>
</details></li>
</ul>
Inline, with the sign marker: in a post and under a step
<div id="inline-specimen">
<p>The plaque counts below come from three plates per dilution.</p>
<details class="cap-disclosure" data-variant="inline" data-marker="sign" id="inline-closed">
<summary>Show the counts</summary>
<div class="cap-disclosure-body"><p>10<sup>-6</sup>: 212, 198, 205. 10<sup>-7</sup>: 22, 19, 25.</p></div>
</details>
<details class="cap-disclosure" data-variant="inline" data-marker="sign" open id="inline-open">
<summary>How the titer is worked out</summary>
<div class="cap-disclosure-body"><p>The mean count at a countable dilution, divided by the volume plated and the dilution.</p></div>
</details>
<ol>
<li>Plate 100 microliters of each dilution in top agar.
<details class="cap-disclosure" data-variant="inline" data-marker="sign" data-print="hide" id="step-calc">
<summary>Calculator: titer from a plate count</summary>
<div class="cap-disclosure-body">
<p>The fields start on the lab's worked example. Enter your own numbers.</p>
<label class="cap-field-label" for="calc-count">Plaques counted</label>
<input class="cap-input" id="calc-count" inputmode="numeric" value="205">
</div>
</details>
</li>
</ol>
</div>
Expand toggle: a step's email, and a table row's detail
"accordion": shadcn's flat look, a rule between items and the chevron at the end. "card": each section its own rounded card, with a plus that turns to a cross. "inline": no box, a rule above and below, the title in the link color (a post's "Show the data", a procedure step's calculator).
size
"sm"
"sm" on the card: the compact card for a form or a list behind its title.
marker
"sign" | "triangle"
"sign": a mono plus that becomes a minus, in place of the chevron. "triangle": a small triangle at the start, as the browser's own, in place of the variant's chevron or plus.
print
"hide"
Sections are open on paper. "hide" leaves this one off the printed page (a calculator).
className
string
Group
Prop
Type
Required
Does
label
string
Yes
What the rows are: "Notices".
count
number
Yes
How many rows it holds; read as "Notices, 4".
children
ReactNode
Yes
The grouped rows, as <li> elements.
defaultExpanded
boolean
holdsCritical
boolean
Critical rows are never collapsed: true keeps the group open.
headingLevel
2 | 3 | 4
Puts the button in a heading of this level, so a person moving by heading finds the group.
ExpandToggle
Prop
Type
Required
Does
label
ReactNode
Yes
What the button says while the region is closed ("View email") and while open ("Hide email").
openLabel
ReactNode
open
boolean
Yes
onToggle
() => void
Yes
controls
string
Yes
The id of the region it shows or hides.
className
string
ExpandRows
Prop
Type
Required
Does
row
(toggle: ReactNode) => ReactNode
Yes
The row's cells. Put toggle (the button) in the first cell.
name
ReactNode
Yes
What the button names ("customer.subscription.updated"); a hidden " details" follows it unless toggleSuffix says otherwise ("payload").
One region shown or hidden by a toggle beside it: the state, and the props for the button and the region. For a list of rows that open one at a time, keep the open id in the parent instead.
setGroup
(button: HTMLElement, expanded: boolean): void
Show and hide. A <details class="cap-disclosure"> needs no JavaScript. This module runs the group rows (.cap-group): a button with aria-expanded and aria-controls that shows or hides the rows it groups. Two levels at most, and a critical item is never inside a collapsed group. No framework; the React wrapper uses the same rules. Shows or hides what one button controls (a group's rows, a step's email, the warnings past the cap) and keeps the button's state true. A button with data-open-label says that while open ("Fewer warnings") and its own words again when closed (data-closed-label, else the words it had); an expand toggle's words are its .cap-expand-label.
toggleGroup
(button: HTMLElement): void
groupDepth
(group: Element): number
How deep a group sits: 1 for a group at the top, 2 for one inside another.
enhanceExpand
(root?: ParentNode): () => void
Attaches to every expand toggle ([data-cap="expand"], a button with aria-expanded and aria-controls) under root: a press shows or hides the region it names (a step's email, a table row's detail row). Returns a function that detaches them.
enhance
(root?: ParentNode): () => void
Attaches to every [data-cap="disclosure"] group under root. A collapsed group that holds a critical item ([data-tone="crit"]) is opened, because critical items are never hidden. Returns a function that detaches them.
CSS variables
Variable
Default
--disclosure-body-gap
0
--disclosure-body-pad
0 var(--space-4) var(--space-4)
--disclosure-marker-gap
var(--space-3)
--disclosure-pad
0
--disclosure-summary-min-h
max(var(--target), var(--control))
--disclosure-summary-pad
var(--space-2) var(--space-4)
Parts and data attributes
Class
Is
.cap-disclosure
the root
.cap-disclosure-body
a part
.cap-expand-detail
its own class
.cap-expand-region
its own class
.cap-expand-toggle
its own class
.cap-group
its own class
.cap-group-count
its own class
.cap-group-heading
its own class
.cap-group-nest
its own class
.cap-group-rows
its own class
.cap-group-toggle
its own class
Attribute
Values
data-marker
signtriangle
data-print
hide
data-size
sm
data-variant
accordioncardinline
State
Read from
:active
the platform
:disabled
the platform
:focus-visible
the platform
:hover
the platform
[aria-disabled="true"]
an attribute
[aria-expanded="true"]
an attribute
[hidden]
an attribute
[open]
an attribute
Accessibility
Key
Does
Tab
Reaches each summary and each group button
Enter or Space on a summary
Opens or closes the section
Enter or Space on a group button
Shows or hides its rows; aria-expanded follows
summary is announced as a button with its expanded state by the browser; the group button sets aria-expanded itself.
Hidden rows use hidden, so they leave the accessibility tree and the tab order.