Skip to main content

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:

Loading...
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":

Loading...
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 when closed for a when open:

Loading...
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:

Loading...
Code editor

Guidelines

When styling <details>:

  1. Use the cursor-pointer class on <summary> to make it obviously clickable.
  2. 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.