Tailwind CSS Cursor
The cursor property controls how the mouse pointer appears when it hovers over an element. This property allows developers to define how users interact visually with elements in a user interface.
With Tailwind's utility classes, it becomes even simpler to control the cursor. In this guide, we will learn every step of working with cursor styling in Tailwind CSS.
| Class | Properties | Example |
|---|---|---|
cursor-auto | cursor: auto; | <div className="cursor-auto"></div> |
cursor-default | cursor: default; | <div className="cursor-default"></div> |
cursor-pointer | cursor: pointer; | <div className="cursor-pointer"></div> |
cursor-wait | cursor: wait; | <div className="cursor-wait"></div> |
cursor-text | cursor: text; | <div className="cursor-text"></div> |
cursor-move | cursor: move; | <div className="cursor-move"></div> |
cursor-help | cursor: help; | <div className="cursor-help"></div> |
cursor-not-allowed | cursor: not-allowed; | <div className="cursor-not-allowed"></div> |
cursor-none | cursor: none; | <div className="cursor-none"></div> |
cursor-context-menu | cursor: context-menu; | <div className="cursor-context-menu"></div> |
cursor-progress | cursor: progress; | <div className="cursor-progress"></div> |
cursor-cell | cursor: cell; | <div className="cursor-cell"></div> |
cursor-crosshair | cursor: crosshair; | <div className="cursor-crosshair"></div> |
cursor-vertical-text | cursor: vertical-text; | <div className="cursor-vertical-text"></div> |
cursor-alias | cursor: alias; | <div className="cursor-alias"></div> |
cursor-copy | cursor: copy; | <div className="cursor-copy"></div> |
cursor-no-drop | cursor: no-drop; | <div className="cursor-no-drop"></div> |
cursor-grab | cursor: grab; | <div className="cursor-grab"></div> |
cursor-grabbing | cursor: grabbing; | <div className="cursor-grabbing"></div> |
cursor-all-scroll | cursor: all-scroll; | <div className="cursor-all-scroll"></div> |
cursor-col-resize | cursor: col-resize; | <div className="cursor-col-resize"></div> |
cursor-row-resize | cursor: row-resize; | <div className="cursor-row-resize"></div> |
cursor-n-resize | cursor: n-resize; | <div className="cursor-n-resize"></div> |
cursor-e-resize | cursor: e-resize; | <div className="cursor-e-resize"></div> |
cursor-s-resize | cursor: s-resize; | <div className="cursor-s-resize"></div> |
cursor-w-resize | cursor: w-resize; | <div className="cursor-w-resize"></div> |
cursor-ne-resize | cursor: ne-resize; | <div className="cursor-ne-resize"></div> |
cursor-nw-resize | cursor: nw-resize; | <div className="cursor-nw-resize"></div> |
cursor-se-resize | cursor: se-resize; | <div className="cursor-se-resize"></div> |
cursor-sw-resize | cursor: sw-resize; | <div className="cursor-sw-resize"></div> |
cursor-ew-resize | cursor: ew-resize; | <div className="cursor-ew-resize"></div> |
cursor-ns-resize | cursor: ns-resize; | <div className="cursor-ns-resize"></div> |
cursor-nesw-resize | cursor: nesw-resize; | <div className="cursor-nesw-resize"></div> |
cursor-nwse-resize | cursor: nwse-resize; | <div className="cursor-nwse-resize"></div> |
cursor-zoom-in | cursor: zoom-in; | <div className="cursor-zoom-in"></div> |
cursor-zoom-out | cursor: zoom-out; | <div className="cursor-zoom-out"></div> |
Overview of Cursor
Adding the Cursor
To start, you can set the mouse pointer style directly on any HTML element by using Tailwind's cursor utilities. These classes correspond to CSS cursor functionalities like pointer, not-allowed, wait, and more. Below is how you can use the cursor property:
export default function App() { return <h1>Hello world</h1> }
States and Responsiveness
Hover and Focus States
Tailwind allows you to change cursor styles dynamically based on user interactions. In Tailwind CSS, this is made easy by using state-based modifiers like hover: or focus:. For example, below is a pointer cursor that becomes wait on focus:
export default function App() { return <h1>Hello world</h1> }
Breakpoint Modifiers
You can also style cursors responsively based on screen size using Tailwind's breakpoint modifiers like sm, md, lg, etc. This enables you to adapt the user experience according to device dimensions fluidly.
export default function App() { return <h1>Hello world</h1> }
Custom Cursor
While Tailwind comes with several predefined options, customizing cursor styles to match specific design needs or branding is incredibly easy. You can implement custom cursors by extending Tailwind's configuration or through arbitrary values.
Extending the Theme
Tailwind's configuration file (usually tailwind.config.js) allows us to extend default cursor options. This proves useful when you want to add unique styles for various use cases. After extending the configuration, use these utilities like any other Tailwind class:
export default function App() { return <h1>Hello world</h1> }
Using Arbitrary Values
In scenarios where predefined values are insufficient and theme configuration is too much effort, arbitrary values come into play. Tailwind lets you define cursor values on-the-fly by wrapping the desired CSS property in square brackets.
export default function App() { return <h1>Hello world</h1> }
Real World Examples
Interactive Product Cards Grid
This example shows a grid of product cards with different cursor styles based on product availability:
export default function App() { return <h1>Hello world</h1> }
Custom File Upload Interface
This example demonstrates a file upload interface with different cursor states for drag and drop functionality.
export default function App() { return <h1>Hello world</h1> }
Interactive Table with Sorting
This example shows a table with sortable columns and various cursor interactions:
export default function App() { return <h1>Hello world</h1> }
Interactive Image Gallery
This example shows an image gallery with different cursor states for interactions:
export default function App() { return <h1>Hello world</h1> }
Interactive Rating Component
This example demonstrates a rating component with different cursor interactions:
export default function App() { return <h1>Hello world</h1> }
Customization Examples
Custom Text Selection Cursor
Implement a text editor interface with a custom cursor for different text selection states.
export default function App() { return <h1>Hello world</h1> }
Custom Image Cursor for Interactive Gallery
A photo gallery component that changes cursor to a magnifying glass on hover, perfect for image exploration interfaces.
export default function App() { return <h1>Hello world</h1> }
Gradient Progress Cursor
A reading progress component that changes cursor based on scroll position, ideal for blog posts and articles.
export default function App() { return <h1>Hello world</h1> }
Best Practices
Maintain Design Consistency
When building an interface with Tailwind CSS, ensuring consistent cursor styling is critical for a consistent user experience. Cursors should complement the interactive elements they represent, maintaining uniformity across buttons, links, and card elements. For instance, using cursor-pointer on all clickable items creates a predictable and seamless interaction model for users without confusion or unintended behaviors.
Ensure that all interactive elements, like buttons, links, and form inputs, have a cursor style that matches their expected behavior. For example, buttons use cursor-pointer, disabled buttons use cursor-not-allowed, and non-interactive containers default to cursor-auto. This simple yet effective approach enforces consistency and clarity for both designers and end-users.
Leverage Utility Combinations
Tailwind utilities thrive on being combined to achieve highly customized interfaces while keeping your codebase maintainable. For cursor-specific classes, pairing them with layout or spacing utilities is an effective way to meet both functional and aesthetic needs. For instance, you might group cursor-pointer with hover transitions (transition-colors and hover:bg-gray-100) to create interactive buttons.
Using consistent utility combinations also helps highlight semantic meaning. If you plan to draw attention to interactive elements that perform a destructive action, consider pairing cursor-pointer with a red color scheme and distinct hover states. This coordinated usage can guide users’ eyes toward interactive regions more naturally and emphasize key functionalities.
Accessibility Considerations
Enhance Readability and Navigability
Cursor styles may seem like a subtle aspect of your interface, but they can significantly impact how users read and navigate content. By providing clear visual cues, users immediately know where to click or tap, reducing guesswork and friction. This clarity helps everyone, including individuals who may struggle with complex layouts or smaller screens.
Readability is often influenced by spacing and contrast, but cursor indicators add another layer of feedback. For instance, ensuring that every interactive headline uses cursor-pointer alongside a distinct text color can help users visually parse content sections. This small but meaningful addition can improve how easily people navigate through dense or multi-layered interfaces.
Support Accessible Interactive Elements
Interactive components—from buttons to dropdown menus—rely on visual cues to guide user actions. Applying cursor utilities in a thoughtful way can make these elements more accessible. For example, a toggle switch that uses cursor-pointer for the actionable part and cursor-default for the label helps users understand exactly which region controls the action.
It’s also beneficial to consistently style focus states when dealing with interactive elements. While the cursor indicates hover or pointer presence, keyboard users rely on outlines. By providing both clear cursor and well-defined outlines, you meet a wide range of accessibility needs.