cursor is used to change the mouse cursor on specific elements. This is especially useful in web apps where different tasks can be done other than clicking. This obviously only works when there’s a pointing device:
.in-progress {
cursor: progress;
}
Hover over the following to see the different cursors available if you’re on a desktop/laptop computer:
You can define custom cursors. Note that not all browsers support svg files for cursors, and .cur files are supported across the board, so it can be a good idea to provide a .cur fallback if you want to use an svg cursor. You can also provide a fallback to one of the non-custom cursors.
You can define a custom position for the cursor hotspot by adding x & y coordinates for where the hotspot should be in the provided custom image.
Note that, when using svg cursors, it’s important that your svg has width & height values on the root svg element, or else your cursor won’t show. In the following example, our svg file (droplet.svg) starts like this:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 42" width="42" height="42">...
.custom-cur {
cursor: url('/images/droplet.svg');
}
/* With a .cur fallback */
.custom-cur {
cursor: url('/images/droplet.svg'),
url('/images/droplet.cur');
}
/* With a custom hotspot */
.custom-cur {
cursor: url('/images/droplet.svg') 10 12;
}
/* With a non-custom fallback: */
.custom-cur {
cursor: url('/images/droplet.svg'),
move;
}
Here’s an example with a custom cursor:
Browser Support: As of 2020, only 80% of browsers worldwide support custom cursors according to Can I Use css3-cursors?. But this isn’t surprising, many of the browsers that don’t support it are mobile-only browsers that have no use for cursors.
Custom cursors are most commonly used to indicate that an HTML element that’s not already a link <a href="...">
is clickable. But it provides a diverse set of additional configurability that could be useful to developers building rich web apps. Keep the following caveats in mind when using custom cursors:
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thanks for this article, very helpful! :)
Totally complete explanation, thanks guys.