grab
and grabbing
are two great CSS cursors you can use when you are moving things around.
Since those are not standard, it is really tricky to get them working cross browser. This article is going to show you all the available workarounds to get the best version working everywhere.
Browsers
Firefox
The grab icons were first introduced in Firefox 1.5 (November 29, 2005).
.grab { cursor: -moz-grab; } .grabbing { cursor: -moz-grabbing; } |
Chrome & Safari on Mac & Linux
The cursor were then introduced on Webkit in March 2008 but only for Mac. The cursors are also working on Linux.
.grab { cursor: -webkit-grab; } .grabbing { cursor: -webkit-grabbing; } |
Chrome Windows
However, the icons don't work on Windows. This is even more vicious as the CSS rule is being parsed and accepted, but it doesn't change the cursor. Therefore you cannot do something like this:
.grab { cursor: move; cursor: -webkit-grab; /* NOT WORKING */ } |
You have to do two distinct rules, one for Windows and one for Mac & Linux.
There is a way to get the cursor working using a custom cursor. Fortunately for us, Google already did the asset in Gmail and Google Maps.
.grab { cursor: url(https://mail.google.com/mail/images/2/openhand.cur) 8 8, move; } .grabbing { cursor: url(https://mail.google.com/mail/images/2/closedhand.cur) 8 8, move; } |
Internet Explorer 7, 8, 9
Now, as usual, Internet Explorer doesn't support everything. You cannot specify the relative position of the cursor. This is not the end of the world, we can just ignore it and the cursor will be slightly misaligned. Since the cursor isn't a pointer, this is not an issue in practice.
.grab { cursor: url(https://mail.google.com/mail/images/2/openhand.cur), move; } .grabbing { cursor: url(https://mail.google.com/mail/images/2/closedhand.cur), move; } |
I did not test IE6 nor IE10. If you know something about those please leave a comment 🙂
Opera
Opera doesn't have any support for custom cursors. So we can use the move
cursor that is less than ideal but gives the idea of movement.
.grab, .grabbing { cursor: move; } |
Conclusion
I made this jsFiddle to test all the different ways to show cursors. You can play with it to handle browsers I did not list here.
There is a viable solution for all the major browsers except Opera. Sadly, I couldn't find a way to do feature detection in order to see which version to use in which case. Also, because of the Webkit issue on Windows, you cannot make a simple sequence of rules and let the browser ignores the ones he doesn't know. You have to get a browser sniffing library and include the appropriate rule for the browser.
Some related articles that helped me come to the solution. Note that no one is successfully managing to get it working on all the browsers.