Lesson 35 of 50
cssCSS Accessibility – Focus Styles & Reduced Motion
9 mins
Course progress70%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 35 of 50
css9 mins
Keep these ideas in mind as you work through the lesson.
Accessibility isn’t an after‑thought – it’s a core part of a usable design system.
focus-visible matches elements that receive focus via keyboard, not by mouse click.
:focus-visible {
outline:2px solid #ff6600;
outline-offset:2px;
}
This prevents the unsightly outline that appears when clicking with a mouse, while still keeping a visible cue for keyboard navigation.
Many users set prefers‑reduced‑motion to minimise animations that can cause discomfort.
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration:0.001ms !important;
transition:none !important;
}
}
The rule essentially turns off all non‑essential motion for those users.
<button>, <nav>, <header>) whenever possible – they come with built‑in keyboard support.role only when native semantics are insufficient..modal {
display:none; /* hidden by default */
position:fixed; inset:0; background:rgba(0,0,0,.5);
align-items:center; justify-content:center; /* Flex centering */
}
.modal[open] { display:flex; }
.modal:focus-visible { outline:none; }
<div class="modal" id="myModal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<div class="dialog" tabindex="-1">
<h2 id="modalTitle">Dialog title</h2>
<p>Content …</p>
<button data-close>Close</button>
</div>
</div>
axe core or Chrome DevTools Lighthouse > Accessibility).prefers-reduced-motion and prefers-contrast.