Preference queries and print styles
CSS can respond to user preferences as well as screen dimensions. Supporting these preferences improves comfort and makes printed pages more useful.
✓ What you will learn in this topic
- Explain the key idea: Media features can respect preferences and tailor output for print.
- Apply the concept: Users who request reduced motion see fewer animations; printed pages omit navigation and retain readable card text.
- Avoid this common mistake:
Concept explanation
prefers-reduced-motion reports a user setting that asks for less motion. prefers-color-scheme reports a light or dark preference. A print media query can remove navigation, backgrounds, and controls that do not help on paper while preserving useful content.
Do not assume the preference query replaces a site-level control. If users can choose a theme themselves, keep the pageâs explicit choice coherent with the system preference.
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 {
scroll-behavior: auto;
animation: none;
}
}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 {
scroll-behavior: auto;
animation: none;
}
}Expected result: Users who request reduced motion see fewer animations; printed pages omit navigation and retain readable card text.
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 print {
.site-nav,
.card button {
display: none;
}
.card {
box-shadow: none;
color: #000;
}
}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
Adding many overlapping media queries without a clear progression makes the cascade difficult to predict.
Best practice
Organize conditions consistently, use content-led thresholds, and include reduced-motion or contrast considerations where appropriate.
Practice exercise
Add one breakpoint for a layout change and a reduced-motion query that removes nonessential animation. Apply it to the example above and inspect the result at a narrow and a wide viewport.
Section summary
- Media features can respect preferences and tailor output for print.
- Organize conditions consistently, use content-led thresholds, and include reduced-motion or contrast considerations where appropriate.
Knowledge check
Why use prefers-reduced-motion?
Reveal the explanation
It lets authors disable or simplify nonessential animation for users who request reduced motion.
Finish the module lessons, then take the server-scored module quiz to check your understanding.
Practical example
css@media (prefers-reduced-motion: reduce) {
.demo {
scroll-behavior: auto;
animation: none;
}
}
Expected result:
Users who request reduced motion see fewer animations; printed pages omit navigation and retain readable card text.
Hands-on practice task
Add one breakpoint for a layout change and a reduced-motion query that removes nonessential animation.
In this section
Other lessons in Media Queries and Breakpoints
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.