cursor
Definition
The cursor CSS property sets the type of mouse cursor to be displayed when the mouse pointer is over an element.
Examples
Display a "pointer" cursor on all links:
a {
cursor: pointer;
}
Display a "crosshair" cursor when hovering over a <div> element:
div {
cursor: crosshair;
}
Display an "alias" cursor when hovering over an <img>
element:
img {
cursor: alias;
}
Values
Value | Description |
---|---|
auto | The default. The browser sets a cursor. |
crosshair | A simple crosshair. |
default | The platform-dependent default cursor. Often rendered as an arrow. |
pointer | A clickable hand cursor. |
move | Indicates something is to be moved. |
not-allowed | Indicates the requested action will not be executed. |
help | Help cursor, usually a question mark or balloon. |
e-resize | Indicates a bidirectional resize cursor from left and right. |
n-resize | Indicates a bidirectional resize cursor from top and bottom. |
ne-resize | Indicates a bidirectional resize cursor from top-right and bottom-left. |
nw-resize | Indicates a bidirectional resize cursor from top-left and bottom-right. |
s-resize | Indicates a bidirectional resize cursor from bottom to top. |
se-resize | Indicates a bidirectional resize cursor from bottom-right to top-left. |
sw-resize | Indicates a bidirectional resize cursor from bottom-left to top-right. |
w-resize | Indicates a bidirectional resize cursor from right to left. |
text | Indicates a text edit cursor. |
wait | Indicates that the program is busy and the user should wait. |
progress | A progress indicator. The program is busy, but the user may still interact with the interface. |
inherit | Inherits the value of the parent element. |
Best Practices
- Use the "pointer" cursor for clickable elements, such as links and buttons, to indicate that they are clickable.
- Use the "not-allowed" cursor for disabled elements to indicate that they are not clickable.
- Use the appropriate cursor for the specific action or element, such as "move" for movable elements or "text" for text editing elements.
- Avoid using custom cursors as they may not be recognized by all browsers.
- Consider the accessibility implications of using custom cursors, as they may be difficult for some users to see or understand.
- Be mindful of the performance impact of using custom cursors, as some browsers may need to download the cursor resource, leading to slow loading times.
Browser Compatibility
Chrome | Firefox | Safari | Internet Explorer | Microsoft Edge | Opera |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |