HTML & CSS / Maintainable presentation systems / Lesson 21
Respect reduced motion in an accessible disclosure
Use a native disclosure and adapt optional visual transitions to the user’s motion preference while preserving focus.
On this page
Lesson goals
- Separate essential disclosure behavior from optional motion.
- Apply a reduced-motion media query.
- Verify keyboard access and both motion preferences.
- Keep native disclosure behavior and focus independent of optional motion.
- Verify open and closed interaction under normal and reduced-motion preferences.
Choose a usable baseline
The native details and summary elements provide a disclosure that can be opened and closed without custom JavaScript. The content remains in the document and the summary provides the control. The example uses synthetic delivery text. Choose clear summary text and keep the source order meaningful. If a product requires behavior beyond the native element, define and test the additional keyboard and state requirements before replacing it.
Add optional presentation
The CSS gives the disclosure a border and padding, and adds a short color transition to the summary. The transition is optional presentation; opening and reading the content must not depend on it. A visible focus outline identifies the keyboard target. Use actual foreground and background colors that satisfy the project’s contrast requirements; currentColor alone does not prove sufficient contrast in every theme.
<details class="notice">
<summary>Delivery information</summary>
<p>Orders are prepared on business days.</p>
</details>
The summary controls the details content without requiring custom script.
Respect the user preference
The prefers-reduced-motion media query removes the optional transition when the user requests reduced motion. It does not tell the application why the preference is set, and it should not remove essential information or keyboard access. For larger animations, choose a less motion-intensive alternative where appropriate rather than simply hiding the content. Check browser support and a usable default for the target environment.
.notice {
border: 1px solid currentColor;
padding: 1rem;
}
.notice summary {
cursor: pointer;
transition: color 160ms ease;
}
.notice summary:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
.notice summary { transition: none; }
}
The focus outline remains visible and the optional transition is removed for the reduced-motion preference.
Keep state and focus clear
Native disclosure state is managed by the details element, so avoid adding conflicting custom state or redundant ARIA without a specific need. Ensure that the focus indicator is not clipped by a parent and that the content remains readable at zoom and narrow widths. If script changes the disclosure, verify that visual state and the accessible state remain synchronized and that unexpected focus movement is avoided.
Verify both preferences
Combine the blocks in a document and use a keyboard to focus and activate the summary, then close it again. Check the focus indicator and content at narrow widths and enlarged text. In browser developer tools or operating-system settings, test both normal and reduced-motion preferences and inspect the computed transition. A successful automated scan is useful evidence but does not replace manual interaction testing or establish complete accessibility compliance.
Keep disclosure independent of motion
A native details element with a meaningful summary supplies a disclosure whose open state is represented in HTML. Use it for optional information that can be revealed in the document flow, and retain the information and control when styles or scripts are unavailable. The summary should tell the reader what will be revealed; a generic icon alone may not communicate the subject. The order of the content and any following controls should remain meaningful at narrow widths and with enlarged text.
Motion is presentation around that task, not the mechanism that makes the answer available. In the fixture below, the color transition affects the summary decoration; the native open state and answer do not depend on the transition finishing. Avoid a second class or redundant ARIA state that can contradict details[open]. If the product needs custom behavior, define the additional state, keyboard and focus contract before replacing the native element.
Interpret reduced motion carefully
The prefers-reduced-motion media feature expresses a user preference to reduce nonessential motion; it does not tell the application the person’s diagnosis or reason. When the reduce condition matches, change optional animation or transition without removing the task, the answer or the control. A large slide, zoom or parallax effect may need a less motion-intensive alternative rather than merely becoming faster. The appropriate choice depends on the content and user needs.
The absence of a reduce match is not evidence that every user wants animation, and a feature query or preference rule does not prove usability. Avoid a blanket rule that accidentally suppresses an essential state indication without a replacement. Document which motion is optional and how the same information remains available. Test the preference in target browsers and settings, including live changes when the product supports them.
Coordinate state, visibility and focus
Native details maintains its own open attribute. CSS such as details[open] can reflect that real state, while :focus-visible addresses a separate condition. An open border is not a substitute for a focus indicator, and an outline that is clipped by an ancestor or covered by another element is not effectively visible. Preserve a clear summary name, check the actual colors against their surroundings and give the outline enough space.
If script adds behavior, keep any visual, DOM and accessibility state synchronized and avoid moving focus merely because an animation finished. A hidden panel must not leave invisible focusable controls in the ordinary path. On closure, decide whether focus should remain on the summary or move to a logical location based on the action; do not claim a specific browser or assistive-technology result without testing. Where independent answers support comparison, do not impose exclusivity without a reason.
Trace the sample and preference
The complete document below has one native delivery-help disclosure and a short summary color transition. The base styles provide a border and an independent focus outline. When prefers-reduced-motion:reduce matches, transition:none removes that optional transition; the summary, its answer and the native open behavior remain. The hover color can still change without an animated transition, so reducing motion does not necessarily remove every visual state change.
This is an illustrative document, not an observed keyboard, browser or assistive-technology result. In a supported target environment test the normal and reduce preferences, inspect computed transition values, activate and close the summary by keyboard, and verify the focus indicator and answer at narrow widths and zoom. Record browser, settings and actual observations rather than assuming a successful scan proves the journey.
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Delivery help</title>
<style>
details { border:1px solid; padding:1rem; }
summary { cursor:pointer; transition:color .2s ease; }
summary:hover { color:#174e9a; }
summary:focus-visible { outline:3px solid #174e9a; outline-offset:3px; }
@media (prefers-reduced-motion:reduce) { summary { transition:none; } }
</style>
<main><h1>Delivery help</h1><details><summary>When will my order arrive?</summary>
<p>Standard delivery usually takes several working days.</p></details></main>
The reduced-motion rule removes the transition while the native disclosure and focus rule remain.
Test both paths and their limits
Use a matrix that separates default presentation, reduced motion, open and closed states, long translated text, keyboard navigation and the supported assistive technologies. An automated checker may identify some missing names or contrast issues but cannot determine whether a summary is meaningful, the content suits disclosure, focus is logical or an animation is comfortable for a particular person. Manual and user-centered evaluation complement automated evidence.
Record the tested version, viewport, zoom, operating-system or browser preference and exact steps. Compare the same task under both preferences: focus the summary, open it, read the answer, close it and continue. If an optional script or animation fails, the answer should remain available through the baseline. Report unrun cases as pending and fix the specific failing condition before claiming an observed pass.
20 worked examples
1. Descriptive summary
Problem: A delivery disclosure needs a name that identifies its answer.
- The summary is the native disclosure control.
- Its question describes the information the following paragraph provides.
<details><summary>When will my order arrive?</summary><p>Delivery usually takes several working days.</p></details>
Expected result: The summary names the delivery-time question.
Why this result follows: The visible control text identifies the supplemental information.
2. Open state styling
Problem: A disclosure’s real open attribute should change its border.
- The attribute selector matches when details is open.
- It avoids maintaining a separate presentation class for the same state.
details { border:1px solid; } details[open] { border-width:3px; }
Expected result: An open disclosure has a modeled 3px border under the cascade.
Why this result follows: The selector follows the native open state.
3. Optional transition
Problem: A summary has a 200ms color transition in its baseline style.
- The declaration affects changes to the color property.
- Opening the native disclosure is not implemented by that transition.
summary { transition:color .2s ease; }
Expected result: The declared color transition duration is .2s.
Why this result follows: Presentation timing is separate from native disclosure state.
4. Reduced translation
Problem: A decorative panel translates on hover unless reduced motion is requested.
- The matching preference overrides the transform to none.
- The panel’s text remains present in both conditions.
.panel:hover { transform:translateY(-4px); } @media (prefers-reduced-motion:reduce) { .panel:hover { transform:none; } }
Expected result: The intended reduced state has no hover translation.
Why this result follows: The preference removes decorative movement without deleting content.
5. Instant state change
Problem: A hover color still changes while transition:none applies.
- Removing a transition changes how the property change is animated.
- It does not necessarily prevent the hover color declaration from applying.
summary { transition:none; } summary:hover { color:blue; }
Expected result: The color can change without an animated transition.
Why this result follows: Transition timing and the target color are separate declarations.
6. No preference condition
Problem: An optional animation is inside a no-preference media condition.
- The rule participates only when that condition matches.
- The baseline content and disclosure remain outside the condition.
@media (prefers-reduced-motion:no-preference) { .hint { animation:pulse 1s; } }
Expected result: The animation is eligible only when the condition matches.
Why this result follows: The optional motion is scoped by the preference condition.
7. Focus without animation
Problem: A focused summary has an outline even when transition is none.
- The outline rule is independent of the transition declaration.
- Removing motion need not remove the visible focus indicator.
summary:focus-visible { outline:3px solid; outline-offset:3px; } @media (prefers-reduced-motion:reduce) { summary { transition:none; } }
Expected result: The intended focus rule remains in the reduced-motion state.
Why this result follows: Focus indication and motion timing are separate concerns.
8. Boolean open
Problem: A details element is written with open="false".
- The open attribute is boolean and is present.
- The string false does not make the present attribute absent.
<details open="false"><summary>Delivery</summary><p>Several working days.</p></details>
Expected result: The initial disclosure state is open.
Why this result follows: Presence of the boolean open attribute represents the open state.
9. Separate focus and state
Problem: An open disclosure is not necessarily the focused disclosure.
- The open attribute represents expanded state.
- Focus is determined separately by the active control and browser behavior.
details[open] { border-width:3px; } summary:focus-visible { outline:3px solid; }
Expected result: The two selectors describe different conditions.
Why this result follows: An open border cannot by itself identify keyboard focus.
10. Script-independent help
Problem: A details element includes its supplemental answer in initial HTML.
- The native control and answer exist without an enhancement script.
- Optional styling can fail without removing the content from the document.
<details><summary>Delivery help</summary><p>Contact the team for a delay.</p></details>
Expected result: The initial document contains the control and answer.
Why this result follows: The baseline does not depend on script to supply its content.
11. Opacity is not hiding
Problem: A custom panel is made transparent with opacity:0.
- Opacity changes visual rendering rather than automatically removing focusability.
- A link inside may remain an unexpected keyboard stop.
.panel.closed { opacity:0; }
Expected result: Use an appropriate actual hidden or noninteractive state for a closed panel.
Why this result follows: A transparent box can still participate in interaction.
12. Synced custom panel
Problem: A custom button reports aria-expanded=false and its target has hidden.
- The state claim and the actual hidden panel agree in this snapshot.
- Opening requires updating both together in an implementation.
<button aria-expanded="false" aria-controls="answer">Delivery</button><div id="answer" hidden>Several days.</div>
Expected result: The snapshot represents a collapsed panel.
Why this result follows: Exposed state and visibility must remain synchronized.
13. No timer-dependent focus
Problem: An implementation moves focus only after a 300ms animation ends.
- The task’s focus movement is tied to decorative timing.
- A reduced-motion state may remove the animation while focus still needs a logical plan.
focus target set only on transitionend; reduced-motion transition=none
Expected result: Move focus according to the interaction contract and test both preferences.
Why this result follows: Focus behavior must not depend solely on an optional transition event.
14. Clipped outline
Problem: A summary’s ancestor uses overflow:hidden and clips its outline.
- The outline can extend beyond the summary’s border box.
- The ancestor’s clipping may hide part of that visible indicator.
.container { overflow:hidden; } summary:focus-visible { outline:3px solid; outline-offset:3px; }
Expected result: Adjust the layout or indicator and verify actual focus visibility.
Why this result follows: A declared outline is not necessarily fully visible.
15. Preference and cascade
Problem: A reduced-motion rule sets transition:none but a later equal-specificity rule sets a transition.
- Both declarations participate when the preference condition matches.
- The later rule wins if origin, importance, layer and specificity tie.
@media (prefers-reduced-motion:reduce) { summary { transition:none; } } summary { transition:color .2s; }
Expected result: The later transition wins under the stated assumptions.
Why this result follows: A media condition does not bypass the cascade.
16. Long summary
Problem: A translated summary wraps to three lines at a narrow width.
- The control’s content can need more block space.
- A fixed one-line height could clip text or the focus indicator.
summary { block-size:auto; overflow-wrap:anywhere; }
Expected result: The intended summary can grow for the longer text.
Why this result follows: Content-sized layout accommodates changed line count.
17. Meaning beyond color
Problem: An open disclosure uses a thicker border and retains a descriptive summary.
- The native open state is the real disclosure state.
- The summary and content provide meaning independently of border color.
details[open] { border-width:3px; }
Expected result: The border reinforces state without replacing content.
Why this result follows: The presentation is tied to state while text conveys the subject.
18. Preference reason unknown
Problem: A browser reports the reduced-motion preference as reduce.
- The query communicates the preference value.
- It does not identify why the user selected that preference.
@media (prefers-reduced-motion:reduce) { .decoration { animation:none; } }
Expected result: Respect the preference without inferring a diagnosis.
Why this result follows: The media feature reports a setting, not a medical explanation.
19. Optional animation fallback
Problem: A decorative animation is supported only in some target environments.
- The base answer is present and readable without the animation.
- An optional enhancement can add motion without making the answer depend on it.
.answer { display:block; } @supports (animation-name:fade) { .answer { animation:fade .2s; } }
Expected result: The essential answer remains in the baseline.
Why this result follows: The enhancement is not the only route to the information.
20. Unrun preference test
Problem: A disclosure has not been tested under normal or reduced motion.
- The source declares a preference rule and native markup.
- No computed transition, focus or activation result has been observed.
normal preference=test pending; reduce preference=test pending; keyboard=test pending
Expected result: Report both preference paths and keyboard checks as pending.
Why this result follows: A stylesheet prediction is not an observed interaction result.
Common errors and fixes
Reduced motion hides essential content
- Why it happens
- The preference rule removed the disclosure or its contents.
- How to fix it
- Reduce the optional motion while retaining the information and controls.
- Prevent it next time
- Test open and closed states under both preferences.
Keyboard focus is invisible
- Why it happens
- A custom style removed or clipped the focus indicator.
- How to fix it
- Provide a visible focus style and enough surrounding space.
- Prevent it next time
- Navigate with a keyboard at zoom and narrow widths.
Accessible and visual state disagree
- Why it happens
- Custom script or ARIA conflicts with the native disclosure state.
- How to fix it
- Use native state or synchronize any necessary enhancement carefully.
- Prevent it next time
- Test state changes with keyboard and an accessibility tree.
20 practice exercises
1. What changes when reduced motion is requested?
Show hint
Separate the optional color transition from the disclosure task.
Show worked solution
The optional summary color transition is removed. The disclosure remains available, its content can still be opened, and the focus indicator remains visible.
When reduce matches, the sample removes the summary’s color transition. The native summary, answer and focus rule remain; verify the computed transition and the actual open/close journey in both preference settings rather than assuming an observed result.
Check your solution
- The optional transition is removed in the modeled reduce state.
- The disclosure content and focus remain available in the target test.
2. Does a passing automated accessibility scan prove the interaction works for everyone?
Show hint
Combine automated findings with observed interaction.
Show worked solution
No. It can detect some defects, but keyboard behavior, visible focus, content clarity, and real assistive technology use also need appropriate manual review.
A passing scan detects only some classes of defect. Test keyboard activation, visible focus, meaningful summary and answer, and relevant assistive-technology behavior in supported environments; record unrun cases as pending rather than claiming the interaction works for everyone.
Check your solution
- Keyboard and focus are tested separately from the scan.
- The summary and answer are reviewed with actual content.
3. A page uses smooth scrolling when a disclosure’s help link targets a section. Provide a reduced-motion alternative while preserving the target.
Show hint
Scroll animation and fragment navigation are separate.
Show worked solution
Keep the link and its target intact, and set scroll-behavior:auto under the reduced-motion preference for the relevant scrolling element. Test the actual fragment navigation and focus behavior in supported browsers; removing smooth scrolling should not remove the destination.
Check your solution
- The fragment target remains available.
- Smooth scrolling is disabled under the matching preference.
4. A custom disclosure closes while focus is on a link inside its panel. Design a focus and state update.
Show hint
Do not leave focus on an element that becomes hidden.
Show worked solution
Move focus to the associated disclosure button or another logical target as part of closing, and synchronize aria-expanded with the panel’s actual hidden state. Test the close action and subsequent Tab sequence in supported browsers; do not defer necessary focus movement to decorative animation.
Check your solution
- Focus ends on a visible logical target.
- The closed panel and expanded state agree.
5. A summary contains a separate link to delivery terms, so pressing it can conflict with disclosure activation. Improve the structure.
Show hint
Separate the disclosure control from the navigation action.
Show worked solution
Use a descriptive summary such as “Delivery information” and place the terms link inside the answer or adjacent content with a real href. Test summary activation and link navigation separately with keyboard focus visible in both motion settings.
Check your solution
- The summary clearly names the disclosed subject.
- The terms link remains a separate navigation action.
6. A blue focus outline is visible on a white card but disappears on a dark theme. Design a theme-aware verification and repair.
Show hint
Evaluate the indicator against its actual adjacent colors.
Show worked solution
Choose a focus treatment that remains distinguishable against both real surfaces, and preserve sufficient space so it is not clipped. Measure the relevant color pairs under applicable requirements, then tab to the summary in light and dark themes with normal and reduced motion.
Check your solution
- Focus is visible against both theme surfaces.
- The actual color pairs and keyboard results are recorded.
7. Two FAQ answers need to remain open for comparison, but their details elements share the same name. Repair the grouping and test the result.
Show hint
A shared nonempty name establishes an exclusive details group.
Show worked solution
Remove the shared name or otherwise use independent groups when simultaneous opening is required. Open both answers and compare them in each target browser, checking their summaries and focus; do not assume the grouping supports comparison merely because both answers exist.
Check your solution
- Both disclosures can remain open in the intended behavior.
- Names and keyboard focus are checked during comparison.
8. A user changes the reduced-motion setting while a page is open. Define what the component should do and how to verify it.
Show hint
The media condition can change while the document remains active.
Show worked solution
Ensure optional motion responds to the current matching preference without closing the disclosure or losing its content. Change the setting in a supported environment, inspect the computed transition and repeat keyboard activation; record the actual browser and observed behavior.
Check your solution
- The current preference is reflected in the computed style.
- The answer and control remain available through the change.
9. A component offers an explicit pause control in addition to the system reduced-motion preference. Define how the two settings combine.
Show hint
An explicit pause should not re-enable motion prohibited by the preference.
Show worked solution
Pause decorative motion whenever the user pauses it or reduce matches, and allow motion only when the product policy permits and neither condition requests stopping it. Keep the disclosure content available and test both controls and a live preference change.
Check your solution
- Either pause or reduce stops the decorative motion.
- The disclosure remains operable in all combinations.
10. A summary has transition:color .2s, transform .4s. A reduced-motion rule should remove only the transform transition while retaining the color transition. Write the intended override.
Show hint
The transition shorthand replaces the list of transitions.
Show worked solution
Under the matching preference use transition:color .2s on the summary, placed so it wins the cascade. This retains the color transition but removes transform from the transition list; confirm that the chosen color change itself is acceptable for the product and test computed values.
Check your solution
- The reduced list contains only the color transition.
- Transform no longer has a declared transition in that list.
11. A page adds a sliding decoration only under no-preference, but the answer is initially hidden until the animation completes. Repair the baseline.
Show hint
Essential disclosure content must not depend on an optional animation event.
Show worked solution
Make the answer’s visibility follow the native disclosure state, not animationend, and keep it in the document without the optional animation. Test opening under both no-preference and reduce, including when animation is unsupported or interrupted.
Check your solution
- The answer appears when the disclosure is opened in both settings.
- The answer does not depend on animation completion.
12. A native delivery disclosure has a link in its answer. Define a keyboard journey that includes opening, visiting the link and returning.
Show hint
Check the sequence and the effect of each action.
Show worked solution
Tab to the named summary, activate it, move to the answer link and follow or otherwise test its destination, then return and close the disclosure as appropriate. Observe focus and state at each step in target browsers, including both motion preferences.
Check your solution
- The summary and answer link are reachable and named.
- Opening, navigation and return behavior are observed.
13. A status message flashes and slides into an open disclosure. Design a reduced-motion alternative that retains its information.
Show hint
Keep the message visible while reducing nonessential movement.
Show worked solution
Show the same status text without the slide or flashing when reduce matches, and preserve any necessary semantic announcement through an intentionally implemented mechanism. Test that the message appears promptly and is readable, rather than merely shortening the animation.
Check your solution
- The same status text is available without sliding or flashing.
- Any announcement behavior is tested in supported tools.
14. A decorative animation has duration .2s and runs three iterations with no delay. Calculate its modeled active duration and identify what still needs testing.
Show hint
Multiply the duration by the iteration count.
Show worked solution
The modeled active duration is .2 × 3 = .6s before delays or interruptions. That arithmetic does not show whether the motion is comfortable or frames are smooth; test the user task and the reduced-motion alternative in the target environment.
Check your solution
- The modeled active duration is .6s.
- Comfort and observed performance remain separate checks.
15. A disclosure reveals its only usage instruction through a hover-only animation. Design a non-hover path that works with reduced motion.
Show hint
Essential instructions must not depend on pointer hover or animation.
Show worked solution
Put the instruction in visible text or the native disclosure answer, and keep the summary keyboard-operable. Remove optional motion when reduce matches while retaining the same instruction; test keyboard and touch access in supported browsers.
Check your solution
- The instruction is available without hover or animation.
- Keyboard and touch paths are tested.
16. An Arabic translation makes a summary much longer than its English version. Design a content and layout check in both motion settings.
Show hint
Text length and direction can change wrapping independently of motion.
Show worked solution
Use appropriate language and direction metadata, allow the summary and card to grow, and test the actual Arabic and English strings at narrow widths and zoom. Verify the full question, focus indicator and answer under normal and reduced motion, recording the environment.
Check your solution
- The full translated summary remains readable.
- Focus and answer are checked in both preference states.
17. A global reduced-motion rule removes all animations, including an animated loading indicator that is the only status cue. Redesign the loading state.
Show hint
A status must remain understandable when its animation is removed.
Show worked solution
Keep a visible textual loading message and appropriate status semantics, then remove or replace the nonessential animation under reduce. Test loading, completion and failure with both preferences; do not rely on movement or color as the only indication.
Check your solution
- A textual loading status remains without animation.
- Completion and failure remain understandable.
18. A disclosure appears slow to open, but only a CSS transition duration is known. Design a diagnosis that distinguishes motion from application delay.
Show hint
Measure the interaction path rather than assuming the transition is the bottleneck.
Show worked solution
Record activation, any script or network work, state update and visual completion in the target environment. Compare the same content and settings with the optional transition removed, and verify that the answer and focus remain correct; report actual measurements only.
Check your solution
- The measured task includes state and any asynchronous work.
- The comparison preserves the same answer and focus behavior.
19. A component subscribes to changes in matchMedia for reduced motion, then is removed from the page. Define its cleanup contract.
Show hint
An event listener should not outlive the component that owns it.
Show worked solution
Register a named change listener that updates optional motion, and remove that same listener when the component is disposed. Keep native disclosure content available and test mounting, preference changes and removal without accumulating duplicate listeners.
Check your solution
- The named listener is removed on disposal.
- Repeated mounting does not duplicate preference handlers.
20. A delivery disclosure must work closed and open under both motion preferences at narrow width. Define a four-state verification matrix.
Show hint
Cross the two disclosure states with the two preference settings.
Show worked solution
Test closed and open with normal motion, then closed and open with reduce, at the same narrow viewport and zoom. For each record computed transition, summary name, visible focus and answer availability, plus browser and preference settings; report only observed outcomes.
Check your solution
- The matrix contains all four state/preference combinations.
- Transition, focus and content observations are recorded.
Key takeaways
- Keep essential behavior available without optional animation.
- Test reduced motion, keyboard focus, and state together.
- Reduced motion changes presentation without removing essential information.
- Native open state and keyboard focus are distinct conditions.
- Automated scans complement, but do not replace, observed interaction testing.