CSS Reference ยท Media Queries and Features
The pointer and any-pointer media features
Reference for the CSS pointer and any-pointer media features: detect fine (mouse) or coarse (touch) input and size tap targets accordingly, with examples.
The pointer media feature reports how accurate the primary pointing device is. A mouse or stylus is fine; a finger on a touchscreen is coarse. A device with no pointing at all (a keyboard-only television interface, for instance) is none. any-pointer is the same question across all available pointing devices and matches if at least one of them has the given accuracy.
The main use is making tap targets bigger for fingers while keeping a compact design for mice.
@media (pointer: coarse) { button { min-height: 48px; } }
Try it
Buttons stay compact when you have a mouse and grow when the primary pointer is coarse.
Syntax
@media (pointer: none | coarse | fine) { /* ... */ } @media (any-pointer: none | coarse | fine) { /* ... */ }
Both are discrete media features.
Values
| Value | Description |
|---|---|
none |
No pointing device is available. |
coarse |
A limited-accuracy device, such as a touchscreen. |
fine |
An accurate device, such as a mouse, trackpad or stylus. |
Usage notes
pointeris the primary device only. On a hybrid laptop the primary pointer may befineeven though the user taps the screen.any-pointer: coarsetells you a touch input exists, so it is the safer check when you want to enlarge targets for anyone who might tap.- Target size matters. Interactive elements should be comfortably large for fingers. Guidelines commonly suggest at least 44 by 44 CSS pixels.
- Not a device sniffer. Do not assume touch means a phone. Users switch between inputs.
- Combine with
hover. Mouse and trackpad usually give bothpointer: fineandhover: hover; touch givespointer: coarseandhover: none. - Prefer larger by default. If in doubt, make targets large for everyone and only compact them for
pointer: fine. - Spacing counts too. Space between small buttons can help, but real size is better.
Browser support
Supported in current versions of all major browsers; check a compatibility table for older mobile browsers.
Related
hover and any-hoverโ hover capability@mediaโ the at-rule- Lessons: Media Queries, Responsive Design