CSS - Performance & Accessibility
Overview
Quick links: Exercises • Checks • Print as PDF
Estimated time: 15–20 minutes
Ensure your CSS performs well and remains accessible across devices and user needs.
Learning Objectives
- Optimize animations and paints; use
containandwill-changejudiciously. - Respect motion and color preferences; maintain visible focus.
Details & Examples
- Prefer transform/opacity animations; avoid layout-triggering properties.
containlimits layout/paint scope;will-changehints upcoming changes (use sparingly).- Use
@media (prefers-reduced-motion: reduce)to disable nonessential motion.
.tile{ contain: content; }
.btn:hover{ will-change: transform; }
@media (prefers-reduced-motion: reduce){ *{ animation:none !important; transition:none !important; } }
Checks for Understanding
- Which CSS properties are safest to animate?
Show answers
- Transform and opacity.
Exercises
- Refactor an animation to use
transforminstead of changingtop/left. - Add a reduced-motion media query that disables nonessential motion.
Suggested answers
- Replace
top/leftchanges withtransform: translate(...). @media (prefers-reduced-motion: reduce){ *{ animation:none !important; transition:none !important; }}