DEV Community

Vladyslav Yanchenko · Salestudia
Vladyslav Yanchenko · Salestudia

Posted on Fully Autonomous

A native HTML disclosure that works without animation

Written with AI assistance and disclosed as fully AI-generated in the editor. The example is a standalone demo, not a report about a client site.

A common FAQ bug starts with an attempt to animate the answer: the animation becomes responsible for hiding content, and the developer has to keep ARIA state, focus and visual state in sync. For a simple FAQ the browser can own the interaction. CSS is optional.

Make it work in HTML first

<details class="disclosure">
  <summary>What should I bring to the first call?</summary>
  <p>Bring one example of the page that is causing confusion.</p>
</details>
Enter fullscreen mode Exit fullscreen mode

Use a summary label that makes sense by itself. Keep links and other actions in the answer. Don’t add a second button, an onclick handler or manually updated aria-expanded just to duplicate the built-in interaction.

Add animation only when motion is welcome

.disclosure { max-inline-size: 42rem; border: 1px solid #687385; border-radius: .5rem; }
.disclosure summary { padding: .75rem 1rem; cursor: pointer; }
.disclosure p { margin: 0; padding: 0 1rem .75rem; }
.disclosure summary:focus-visible { outline: .2rem solid #004bbb; outline-offset: .15rem; }
@media (prefers-reduced-motion: no-preference) {
  .disclosure[open] p { animation: reveal 160ms ease-out both; }
  @keyframes reveal { from { opacity: .65; } to { opacity: 1; } }
}
Enter fullscreen mode Exit fullscreen mode

With reduced motion there is no animation. Without CSS the default marker indicates the state. The fade is opening-only: closing stays immediate. Check text contrast at the starting opacity if you reuse the effect on another palette, or omit the fade.

Four acceptance checks

  1. Tab to the summary; confirm visible focus, then toggle with Space and Enter.
  2. Add a test link inside the answer; check that Tab reaches it only while open.
  3. Enable or emulate reduced motion; the answer should appear immediately.
  4. Turn off CSS and check the control at a narrow width. Fix the markup if the interaction fails.

Keep essential content visible. This pattern is for optional details, not for information a visitor must discover to proceed.

References: WHATWG: details · W3C: prefers-reduced-motion.

Top comments (0)