Cursors and selection
A guide and a playground: every cursor, your own SVG cursor, animated ones, clicks that pass through, and what can be selected and how it looks.
- #css
- #ux
- #accessibility
On a phone or a tablet, most of this page can’t be tried: cursors, hover and the pointer need a mouse or a trackpad. The selection demos still work.
This tool runs in your browser and needs JavaScript.
The cursor says what a click will do
Before anyone clicks, the cursor already tells them what will happen: an I-beam over text they can select, a hand over a link. The browser picks it by itself (auto), so most of the time you don’t set it at all.
Set it when an element does something the browser can’t guess from the HTML: a card you can drag, a panel edge that resizes, an image that zooms. Browsers give the hand only to links; buttons keep the arrow. Many sites, this one included, give buttons pointer too, so everything you can click looks clickable.
Use it for
grabandgrabbingfor things you drag: a card, a slider, a map.col-resizeorew-resizeon a handle between two panels.zoom-inon an image that opens bigger.progresswhile something loads but the page still works;waitonly when it really doesn’t.
Avoid
pointeron things that aren’t links or buttons: it promises a click that does nothing.none, unless you draw a cursor of your own (a game, a drawing tool).- Putting meaning only in the cursor: phones and tablets have none, and keyboard users never see it.
Hover over each one to see it; click to copy its CSS.
General
Links and status
Selection
Drag and drop
Resizing and scrolling
Zooming
Your own cursor, in SVG
Any image can be a cursor: cursor: url(…) x y, auto. The two numbers are the hotspot, the pixel that clicks, counted from the top-left corner (0 0 if you leave them out). The keyword at the end is required: it’s the cursor used when the image can’t be.
SVG fits well: a few hundred bytes of text that stay sharp and can go right in the CSS as a data URL, with no extra request. It needs a width and height of its own, and its colours written as values: a CSS variable can’t reach inside it.
Use it for
- A playful spot: a game, a drawing canvas, a hero section with character.
- A tool where precision matters, like a colour picker.
Avoid
- Anything bigger than 32 × 32: Chromium and Firefox ignore cursors over 128 × 128, and big ones hide what’s under them.
- Replacing the cursor on the whole page: some people set a bigger or higher-contrast one in their system settings, and yours replaces it.
- Links and text, where people expect the usual hand and I-beam.
Move the pointer here to try your cursor.
Cursors that move
A GIF makes a poor cursor: browsers draw only its first frame. To animate the real cursor, swap its image a few times a second from JavaScript, one small image per frame. That’s the trick behind alienmelon’s animatedWebCursors; the frames here are our own SVGs, drawn in code, and each carries its own hotspot.
Two more ways to the same thing. CSS can do it alone: cursor can be animated with @keyframes, one keyframe per frame (checked in Chromium). And a GIF can still be the source: split into frames in the browser with ImageDecoder, it moves like the rest (Safari can’t split it yet).
The other way is to leave the cursor alone and draw something that follows it: a trail, sparkles, a ghost. It’s a layer on top with pointer-events: none, so clicks still reach the page.
Use it for
- A playful corner: a game, a portfolio’s hero, an easter egg.
- A busy state you draw yourself, like a spinner while something saves.
Avoid
- Motion for people who asked for less: with
prefers-reduced-motion, keep it still (these do). - Animating the cursor everywhere: it distracts, and a timer swapping images costs battery.
- Effects that cover what’s under the pointer, where people are trying to aim.
Hover over each one: the cursor itself moves, frame by frame.
- Spinner
- Blinking block
- Pulse
One cursor per element
A heading
Some text: hover over it, then over the button.
GIFs
A GIF as a cursor stays on its first frame. Split into frames in your browser and swapped like the ones above, the same GIF moves.
Effects that follow the pointer
Move the pointer over the area.
Move the pointer here.
Clicks that pass through: pointer-events
With pointer-events: none, an element stops existing for the mouse, the finger and the pen: clicks, hover and the cursor go to whatever is underneath, as if it weren’t there.
It doesn’t stop the keyboard. A button with pointer-events: none can still be reached with Tab and pressed with Enter, so it isn’t a way to disable anything.
Use it for
- Decoration laid over content: a fade at the end of a list, or a grid over the page (this site’s background grid uses it).
- An icon inside a button, so
event.targetis the button, not the icon. - A tooltip or a badge that shouldn’t steal the hover from what’s under it.
Avoid
- Disabling a control: use the
disabledattribute, orinertfor a whole area, which stop the keyboard too. - Something that looks clickable: people will try, and nothing will happen.
Clicks: the button 0, the striped layer 0.
Now try Tab and Enter: the keyboard reaches the button either way.
What can be selected: user-select
People select text all the time: to copy it, to translate it, to look a word up, or just to keep their place while reading. user-select decides what a press and drag picks up.
none makes an element unselectable, text makes it selectable again inside one that isn’t, and all selects the whole element at once: one click and it’s ready to copy. Safari still needs the prefixed -webkit-user-select (only its preview version has the plain one), so write both.
Use it for
allon something people copy whole: a command, an ID, a short code.noneon controls you drag or double-click a lot, where a stray selection gets in the way: a drag handle, a slider, a game board.
Avoid
noneon content: text people can’t select is text they can’t copy, translate or quote.- Thinking it protects anything: the text is still in the page, one “view source” away.
user-select: noneYou can’t select this sentence.
user-select: autoThis one you can, as usual.
user-select: allpnpm data:symbols
none + textNot this part, but this part, yes.
You selected: nothing yet
The colour of a selection: ::selection
Selected text gets the system’s colours unless you set ::selection. Only a few properties work there: color, background-color, text-decoration, text-shadow and the -webkit-text-stroke ones. A background image is ignored.
This site selects in its brand colour, with the page’s background colour for the text. Safari on iPhone and iPad ignores ::selection and keeps the system’s.
Use it for
- Matching selections to your brand, as long as the text stays readable.
Avoid
- Low contrast: selected text still has to be read, at 4.5:1 like any other text.
- Changing it just for looks: people know what a selection looks like on their own system.
Select this paragraph, or press the button, to see your colours on real text. Selected text is still text: it has to be read.
Contrast 11.83:1 · passes AAA