6 min read

Accessible CSS Transitions: Build a Disclosure That Respects Reduced Motion

Build a keyboard-accessible shipping disclosure in HTML, CSS, and JavaScript. Compare linear and ease-out timing, watch how reduced motion changes the interaction, and test the result in your browser.

Start reading

You press Shipping details. The answer appears, and a small arrow turns toward it. Now tap twice in quick succession. If the arrow points down over an empty panel, the component has lost track of its state. A shorter animation might hide the problem, but you can fix it at the source.

In this guide you’ll build a disclosure with plain HTML, CSS, and a few lines of JavaScript. The panel responds on every press, the arrow can reverse halfway through a turn, and readers who prefer reduced motion get the same information immediately.

Start with two states #

A disclosure is a button that shows or hides associated content. For this one, write down what must be true after each press.

StateButton announcesShipping informationChevron
ClosedCollapsedHiddenPoints right
OpenExpandedVisiblePoints down

Closed and open shipping disclosures showing the matching button state, panel visibility, and chevron direction.

The panel’s hidden property tells the click handler which state comes next. The handler also updates aria-expanded on the button. CSS reads that attribute to aim the arrow. There is no third “animating” state to reconcile after a rapid second press. This follows the WAI disclosure pattern.

Build the disclosure #

Create an empty folder with three files named index.html, disclosure.js, and disclosure.css. Save the following snippets in those files, then open index.html in your browser. The example runs directly from disk.

1. Make the information available first #

With JavaScript disabled, the page still answers the shipping question. The paragraph starts visible and the button starts hidden. The deferred script will attach a handler before revealing the button.

html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Shipping details disclosure</title>
  <link rel="stylesheet" href="disclosure.css">
  <script src="disclosure.js" defer></script>
</head>
<body>
  <main>
    <h1>Delivery</h1>
    <button id="shipping-toggle" type="button" hidden
            aria-controls="shipping-info" aria-expanded="true">
      <span class="chevron" aria-hidden="true"></span>
      Shipping details
    </button>
    <p id="shipping-info">Orders dispatch within two business days.</p>
  </main>
</body>
</html>

2. Update the panel and the button together #

Save this as disclosure.js. When the panel is hidden, panel.hidden is true, so the next press passes true to setExpanded and opens it. A native button already handles Enter and Space. Adding another keyboard handler can toggle the panel twice.

js
const button = document.querySelector("#shipping-toggle");
const panel = document.querySelector("#shipping-info");

function setExpanded(expanded) {
  panel.hidden = !expanded;
  button.setAttribute("aria-expanded", String(expanded));
}

button.addEventListener("click", () => setExpanded(panel.hidden));
setExpanded(false);
button.hidden = false;

3. Animate just the arrow #

Save this as disclosure.css. The small triangle is decorative, so the markup hides it from assistive technology. The button’s accessible name stays “Shipping details” in both states.

css
body {
  margin: 2rem;
  color: #172b36;
  font: 1.1rem/1.5 system-ui, sans-serif;
}

#shipping-toggle {
  padding: .65em 1em;
  font: inherit;
  color: inherit;
  background: #effaf7;
  border: 1px solid #506d68;
  border-radius: .5em;
  cursor: pointer;
}

#shipping-toggle:focus-visible {
  outline: 3px solid #145eaa;
  outline-offset: 3px;
}

.chevron {
  display: inline-block;
  width: .65em;
  height: .65em;
  margin-inline-end: .35em;
  background: currentColor;
  clip-path: polygon(20% 0, 95% 50%, 20% 100%);
  transform: rotate(0deg);
}

[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

@media (prefers-reduced-motion: no-preference) {
  .chevron {
    transition: transform 180ms ease-out;
  }
}

The transition belongs on .chevron so it applies when opening and closing. Both end positions work without any transition. Only readers whose device reports no-preference get the movement. W3C reduced-motion technique

Read an easing curve #

Duration answers “when will the arrow arrive?” Easing answers “how far has it turned by now?” Imagine pausing the 180 ms turn at 90 ms. With linear, the arrow is at 45°. With CSS ease-out, it has already covered about 68% of its travel, or roughly 62°. Both arrive at 90° at the same time. The CSS keyword ease-out corresponds to cubic-bezier(0, 0, 0.58, 1). CSS Easing Functions specification

Progress versus elapsed time for linear and ease-out. Halfway through, linear has covered 50 percent of the distance and ease-out about 68 percent.

The clip stretches a trip to two seconds and uses a straight track to make the difference easy to see. Watch which marker first passes the middle of the track, then watch when each reaches the end.

Lab: Make the difference visible #

  1. Open your example and press Tab until Shipping details has the focus ring. Press Enter to open the panel, then Space to close it. Focus should stay on the button.
  2. Temporarily change 180ms to 2s and reload. Click once, then click again before the arrow finishes. The paragraph should respond on each press, even while the arrow is partway through its turn.
  3. Switch ease-out to linear and repeat. Look at the last quarter of the turn. Linear keeps a steady pace, while ease-out slows as it approaches the final angle. Restore 180ms ease-out afterward.
  4. In Chrome DevTools, open the command menu, choose Show Rendering, and emulate prefers-reduced-motion: reduce. Toggle the panel again. The arrow should point in the new direction immediately. Switch back to no-preference and repeat. Chrome Rendering panel

This side-by-side replay slows the gesture down fourfold. In both panels the shipping information appears immediately. Watch the arrow on the reduced-motion side jump directly to its final angle. On closing, the text disappears on both sides while the other arrow settles back.

Diagnose a mismatch #

SymptomWhere to lookFix
One Space press opens and closes the panelSeparate key and click handlersKeep the native button and handle its click once.
The arrow eases open but snaps shutTransition declared only under the expanded selectorPut the transition on the chevron in both states.
The panel waits after each pressVisibility tied to a timer or a transition-end handlerSet hidden in the click handler.
The content vanishes when scripts failPanel hidden in the initial markupStart with visible content and collapse it after attaching the handler.

A good final check is to disable the transition entirely. You should still be able to find the button, open it with the keyboard, read the shipping answer, and close it again.

Try the same pattern on a second disclosure. Give it its own button, panel, and unique aria-controls target. Tab between them and verify that opening one changes only the content it controls.

Written by

I’m Jordan Hudgens, a technical educator and AI engineering leader. I built the instructor-development system at Bottega University, from required onboarding and teaching observations to clearance standards and ongoing training. Today I lead an eight-person team building production AI at Encapsa and teach customer teams during every deployment.

Published guides
9
Total views
155
Average read
20 min

What did you think?

Discussion

No comments yet

Start the first thread with a question, a tip, or something you learned.