Tutorial

Change the Mouse Cursor in CSS With the cursor Property

Published on September 8, 2020
Default avatar

By Alligator.io and Andy Hattemer

Change the Mouse Cursor in CSS With the cursor Property

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.

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 us


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.


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!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

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

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel