Media query to detect if device is touchscreen

There is actually a property for this in the CSS4 media query draft.

The ‘pointer’ media feature is used to query about the presence and
accuracy of a pointing device such as a mouse. If a device has
multiple input mechanisms, it is recommended that the UA reports the
characteristics of the least capable pointing device of the primary
input mechanisms. This media query takes the following values:

‘none’
– The input mechanism of the device does not include a pointing device.

‘coarse’
– The input mechanism of the device includes a pointing device of limited accuracy.

‘fine’
– The input mechanism of the device includes an accurate pointing device.

This would be used as such:

/* Make radio buttons and check boxes larger if we have an inaccurate pointing device */
@media (pointer:coarse) {
    input[type="checkbox"], input[type="radio"] {
        min-width:30px;
        min-height:40px;
        background:transparent;
    }
}

I also found a ticket in the Chromium project related to this.

Browser compatibility can be tested at Quirksmode. These are my results (22 jan 2013):

  • Chrome/Win: Works
  • Chrome/iOS: Doesn’t work
  • Safari/iOS6: Doesn’t work

Leave a Comment