Input capabilities and preferences
Definition and purpose
A responsive interface also adapts to user preferences and input capabilities. Hover and pointer describe the primary pointing mechanism, while any-hover and any-pointer consider available mechanisms.
Motion preference
<!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; } #a, #b { background: lightblue; } #a { transition-duration: 200ms; } @media (prefers-reduced-motion: reduce) { #a { transition-duration: 0s; } } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>In the test environment with no motion preference, duration is 200ms. A reduced-motion preference changes it to zero.
Syntax and mental model
Keep actions usable with keyboard and touch by default. Use @media (hover: hover) and (pointer: fine) for optional hover enhancements; use prefers-reduced-motion: reduce to suppress nonessential motion. A preference can change while the page is open.
Optional pointer enhancement
<!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; } #a, #b { background: lightblue; } #a { padding: 16px; } @media (hover: hover) and (pointer: fine) { #a { padding: 20px; } } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> </div> </body></html>The desktop test context has a fine pointer and hover, so padding increases. Touch contexts keep the base padding.
Common mistakes
Do not remove keyboard focus outlines or make information available only on hover. Pointer capabilities do not reveal whether a keyboard is present.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Media query syntax and range comparisons. Next lesson: Responsive media and safe areas.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Input capabilities and preferences — knowledge check
Five questions on input capabilities and preferences.
What does pointer: fine describe?
Which feature considers any pointing device?
Which preference requests less motion?
Should a primary action require hover?
Can a preference change during a session?