CSS
CSS: How to Add a Mouse Pointer to Elements
Changing the mouse pointer (or cursor) in CSS is a subtle but powerful way to improve user experience. Whether you’re making a button, a link, or a clickable area, customizing the cursor tells users that an element is interactive.
In this blog post, you’ll learn:
- ✅ How to change the mouse pointer with CSS
- ✅ Most commonly used
cursor
values - ✅ Practical examples for buttons, links, and more
- 🎨 Bonus: Use custom images for cursors
✅ 1. Use the cursor
Property in CSS
The cursor
property lets you define what type of mouse pointer should appear when hovering over an element.
✅ Basic Example:
<button class="clickable">Click Me</button>
.clickable {
cursor: pointer;
}
✅ This changes the cursor to a hand pointer when hovered—common for buttons and links.
✅ 2. Common cursor
Values
Here are some frequently used cursor styles:
Cursor Value | Description |
---|---|
default | Normal arrow (default) |
pointer | Hand cursor for clickable items |
text | I-beam cursor for text fields |
move | Cross with arrows for drag handles |
not-allowed | Indicates an unavailable action |
wait | Spinner or hourglass (waiting) |
crosshair | Target-like crosshair |
✅ Example:
.text-area {
cursor: text;
}
.disabled {
cursor: not-allowed;
}
✅ 3. Change Cursor on Hover Only
You can target the hover state for extra clarity:
.card:hover {
cursor: pointer;
}
✅ Helpful when you want to keep the default cursor unless hovering.
✅ 4. Use a Custom Cursor Image (Advanced)
You can use your own image as a cursor!
.custom-cursor {
cursor: url('cursor-icon.png'), auto;
}
- Make sure the image is small (ideally 32×32 pixels or less).
- Always provide a fallback (
auto
,pointer
, etc.) for unsupported browsers.
🧠 Best Practices
Tip | Why It Helps |
---|---|
Use cursor: pointer for links/buttons | Signals clickability to users |
Avoid overusing custom cursors | They can confuse or annoy users |
Use not-allowed for disabled UI | Improves accessibility and feedback |
Keep cursor changes consistent | Enhances usability and UX |
🧪 Real Example: Making a Button Interactive
<button class="btn">Submit</button>
.btn {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer; /* 👈 makes it feel clickable */
}
✅ This improves both the functionality and feel of the button.
🏁 Final Thoughts
Adding or changing the mouse pointer with CSS is a small detail that makes a big difference. Whether you’re guiding users to click a button or preventing them from interacting with disabled elements, the cursor
property helps create clear, intuitive interfaces.