CSS Styling & Effects

CSS Cursor Styling

Control cursor appearance to provide intuitive user feedback. From basic pointers to custom cursors, enhance user experience with appropriate visual cues.

How do you change the mouse cursor in CSS?

Use the cursor property: pointer for clickable elements, text for text, not-allowed for disabled controls, grab and grabbing for draggable items, and move, wait or help where they fit. You can use a custom image with cursor: url(cursor.png) 4 4, auto;.

button        { cursor: pointer; }
button:disabled { cursor: not-allowed; }
.draggable    { cursor: grab; }
.draggable:active { cursor: grabbing; }

Interactive CSS Cursor Demo

Code Editor

<p>Hover each box to see its cursor:</p>
<div class="grid">
  <div style="cursor: pointer">pointer</div>
  <div style="cursor: text">text</div>
  <div style="cursor: move">move</div>
  <div style="cursor: grab">grab</div>
  <div style="cursor: not-allowed">not-allowed</div>
  <div style="cursor: wait">wait</div>
  <div style="cursor: help">help</div>
  <div style="cursor: zoom-in">zoom-in</div>
</div>

Preview

Cursor Fundamentals

The CSS cursor property controls the appearance of the mouse pointer when hovering over elements. It's essential for user experience, providing visual feedback about element functionality and available interactions.

Cursor Property Syntax

cursor: keyword;
cursor: url(image.png) x y, fallback;
cursor: url('data:image/svg+xml,...') hotspot-x hotspot-y, auto;

Keyword: Built-in cursor types (pointer, text, etc.)

URL: Path to custom cursor image

Hotspot: Click point coordinates in pixels

Fallback: Backup cursor if URL fails

Standard Cursor Types

CSS provides numerous built-in cursor types for different interaction patterns. Using the appropriate cursor helps users understand element behavior instantly.

Common Interactive

pointer /* Hand for links */
text /* I-beam for text */
grab /* Open hand */
grabbing /* Closed hand */

Most commonly used for interactive elements

State Indicators

wait /* Loading spinner */
progress /* Background process */
not-allowed /* Disabled */
help /* Info available */

Communicate current state or availability

Resize Controls

n-resize /* ↑ North */
se-resize /* ↘ Southeast */
ew-resize /* ↔ Horizontal */
ns-resize /* ↕ Vertical */

Indicate resizable areas and directions

Custom Cursors & Advanced Techniques

Custom Cursor Implementation

Image File Cursor

cursor: url('custom-cursor.png') 16 16, auto;
cursor: url('cursor.svg') 8 8, pointer;

Inline SVG Cursor

cursor: url('data:image/svg+xml,<svg...>') 12 12, auto;

Best practices: Keep cursor files small (<32x32px), specify hotspot coordinates, always provide fallbacks

Dynamic Cursors

.draggable {
  cursor: grab;
}

.draggable:active {
  cursor: grabbing;
}

Change cursors based on interaction state

Conditional Cursors

.button {
  cursor: pointer;
}

.button.disabled {
  cursor: not-allowed;
}

Use different cursors for different states

UX Best Practices & Accessibility

Best Practices

  • • Use pointer for all clickable elements
  • • Apply text cursor to input fields and editable text
  • • Show wait/progress cursors during loading
  • • Use not-allowed for disabled elements
  • • Provide consistent cursor behavior across the site
  • • Test custom cursors across different browsers

Accessibility Considerations

  • • Cursors should supplement, not replace, other feedback
  • • Ensure sufficient contrast for custom cursors
  • • Don't rely solely on cursor changes for state indication
  • • Test with keyboard navigation users
  • • Consider users with motor disabilities
  • • Provide alternative feedback methods
Mobile & Touch Considerations

Cursors don't exist on touch devices. Don't rely on cursor feedback for critical functionality. Always provide additional visual cues like button states, loading indicators, and clear labeling for touch users.

CSS Cursor — step by step

1 / 4
1

Built-in Cursor Values

CSS provides many cursor keywords: pointer for links, grab/grabbing for draggable items, not-allowed for disabled elements, crosshair for drawing tools.

1 of 4
💡Always Include a Fallback Cursor
When using custom cursor images, the fallback keyword after the comma is required: cursor: url('custom.cur'), pointer. If the image fails to load, the browser uses pointer instead of falling back to default.

🎯 Quick Check

Which cursor value communicates that an element is draggable?

Cursor Styling Mastered!

You've completed CSS Styling & Effects! Ready to explore more CSS topics?

CSS Cursor: summary

Key points

  • Native button elements don't show a pointer cursor by default in most browsers; many resets add it.
  • A custom cursor needs a keyword fallback at the end, such as auto.
  • Touch devices have no cursor, so never rely on it to convey information.

Frequently asked questions

›How do I make the cursor a hand on hover?

Set cursor: pointer on the element. The cursor changes automatically while the mouse is over it; you don't need :hover.

›Can I use a custom image as a cursor?

Yes: cursor: url("/cursor.png") 8 8, auto;. The numbers set the hotspot, and the image should be 32×32 pixels or smaller.