Animation and progressive enhancement project
Definition and purpose
Progressive enhancement keeps a complete interaction in the baseline and adds optional visual motion only when it is supported and appropriate. Build a native disclosure with readable open content before adding any animation.
Baseline disclosure
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } details { padding: 12px; border: 1px solid; } #panel { opacity: 1; } </style> </head> <body> <details id="d" open> <summary>Shipping details</summary> <div id="panel">Delivery in three business days.</div> </details> </body></html>Open content is readable without any animation. Close and reopen it using the summary.
Syntax and mental model
Use details and summary so keyboard activation and expanded state do not require a custom script. Baseline opacity is 1; opening the disclosure already reveals content. Define reveal keyframes, then apply the animation within both a no-preference media query and a feature query. A true feature query demonstrates syntax acceptance, not complete implementation or good performance. The animation is short, finite and not required to understand the state. Reduced motion users receive the same open content instantly. Transfer task: build a second disclosure with different content and a status message that is readable without movement; test with keyboard, reduced motion, and a deliberately false @supports condition (for example, display: impossible-layout). For the false branch test, change only the condition, not the baseline rules. Record whether the disclosure still opens, closes, and retains focus. Inspect animation duration and final opacity. In DevTools record open/close interactions and check whether actual layout or paint work changes; do not assert GPU acceleration from transform alone. Deliver the baseline, enhancement and test matrix.
Optional entry motion
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } details { border: 1px solid #64748b; padding: 12px; } summary { min-block-size: 44px; cursor: pointer; } summary:focus-visible { outline: 3px solid navy; } #panel { padding: 12px; background: #e2e8f0; color: #172033; opacity: 1; } @keyframes reveal { from { opacity: .25; transform: translateY(6px); } to { opacity: 1; transform: none; } } @media (prefers-reduced-motion: no-preference) { @supports (animation-name: reveal) { details[open] #panel { animation: reveal 200ms ease-out both; } } } </style> </head> <body> <details id="d" open> <summary>Shipping details</summary> <div id="panel">Delivery in three business days.</div> </details> </body></html>In a supporting browser with no reduction preference, the open panel fades and moves slightly into place. With reduced motion or the enhancement omitted, it stays readable.
Common mistakes
Never make baseline content transparent until an optional animation ends. A missing animation, skipped timeline or reduced-motion rule could leave it invisible. Do not rely on animationend to enable essential actions, or use a feature query as proof of full browser interoperability.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Themeable international component library. Next lesson: Architecture and performance audit.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Animation and progressive enhancement project — knowledge check
Five questions on animation and progressive enhancement project.
What must the baseline disclosure do?
When is optional motion enabled here?
What does a true @supports query establish?
What should a deliberately false feature query test?
Why avoid waiting on animationend for essential actions?