CSS can control the appearance of a cursor. There are a ton of options available to us and we’ve covered them pretty thoroughly in the ol’ Almanac here on CSS-Tricks.
Still, it’s easy to overlook cursors and their impact on the user experience of our sites. Remember when we learned ::selection
was a thing and every site started using it to personalize the background color of text selections? Customizing cursors is just as easy and adds that extra bit of understated flourish when used correctly.
In this post I’ll cover two ways I think controlling the cursor in CSS can improve user experience.
Using the Correct Cursor on an Element
Some cursor changes are built into the User Agent Stylesheet. Look at <a>
links as an example. Even if we do nothing else in our CSS, links will have color: blue;
and text-decoration: underline;
. That’s a solid visual indicator that the hyperlinked text is clickable.
Browsers take it a bit further. Hover over the link and the cursor changes from the default black arrow to a hand with its index finger extended, otherwise known as a pointer.
There are some times where the default cursor behavior from the User Agent Stylesheet doesn’t cut it. In these cases, we ought to change the cursor to something that reflects the expected user interaction on that element.
Take the jQueryUI draggable()
function. We can apply that to an element and it will allow a user to click and drag that element around the viewport, but the user never know that if the cursor remains in its default state. Adding cursor: move;
to the element would help solve that.
See the Pen QNqMRp by Geoff Graham (@geoffgraham) on CodePen.
The same is true for any number of scenarios, whether we’re talking about form inputs, images, or just about anything else you can imagine. Always take the opportunity to match an element’s cursor to its behavior when the default arrow isn’t enough of a clue. Here’s a demo of everything currently available:
See the Pen The Cursors! by Chris Coyier (@chriscoyier) on CodePen.
Using a Custom Cursor to Enhance an Element
What about custom cursors, you ask? As in, an image of your own creation tha takes the place of a cursor. Of course that’s possible!
We can point the cursor
property to an image like this:
.module {
cursor: url('path-to-image.png'), auto;
}
I find this comes in handy when adding just a touch of personalization fits, but the user might not expect it. For example, a form where the answer to a question corresponds to a specific emotion:
See the Pen qZjwGe by Geoff Graham (@geoffgraham) on CodePen.
I found working with emoji to be a bit of a trick in and of itself. You can copy and paste emoji from a site like this, then paste it into a text editor and save it as a PDF, which can then be opened in Illustrator. From there, I was able to select the image, paste it into Photoshop and create a PNG image with a transparent background. Boom!
For those of you curious about SVG, I’m happy to say it’s a go! The cursor
property does accept SVG files in all its glory. No animated GIF’s though, sadly.
See the Pen QNgoQW by Geoff Graham (@geoffgraham) on CodePen.
So no animated cursors sadly, unless you do something crazy like hide the cursor (cursor: none;
), track the mouse position with JavaScript, and display something entirely custom.
Um, like this!
See the Pen Animation following cursor by tamm (@tamm) on CodePen.
Other examples from around the web
It’s harder to find good examples of custom cursors than you might think. Perhaps it’s not as widely used as other CSS features or it is something we’re still trying to figure out, but here are a few sites where it’s been put to good use.
I agree with the article regarding using the correct cursor for an element, however I highly dislike the use of custom cursors unless the interaction behind the cursor is obvious. The emoji example, while just an example is not at all clear to what the user interaction should be. Accessibility should not be lost and so one should tread carefully if choosing to implement this.
Yes i agree, and another thing is that there is no guarantee the other parts of the website’s pictures/theme will not clash with the desired cursor colour in choice .. have you ever experienced that feeling of ‘where did my cursor go?’….
Totally agree Melanie, replacing the cursor with something unfamiliar is disorientating for the user, even if the intention is to be “fun” or “quirky”. If an author really really wanted to do this they should at least include the image of the expected cursor along with their custom image. In the emoji example above it would be more clear that the call to action was to ‘click’ if the default
cursor: pointer
icon was displayed, with the addition of a smilie face as an enhancement rather than a replacement.That said, you would still run into issues because default cursor icons can be visually different across platforms. It’s a slippery slope!
If you like rock n roll, check out the cursors on this site :D http://radiokdug.com/
Ha! That’s freaking rad — thanks for sharing. :)
I love you just for the link! :D
Haaa, legit implementation.
It’s a real shame that hand-dragging cursors are still a vendor prefixed thing. Should really go into CSS specs imo.
Do you mean cursor: grab | grabbing? In fact, they are already in the spec (even not as an at-risk feature) and are supported by Firefox without prefix (since version 27, according to MDN).
Oh, nice. Seem to have missed that one. Thanks for mentioning! :)
You must also consider that because handheld devices make up the majority of website visitors these day, cursors are less important that they used to be.
I don’t know about less important, but just another context to consider. :)
I’m not sure SVG cursor support is all that deep. IMO, anything other than PNG isn’t such a safe bet.
Yeah, looking at all the browsers and things in which SVG doesn’t work properly with some CSS feature or some special stacking effect or filters, it make me feel very sad. I love SVG and everytime that I include in a project it complicate so much to create so many workarounds that sometimes I feel like going back to raster.
Don’t do this. Changing the cursor should be done only when absolutely needed. Changing the cursor is unpredictable cross browser and can lead to usability issues and frustrated users. I agree that changing the cursor to “move” when doing a drag&drop is a good idea, or to “pointer” when that element should be clickable.
When you take touch screens into account of your design, you probably will have to find other ways to express the interaction models than replying on hover. In which case, you can still change the cursor to optimize for desktop users, but why bother to add this redundant design element?
Because if there is a cursor, having it signaling the wrong type of interaction is really confusing, even if the element without cursor would be clear enough. Look at the input fields (search box, name, e-mail, response) – their purpose is very clear. But try what happens when the cursor doesn’t change, or changes to something wrong (like the wait-icon). Same goes for links that are very clearly links by being coloured text and perhaps have underlining, or buttons that are very distinctly buttons – on touch screens none of those would be a problem, but if we have a cursor, we expect it to convey certain information, and so it should do exactly that.
I fairly understood types of coursors
How could i use font icon in cursor ?
Super handy. I was just looking for this. Thanks.
If you like rock n roll, check out the cursors on this site :D http://radiokdug.com/
Thats what I said…
This could totally help communicate “hidden” actions on something like a timeline chart, where clicking a point does something.. Say it expands something and the cursor had a little expand image/icon next to it.
Next on CSS-Tricks: sweet animated burning skulls using SVG’s and background MIDI’s with the < audio > tag.
In all seriousness, there are many good uses for the re-specifying the stock UA cursors. I have yet to see an image-file cursor respec that wasn’t a bad choice.
User experience helps in decreasing bounce rates and can improve conversion ratio, thus it is important to have an engaging site. Enterprise web content management services like Sitefinity CMS, WordPress etc are potentially powerful platforms allowing developer to deliver attractive digital experiences. CSS can implement attractive tasks however over using of CSS can make a page heavy. Make sure that the balance is maintained between page loading time and user experience. Using caching tools may help if the website has too much of CSS on it.
Great write-up, thanks Geoff.
The content of the fourth Codepen (custom cursor methods: SVG, PNG, etc) rendered inconsistently for me across browsers. I didn’t see anything in the article about browser compatibility so presume they should be robust?
I didn’t have time to poke around in the code but this is what I experienced under Windows 8.1 Pro:
Chrome 49 – Working: SVG, Base64 PNG, PNG. Broken: Base 64 SVG, GIF
Firefox 45 – Working: Base64 PNG, PNG. Broken: SVG, Base 64 SVG, GIF
IE11 – Working: None. Broken: All.
Hi please i have a question different from what was posted , on this site the background different types of background , how do i make the background that looks like TILES like one of the ones on this site?
Sorry typos “This site has different kinds of backgrounds ………………….” , how do i do the background that looks like Tiles?