Zoom, forced colors, and motion preferences
A design should remain understandable when visitors change text size, use a high-contrast mode, or request reduced motion.
✓ What you will learn in this topic
- Explain the key idea: Test preferences, zoom, and high-contrast modes as part of CSS quality.
- Apply the concept: Nonessential motion is minimized and cards retain a visible boundary in forced-colors mode.
- Avoid this common mistake:
Concept explanation
Avoid fixed-height text containers and let content reflow when zoomed. Forced-colors modes may replace authored colors, so do not depend on subtle background shades alone to show boundaries. Reduced-motion preferences should suppress nonessential transitions and animations.
Check that controls remain visible, focus is not clipped, and no content requires a motion effect to be understood.
Syntax
A CSS rule has a selector followed by declarations. Each declaration is a property and a value; the braces group the declarations that apply to matching elements.
@media (prefers-reduced-motion: reduce) {
.demo *,
.demo *::before,
.demo *::after {
animation-duration: 0.01ms;
transition-duration: 0.01ms;
}
}Example 1: a small page element
Use this HTML as the target and place the CSS in a stylesheet linked to the page, or inside a <style> element while experimenting.
<main class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></main>@media (prefers-reduced-motion: reduce) {
.demo *,
.demo *::before,
.demo *::after {
animation-duration: 0.01ms;
transition-duration: 0.01ms;
}
}Expected result: Nonessential motion is minimized and cards retain a visible boundary in forced-colors mode.
Example 2: a practical interface card
The same idea can style a reusable card on a course page. The class selector keeps the rule attached to this component rather than changing every element of that type.
<section class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></section>@media (forced-colors: active) {
.card {
border: 1px solid CanvasText;
box-shadow: none;
}
}Expected result: The course update reads as a distinct interface card, and its content follows the spacing, color, and layout choices in the rule.
Common mistake
Using display:none to hide information that a user still needs, or removing focus indicators for visual neatness.
Best practice
Test keyboard interaction, contrast, zoom, forced colors, and reduced motion; keep meaning in semantic HTML.
Practice exercise
Audit a card interface for visible focus, text contrast, zoom behavior, and states that are not conveyed by color alone. Apply it to the example above and inspect the result at a narrow and a wide viewport.
Section summary
- Test preferences, zoom, and high-contrast modes as part of CSS quality.
- Test keyboard interaction, contrast, zoom, forced colors, and reduced motion; keep meaning in semantic HTML.
Knowledge check
Why should text containers generally be allowed to grow?
Reveal the explanation
Content-driven height lets text reflow instead of being clipped.
Finish the module lessons, then take the server-scored module quiz to check your understanding.
Practical example
css@media (prefers-reduced-motion: reduce) {
.demo *,
.demo *::before,
.demo *::after {
animation-duration: 0.01ms;
transition-duration: 0.01ms;
}
}
Expected result:
Nonessential motion is minimized and cards retain a visible boundary in forced-colors mode.
Hands-on practice task
Audit a card interface for visible focus, text contrast, zoom behavior, and states that are not conveyed by color alone.
In this section
Other lessons in Accessibility and CSS
Broaden your knowledge
Related learning topics
HTML
Learn to structure accessible, meaningful web pages with a complete HTML course from first document to professional application patterns.
JavaScript
Build strong JavaScript foundations with browser examples, focused practice, beginner projects, and module quizzes.