Details
The HTML <details>
element is a browser-native disclosure control
for showing and hiding a single element. Without any styling, it looks like
this:
Code editor
Details reset
Browsers style <details>
and <summary>
elements differently, so we
provide a details-reset
class to normalize them and remove the ▶ summary
marker. You can still click the word "Summary" to hide and show "Details":
Code editor
Open variants
We provide open:
utility class variants so that you can conditionally
show and hide elements within <summary>
when their parent <details>
element
is open (whenever the open
attribute is present). This is how you would
visually swap a
Code editor
The open:
variants apply to the <details>
and <summary>
elements, and
descendents of the <summary>
, and are available for:
- display utilities (
hidden
,block
, etc.) - color utilities (
bg-*
,text-<color>
, etc.) - border utilities (
border-*
, etc. for width, style, and color)
Also note that the variants only target the directly descendent summary of the open details element, which makes it possible to distinctly style nested summary elements.
Putting it all together
This example uses display, border, color, typography, and spacing utilities
with open:
variants to style a <details>
element as they're currently shown
on SF.gov:
Code editor
Guidelines
When styling <details>
:
- Use the
cursor-pointer
class on<summary>
to make it obviously clickable. - Do not use
open:
variants in the content portion (the element after<summary>
) of<details>
. They will have no effect because this element is only visible when the details element is open.