Tutorial

Change the Mouse Cursor in CSS With the cursor Property

Published on September 8, 2020
authorauthor

Alligator.io and Andy Hattemer

Change the Mouse Cursor in CSS With the cursor Property

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;
}

Available Cursors

Hover over the following to see the different cursors available if you’re on a desktop/laptop computer:

General/Default Cursors

auto
default
none
pointer

Scroll Cursor

all-scroll

Status Cursors

context-menu
help
wait
progress

Selection Cursors

crosshair
cell
text
vertical-text

Drag & Drop Cursors

alias
copy
move
no-drop
not-allowed

Zoom Cursors

zoom-in
zoom-out

Grab Cursors

grab
grabbing

Resizing Cursors

e-resize
n-resize
ne-resize
nw-resize
s-resize
se-resize
sw-resize
w-resize
ew-resize
ns-resize
nesw-resize
nwse-resize
col-resize
row-resize

Custom Cursors

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:

Blue Droplet 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.

Conclusion:

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:

  1. Your users spend most of their time on other sites, so use custom cursors in a way that is consistent with other sites.
  2. Touchscreen users (mobile and tablet) won’t see custom cursors.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Alligator.io

author


Default avatar

Community Builder

Then: Learned to build the internet on DigitalOcean Community. Now: Building DigitalOcean Community on the internet.


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.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
2 Comments


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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.