CSS Cursors

In CSS, the cursor property is one of the most effective tools for improving User Experience (UX). It allows you to change the appearance of the mouse pointer when it hovers over specific elements. By switching the cursor, you provide immediate visual feedback, telling the user what an element does—whether it’s clickable, draggable, or currently disabled—before they even click.

Best Practice: Always use cursors that match the expected behavior. For example, users expect a hand icon (pointer) for links. Using the wrong cursor can confuse users and make your interface feel broken.

Here are the most common values you can use for the cursor property, categorized by their typical use cases:

  • auto: The browser determines the best cursor based on the context. For instance, it displays a text cursor over text and a default arrow over empty space.
  • default: The standard platform cursor, which is usually an arrow. This is often used on non-interactive areas of a page.
  • none: The cursor is completely hidden. This is useful for immersive experiences like fullscreen video players or games where the mouse might be distracting.
  • Watch Out: Use cursor: none; with extreme caution. If you hide the cursor without providing a clear way to navigate, you may make your site completely unusable for many visitors.
  • pointer: A hand icon, which is the universal signal for a link or a clickable item. While browsers do this automatically for <a> tags, you should manually apply it to custom buttons, tabs, or interactive div elements.
  • Common Mistake: Forgetting to add cursor: pointer; to custom <button> elements or clickable <div> components. Without it, users may not realize the element is interactive.
  • text: Indicates that the text can be highlighted or selected. This is the default behavior for paragraphs and headings, but you might use it on custom input fields.
  • crosshair: Displays a thin cross. This is common in photo editing tools, map interfaces, or applications where precise selection or "drawing" is required.
  • move: Indicates that an element (like a modal window or a list item) can be moved or dragged.
  • Developer Tip: Consider using grab and grabbing for drag-and-drop interfaces. They provide even better feedback than move by showing a hand that "clenches" when the user clicks down.
  • not-allowed: Displays a circle with a line through it. This is perfect for showing that a button is disabled or that a specific action is currently blocked.
  • wait: Indicates that the application is busy in the background (e.g., saving data) and the user should wait before interacting again.
  • help: Usually appears as a question mark or a balloon. Use this for tooltips or "What is this?" icons to show that more information is available on hover.
  • resize directions (e.g., n-resize, e-resize, s-resize, w-resize): These indicate that an edge of an element can be resized in a specific cardinal direction (North, East, South, West).
  • resize diagonals (e.g., ne-resize, nw-resize, se-resize, sw-resize): These indicate that a corner can be resized diagonally. These are essential for building resizable sidebars or dashboard widgets.
  • zoom-in / zoom-out: These indicate that an image or a section of a page can be magnified or shrunk. These are commonly used in image galleries.

Beyond the built-in cursors, CSS allows you to get creative by defining custom cursors using an image. This is a great way to reinforce your brand's personality.

Example: Custom Cursor Implementation

.custom-cursor {
  /* The URL points to the image, 'auto' is the mandatory fallback */
  cursor: url('custom-pointer.png'), auto;
}
Developer Tip: When using custom cursors, ensure your image is small (ideally 32x32 pixels or smaller). Large images can be laggy or may be ignored by some browsers. You should also always provide a standard fallback like auto or pointer after the URL.

By mastering the cursor property, you can bridge the gap between a static design and a truly interactive, intuitive web application.