pointer Media Query

By  on  

This media query has not yet been implemented and is currently only a proposed spec. I've written this post to raise awareness of it and get general thoughts about it.

As more devices emerge and differences in device interaction are implemented, the more important good CSS code will become.  In order to write good CSS, we need some indicator about device capabilities.  We've used CSS media queries thus far, with checks for max-width and pixel ratios.  One new proposed CSS media query is the pointer media query;  the pointer media query provides information about how accurate the device pointer is (if present).

The pointer media query has three values:

  • none - device has no pointer
  • coarse - pointer has limited accuracy
  • fine - pointer has high level of accuracy

A fine pointer would be a mouse or a stylus-based touch screen, while a coarse pointer would be a finger-based touch screen, like an iPad, iPhone, or other tablet.  The example provided within the spec shows enlarging checkboxes and radio buttons on coarse-pointered devices:

/* 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 envision this API being used to enlarge navigation items and other prominent links when the pointer is coarse.  What would you do with the pointer media query?

Recent Features

  • By
    From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!

    My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...

  • By
    9 Mind-Blowing Canvas Demos

    The <canvas> element has been a revelation for the visual experts among our ranks.  Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead.  Here are nine unbelievable canvas demos that...

Incredible Demos

  • By
    Hot Effect: MooTools Drag Opacity

    As you should already know, the best visual features of a website are usually held within the most subtle of details. One simple trick that usually makes a big different is the use of opacity and fading. Another awesome MooTools functionality is...

  • By
    Facebook Open Graph META Tags

    It's no secret that Facebook has become a major traffic driver for all types of websites.  Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly.  And of course there are Facebook "Like" and "Recommend" widgets on every website.  One...

Discussion

  1. This is great. Is there also a way to check this with JS? I guess you could use the “animation end event” hack for this, but would be better if it’s officially supported and always in sync.

  2. DigDug2k

    The problem with this particular query is that it assumes you have one or the other, when its becoming more common to have both a fine and a course pointer. In fact, studies have constantly shown people are really really good at using two different pointing devices at the same time!

    Webdevs need to be careful that they don’t assume just because the user is on a touch screen, they’re using touch. Sites need to design to handle both (simultaneously, CSS is the oddball here because there you can’t optimize for both experiences at the same time). PointerEvents will make that easier, but they’re barely at the starting gate right now (which is good because it means this time we can design something good and not just something that matches the iPhone).

  3. Providing a live demo for something that has no implementations at all is somewhat confusing.

  4. Alex

    Do Canary

    • Alex

      … or Aurora support this?

  5. Daniel Glazman

    With my CSS WG Co-chairmanship’s hat on, this is a part of an Editor’s Draft that was *never* discussed inside the CSS WG and is *far away* from reaching the level of first public Working Draft yet. I really hope your implementation is prefixed or behind a preference. And I think you should probably not have implemented-and-released it at all without discussing it with the CSS WG first… Speaking of the proposal, ‘coarse’ is a VERY bad choice for a value since most non english speakers will not understand it, trust me on that please.

    In summary, this is a very very very early proposal, it’s still subject to major changes, and I certainly don’t want to hear in the future “we’ve implemented and shipped it, we can’t change it any more” from Mozilla :-)

    • I just found the proposal interesting — I’m not someone who implements these things at Mozilla. I’ve updated the note at the top to make it clear that this proposal has not been approved.

  6. I’d love this media query to also tell me if I’m dealing with a touchscreen or a pointer. Basically, can I use the hover effect.

    * None
    * Fine Touch (stylus)
    * Course Touch (finger)
    * Pointer (mouse)

    Maybe even a:

    * Terrible Pointer (Wiimote)

  7. Matt

    @Justin css media query level 4 is also proposing the hover media feature, check http://dev.w3.org/csswg/mediaqueries4/#hover for spec and other level 4 stuff

  8. Here’s an interesting result when trying to match the query in Chrome: http://d.pr/i/gP5r

    Very frustrating – I’m trying to find a semi-reliable way to distinguish between desktop and touch-based users for tooltips.

  9. boppy

    I just used that code for some testing. Current Results (of support)

    pointer and hover media queries are supported on iOS beginning with 9 (tested 9.3.5 on iPad) whereas it’s not working on 8 (tested 8.4 on iPhone 5S).

    Both the old iPad (mini 1, iOS 8) and the new iPad (Air 2, iOS 9) respond with pointer: coarse and hover: none.

    It gets weird if I look at my Nexus 5X with Android 7.1.1:
    With the current Chrome stable (version 54) it has pointer: coarse and no hover.
    With the current Chrome beta (version 55) it has pointer: fine and hover: hover.
    Current Firefox on Android (version 49) doesn’t know any of pointer and hover.

    Just to complete:
    My local (no touch, W10x64) Chrome beta (v55) and Edge (v38.14393) shows pointer: fine and hover: hover.
    My local Firefox (v49) and IE (11) don’t know any of pointer and hover.

  10. Awesome. Thanks. Great article, to the point and with the code. This is how articles ought to be written. No need for 13 Ways to… I’ll settle for one. Thanks you. Refreshing.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!