Course
Cursor
CSS Tutorial
This CSS tutorial is designed for beginners to navigate through the essentials and intricate aspects of CSS styling. Upon finishing this tutorial, participants will possess a comprehensive understanding of CSS, setting a solid foundation for further exploration and mastery. This guide aims to equip you with the skills necessary to transform your visions into visually appealing web designs, laying the groundwork for your journey towards becoming an accomplished web designer.
cursor
The CSS cursor property determines the appearance of the mouse cursor when hovering over an element to which this property is applied. This property is only applicable in environments with mouse and cursor functionality. Its main purpose is to improve usability by visually representing certain functions.
Possible Values
The cursor property can have following values:
- <url>: (optional) You have the flexibility to use a series of url() values separated by commas, with each url() pointing to an image file.
- <x> <y>: (optional) You have the option to specify x and y coordinates that define the hotspot of the cursor and specify the exact position within the cursor image that the cursor points to.
- <keyword>:A keyword value is required that specifies either the cursor type to use or the alternate cursor to use if none of the specified symbols can be loaded.
The following table lists the available keywords.
Applies to
All the HTML elements.
DOM Syntax
object.style.cursor = "cell";
Some points to note:
- The cursor property is characterized by a combination of values, which can range from zero to many <url>, separated by commas followed by a mandatory keyword (all keywords listed in table in the following section) value.
- Each <url> should point to an image file.
- The browser will try to load the first image specified, falling back to the next if it can't, and falling back to the keyword value if no images could be loaded (or if none were specified).
CSS Cursor - Keyword Value
Here is the example which shows various types of cursors in css
<html><head><title>All CSS Cursors</title><style> .demo-cursor { display: inline-block; background-color: LightYellow; width: 100px; height: 100px; margin: 10px; border: 3px solid #ccc; cursor: pointer; } .default { cursor: default; } .auto { cursor: auto; } .crosshair { cursor: crosshair; } .pointer { cursor: pointer; } .move { cursor: move; } .text { cursor: text; } .wait { cursor: wait; } .help { cursor: help; } .not-allowed { cursor: not-allowed; } .progress { cursor: progress; } .alias { cursor: alias; } .copy { cursor: copy; } .no-drop { cursor: no-drop; } .e-resize { cursor: e-resize; } .n-resize { cursor: n-resize; } .ne-resize { cursor: ne-resize; } .nw-resize { cursor: nw-resize; } .s-resize { cursor: s-resize; } .se-resize { cursor: se-resize; } .sw-resize { cursor: sw-resize; } .w-resize { cursor: w-resize; } .ew-resize { cursor: ew-resize; } .ns-resize { cursor: ns-resize; } .nesw-resize { cursor: nesw-resize; } .nwse-resize { cursor: nwse-resize; } .col-resize { cursor: col-resize; } .row-resize { cursor: row-resize; } .zoom-in { cursor: zoom-in; } .zoom-out { cursor: zoom-out; } .grab { cursor: grab; } .grabbing { cursor: grabbing; }</style></head><body><h1>All CSS Cursors, hover the mouse on the blocks.</h1> <div class="demo-cursor auto"><h3 style="text-align:center;">Auto</h3></div> <div class="demo-cursor default"><h3 style="text-align:center;">Default</h3></div> <div class="demo-cursor crosshair"><h3 style="text-align:center;">Crosshair</h3></div> <div class="demo-cursor pointer"><h3 style="text-align:center;">Pointer</h3></div> <div class="demo-cursor move"><h3 style="text-align:center;">Move</h3></div> <div class="demo-cursor text"><h3 style="text-align:center;">Text</h3></div> <div class="demo-cursor wait"><h3 style="text-align:center;">Wait</h3></div> <div class="demo-cursor help"><h3 style="text-align:center;">Help</h3></div> <div class="demo-cursor not-allowed"><h3 style="text-align:center;">Not-allowed</h3></div> <div class="demo-cursor progress"><h3 style="text-align:center;">Progress</h3></div> <div class="demo-cursor alias"><h3 style="text-align:center;">Alias</h3></div> <div class="demo-cursor copy"><h3 style="text-align:center;">Copy</h3></div> <div class="demo-cursor no-drop"><h3 style="text-align:center;">No-drop</h3></div> <div class="demo-cursor e-resize"><h3 style="text-align:center;">e-resize</h3></div> <div class="demo-cursor n-resize"><h3 style="text-align:center;">n-resize</h3></div> <div class="demo-cursor ne-resize"><h3 style="text-align:center;">ne-resize</h3></div> <div class="demo-cursor nw-resize"><h3 style="text-align:center;">nw-resize</h3></div> <div class="demo-cursor s-resize"><h3 style="text-align:center;">s-resize</h3></div> <div class="demo-cursor se-resize"><h3 style="text-align:center;">se-resize</h3></div> <div class="demo-cursor sw-resize"><h3 style="text-align:center;">sw-resize</h3></div> <div class="demo-cursor w-resize"><h3 style="text-align:center;">w-resize</h3></div> <div class="demo-cursor ew-resize"><h3 style="text-align:center;">ew-resize</h3></div> <div class="demo-cursor ns-resize"><h3 style="text-align:center;">ns-resize</h3></div> <div class="demo-cursor nesw-resize"><h3 style="text-align:center;">nesw-resize</h3></div> <div class="demo-cursor nwse-resize"><h3 style="text-align:center;">nwse-resize</h3></div> <div class="demo-cursor col-resize"><h3 style="text-align:center;">col-resize</h3></div> <div class="demo-cursor row-resize"><h3 style="text-align:center;">row-resize</h3></div> <div class="demo-cursor zoom-in"><h3 style="text-align:center;">Zoom-in</h3></div> <div class="demo-cursor zoom-out"><h3 style="text-align:center;">Zoom-out</h3></div> <div class="demo-cursor grab"><h3 style="text-align:center;">Grab</h3></div> <div class="demo-cursor grabbing"><h3 style="text-align:center;">Grabbing</h3></div></body></html>
CSS Cursor - <url> Value
Here is the example which shows using image as cursor value
<html><head><title>All CSS Cursors</title><style> .demo-cursor { display: inline-block; background-color: LightYellow; width: 100px; height: 100px; margin: 10px; border: 3px solid #ccc; cursor: url(images/try-it.jpg), pointer; } </style></head><body><h1>Image CSS Cursors, hover the mouse on the block.</h1> <div class="demo-cursor"><h3 style="text-align:center;">Image Cursor</h3></div> </div></body></html>
CSS Cursor - <url> Multiple Values
Here is the example which shows using multiple images (comma separated) as cursor values
<html><head><title>All CSS Cursors</title><style> .demo-cursor { display: inline-block; background-color: LightYellow; width: 100px; height: 100px; margin: 10px; border: 3px solid #ccc; cursor: url(images/try-it.jpg),url(images/cursor-text1.png), crosshair; } </style></head><body><h1>Image CSS Cursors, hover the mouse on the block.</h1> <div class="demo-cursor"><h3 style="text-align:center;">Image Cursor</h3></div> </div></body></html>
Try renaming first image file name to try-it-1.jpg (so that image is not found) and thene execute the program. We see the fallback effect, i.e when first image is not found the source, control fallsback on second image and that is used as cursor.