Definition and Usage
The cursor property specifies the type of cursor displayed when the mouse pointer is over an element.
Specifying the cursor's appearance with this property allows users to more intuitively understand what actions they can perform on an element when hovering over it.
Let's look at the types of standard CSS cursors available for this property, how to specify a custom cursor image, and what to keep in mind when doing so.
Basic Example
The following example shows how to use the cursor property to specify the cursor type as not-allowed on a disabled button element, indicating that the action is not permitted when users hover over the element:
<button disabled>You can't click this!</button>
Code Explanation
The disabled attribute disables the element.
button:disabled {
cursor: not-allowed;
}
Code Explanation
:disabled is a pseudo-class selector that selects elements that are actually disabled by the HTML disabled attribute.
Types of Standard CSS Cursors
The following example demonstrates the types of predefined cursors defined in the specification:
You can see how each cursor looks when applied by hovering the mouse pointer directly over the words in the Rendered Output.
<style>
ul {
margin: 0;
padding: 0;
list-style-type: none;
}
li {
width: 200px;
padding: 0.5em 0.7em;
border: 1px solid;
border-radius: 5px;
margin-bottom: 0.7em;
transition: all 0.2s;
}
li:hover {
color: red;
box-shadow: 0 1px 1px red;
}
</style>
<h3>Types of Standard CSS Cursors</h3>
<p>Hover over a word to change the mouse cursor.</p>
<ul>
<li style="cursor: auto;">auto</li>
<li style="cursor: default;">default</li>
<li style="cursor: none;">none</li>
<li style="cursor: context-menu;">context-menu</li>
<li style="cursor: help;">help</li>
<li style="cursor: pointer;">pointer</li>
<li style="cursor: progress;">progress</li>
<li style="cursor: wait;">wait</li>
<li style="cursor: cell;">cell</li>
<li style="cursor: crosshair;">crosshair</li>
<li style="cursor: text;">text</li>
<li style="cursor: url(heart.png),auto;">url: Custom Cursor Image</li>
<li style="cursor: vertical-text;">vertical-text</li>
<li style="cursor: alias;">alias</li>
<li style="cursor: copy;">copy</li>
<li style="cursor: move;">move</li>
<li style="cursor: no-drop;">no-drop</li>
<li style="cursor: not-allowed;">not-allowed</li>
<li style="cursor: grab;">grab</li>
<li style="cursor: grabbing;">grabbing</li>
<li style="cursor: e-resize;">e-resize</li>
<li style="cursor: n-resize;">n-resize</li>
<li style="cursor: ne-resize;">ne-resize</li>
<li style="cursor: nw-resize;">nw-resize</li>
<li style="cursor: s-resize;">s-resize</li>
<li style="cursor: se-resize;">se-resize</li>
<li style="cursor: sw-resize;">sw-resize</li>
<li style="cursor: w-resize;">w-resize</li>
<li style="cursor: ew-resize;">ew-resize</li>
<li style="cursor: ns-resize;">ns-resize</li>
<li style="cursor: nesw-resize;">nesw-resize</li>
<li style="cursor: nwse-resize;">nwse-resize</li>
<li style="cursor: col-resize;">col-resize</li>
<li style="cursor: row-resize;">row-resize</li>
<li style="cursor: all-scroll;">all-scroll</li>
<li style="cursor: zoom-in;">zoom-in</li>
<li style="cursor: zoom-out;">zoom-out</li>
</ul>
The appearance of cursors specified using the CSS cursor property may vary slightly depending on the browser and operating system (OS).
Types of Standard CSS Cursors
Hover over a word to change the mouse cursor.
- auto
- default
- none
- context-menu
- help
- pointer
- progress
- wait
- cell
- crosshair
- text
- url: Custom Cursor Image
- vertical-text
- alias
- copy
- move
- no-drop
- not-allowed
- grab
- grabbing
- e-resize
- n-resize
- ne-resize
- nw-resize
- s-resize
- se-resize
- sw-resize
- w-resize
- ew-resize
- ns-resize
- nesw-resize
- nwse-resize
- col-resize
- row-resize
- all-scroll
- zoom-in
- zoom-out
How to Specify the Cursor Appearance
Let's look at how to specify the cursor appearance using the cursor property.
Formal Syntax
/* Formal syntax for specifying
a cursor using a keyword value */
selector {
cursor: keyword-value;
}
/* Formal syntax for specifying
a custom cursor using an image */
selector {
cursor: <url>, fallback-keyword-value;
}
/* Formal syntax for specifying a custom cursor
with hotspot coordinates relative to the
top-left corner of the image */
selector {
cursor: <url> <x> <y>, fallback-keyword-value;
}
Syntax
/* Keyword values */
cursor: auto;
cursor: pointer;
/* ... */
cursor: zoom-out;
/* <url>,
fallback keyword (the keyword value to use
if the image fails to load) */
cursor: url(hand.png), grab;
cursor: url(heart.png), auto;
/* <url>
coordinates relative to the top-left corner
(<x> <y>, integers or decimals less than 32),
fallback keyword (the keyword value to use
if the image fails to load) */
cursor: url(hand.png) 4 12, grab;
cursor: url(heart.png) 2 2, auto;
/* Global values */
cursor: inherit;
cursor: initial;
cursor: revert;
cursor: revert-layer;
cursor: unset;
Formal Definition
| Initial value | auto |
|---|---|
| Applies to | all elements |
| Inherited | yes |
| Animatable | no |
Values
The values of the cursor property fall into two categories: values for "Specifying a Standard CSS Cursor Using a Keyword" and values for "Specifying a Custom Cursor Using an Image".
Specifying a Standard CSS Cursor Using a Keyword
| Keyword Value | Example(Hover over the mouse pointer to see the rendered result.) | Description |
|---|---|---|
auto |
Hover over me!
|
Initial value. The browser determines which cursor to display based on the current context. Specifically, auto behaves like text over selectable text or editable elements, and like default otherwise. |
default |
Hover over me!
|
The default pointer, usually displayed as an arrow. |
none |
Hover over me!
|
No cursor is displayed. |
context-menu |
Hover over me!
|
Indicates that a context menu is available. Browsers or operating systems (OS) that do not support this value may display the default cursor instead. |
help |
Hover over me!
|
Often displayed as a question mark or a speech bubble. |
pointer |
Hover over me!
|
Often displayed as the back of a hand with its index finger extended. |
progress |
Hover over me!
|
Often displayed as a cursor indicating that an operation is in progress, such as a spinning beach ball, a watch, an hourglass, or an arrow with a loading indicator. Unlike wait, it indicates that the program is performing some processing while still allowing the user to interact with it. |
wait |
Hover over me!
|
Often displayed as a cursor indicating a waiting state, such as a spinning beach ball, a watch, or a loading indicator. Unlike progress, it indicates that the user cannot interact with the program. |
cell |
Hover over me!
|
Indicates that a cell or a set of cells can be selected. It is often displayed as a thick plus sign with a dot in the center. |
crosshair |
Hover over me!
|
Displayed as a thin cross resembling a simple + sign. It is often used to indicate a mode for selecting a two-dimensional bitmap. |
text |
Hover over me!
|
Often displayed as an I-beam. It is primarily used for selecting horizontally written text. |
vertical-text |
Hover over me!
|
Often displayed as a horizontal I-beam (I). It is primarily used for selecting vertically written text. |
alias |
Hover over me!
|
Indicates that an alias or shortcut is to be created. It is often displayed as an arrow with a small curved arrow beside it. |
copy |
Hover over me!
|
Indicates that content can be copied. It is often displayed as an arrow with a small plus sign beside it. |
move |
Hover over me!
|
Indicates that something can be moved. It is usually displayed as a four-headed arrow. |
no-drop |
Hover over me!
|
Indicates that a dragged item cannot be dropped at the current cursor position. It is often displayed as a hand or pointer with a small circle containing a diagonal line. It is often displayed in the same way as not-allowed. |
not-allowed |
Hover over me!
|
Indicates that an action is not permitted. It is often displayed as a circle with a diagonal line. |
grab |
Hover over me!
|
Indicates that something can be grabbed (and dragged to move it). It is often displayed as the back of an open hand. |
grabbing |
Hover over me!
|
Indicates that something is being grabbed (and dragged to move it). It is often displayed as the back of a hand with its fingers closed. |
e-resize |
Hover over me!
|
Indicates that an edge can be moved to the right (east). |
n-resize |
Hover over me!
|
Indicates that an edge can be moved upward (north). |
ne-resize |
Hover over me!
|
Indicates that an edge can be moved diagonally toward the upper right (north/east). |
nw-resize |
Hover over me!
|
Indicates that an edge can be moved diagonally toward the upper left (north/west). |
s-resize |
Hover over me!
|
Indicates that an edge can be moved downward (south). |
se-resize |
Hover over me!
|
Indicates that an edge can be moved diagonally toward the lower right (south/east). |
sw-resize |
Hover over me!
|
Indicates that an edge can be moved diagonally toward the lower left (south/west). |
w-resize |
Hover over me!
|
Indicates that an edge can be moved to the left (west). |
ew-resize |
Hover over me!
|
Indicates that an edge can be moved in either the left or right direction (west/east). |
ns-resize |
Hover over me!
|
Indicates that an edge can be moved in either the upward or downward direction (north/south). |
nesw-resize |
Hover over me!
|
Indicates that an edge can be moved in either of two diagonal directions: upper right (north/east) or lower left (south/west). |
nwse-resize |
Hover over me!
|
Indicates that an edge can be moved in either of two diagonal directions: upper left (north/west) or lower right (south/east). |
col-resize |
Hover over me!
|
Indicates that an item or column can be resized horizontally. It is often displayed as symmetrical arrows pointing left and right, separated by a vertical bar. |
row-resize |
Hover over me!
|
Indicates that an item or row can be resized vertically. It is often displayed as symmetrical arrows pointing up and down, separated by a horizontal bar. |
all-scroll |
Hover over me!
|
Indicates that something can be scrolled (panned) in any direction. It is often displayed as arrows pointing up, down, left, and right, with a dot in the center. |
zoom-in |
Hover over me!
|
Indicates that something can be enlarged. It is often displayed as a magnifying glass with a + sign in the center of the lens. |
zoom-out |
Hover over me!
|
Indicates that something can be reduced in size. It is often displayed as a magnifying glass with a - sign in the center of the lens. |
Specifying a Custom Cursor Using an Image
/* <url>,
fallback keyword (the keyword value to use
if the image fails to load) */
cursor: url(hand.png), grab;
cursor: url(heart.png), auto;
/* <url>
coordinates relative to the top-left corner
(<x> <y>, integers or decimals less than 32),
fallback keyword (the keyword value to use
if the image fails to load) */
cursor: url(hand.png) 4 12, grab;
cursor: url(heart.png) 2 2, auto;
/* URLs and fallback URLs (some with coordinates),
followed by a fallback keyword */
cursor:
url(cursor_1.svg) 4 5,
url(cursor_2.svg),
/* ..., */ url(cursor_n.cur) 5 5,
progress;
<url> |
A url(...) pointing to an image file, or a comma-separated list of url(...) values: url(...), url(...), ...,
If some cursor image types are not supported, two or more url(...) values can be provided as fallbacks. A non-URL fallback (one or more keyword values) must appear at the end of the fallback list. |
|---|---|
<x>, <y> |
Optional.
Coordinates relative to the top-left corner. The numbers are in pixels. They are measured from the top-left corner of the image and correspond to " <x> <y>". The coordinates must be within the boundaries of the cursor image. If these values are not specified, they can be read from the file itself; otherwise, they default to the top-left corner of the image. |
Keyword Value |
Required.
The keyword value specified using a keyword, to be used if the image fails to load. It must appear at the end of the list. |
Things to Keep in Mind
When using the cursor property, you must keep two things in mind.
Does Not Work When pointer-events: none Is Specified
The pointer-events property specifies whether an element can be the target of pointer events.
When pointer-events: none is specified on an element, that element cannot be the target of pointer events. Even if the cursor property is specified on that element, the cursor property does not work.
In other words, the mouse cursor ignores that element, and its appearance is determined by the cursor property of an "element below it in the visual layer".
An "element below it in the visual layer" does not mean a parent element in the DOM structure. It refers to an element that is visually overlapped beneath that element.
Let's look at the following example:
<div class="parent" style="cursor: not-allowed;">
<div class="child" style="pointer-events: none; cursor: pointer;">
This area is not clickable
</div>
</div>
not-allowed cursor appears.
childelement: Becausepointer-events: noneis applied, the cursor does not change topointerwhen you hover over this element. This element does not receive mouse events, so it does not respond when you move the cursor over it.parentelement: Theparentelement, which is below thechildelement in the visual layer, receives the mouse events instead. Itscursor: not-alloweddeclaration takes effect, and thenot-allowedcursor appears.
Image Restrictions for Custom Cursors
Images used for custom cursors have restrictions on their size and file format.
Image File Format Restrictions
The specification does not mention any restrictions on the size of images used for custom cursors. However, most browsers impose their own limits on image sizes.
MDN - cursor#Icon size limits recommends limiting cursor image sizes to 32 × 32 pixels. If an image larger than the maximum size supported by the browser is used as a cursor, it is generally ignored.
Limit cursor image sizes to 32 × 32 pixels.
Image Size Restrictions
The specification states that the image file formats used for custom cursors are limited and that the following file formats must be supported:
- PNG files (required)
- SVG 1.1 files (SVG files in secure static mode with an intrinsic size, required)
.curfile format (widely supported in desktop browsers)- Other non-animated image file formats (non-animated image formats supported by the browser for other properties)
However, the supported formats may vary from browser to browser. Visit caniuse.com for more detailed information.
Browser Compatibility
| Property |
Desktop Chrome
|
Desktop Edge
|
Desktop Firefox
|
Safari
|
|---|---|---|---|---|
cursor
|
1 | 12 | 1 | 1.2 |
Specifications
| Specification | |
|---|---|
cursor
|
CSS Basic User Interface Module Level 4 #cursor |