[css] How to change the cursor into a hand when a user hovers over a list item?

I've got a list, and I have a click handler for its items:

<ul>
  <li>foo</li>
  <li>goo</li>
</ul>

How can I change the mouse pointer into a hand pointer (like when hovering over a button)? Right now the pointer turns into a text selection pointer when I hover over the list items.

This question is related to css

The answer is


Use:

ul li:hover{
   cursor: pointer;
}

For more mouse events, check CSS cursor property.


For being able to make anything get the "mousechange" treatment, you can add a CSS class:

_x000D_
_x000D_
.mousechange:hover {_x000D_
  cursor: pointer;_x000D_
}
_x000D_
<span class="mousechange">Some text here</span>
_x000D_
_x000D_
_x000D_

I would not say to use cursor:hand since it was only valid for Internet Explorer 5.5 and below, and Internet Explorer 6 came with Windows XP (2002). People will only get the hint to upgrade when their browser stops working for them. Additionally, in Visual Studio, it will red underline that entry. It tells me:

Validation (CSS 3.0): "hand" is not a valid value for the "cursor" property


Use

cursor: pointer;
cursor: hand;

if you want to have a crossbrowser result!


ul li:hover{
   cursor: pointer;
}

li:hover {cursor: hand; cursor: pointer;}

For a basic hand symbol:

Try

cursor: pointer 

If you want a hand symbol like drag some item and drop it, try:

cursor: grab

For complete cross browser, use:

cursor: pointer;
cursor: hand;

CSS:

.auto            { cursor: auto; }
.default         { cursor: default; }
.none            { cursor: none; }
.context-menu    { cursor: context-menu; }
.help            { cursor: help; }
.pointer         { cursor: pointer; }
.progress        { cursor: progress; }
.wait            { cursor: wait; }
.cell            { cursor: cell; }
.crosshair       { cursor: crosshair; }
.text            { cursor: text; }
.vertical-text   { cursor: vertical-text; }
.alias           { cursor: alias; }
.copy            { cursor: copy; }
.move            { cursor: move; }
.no-drop         { cursor: no-drop; }
.not-allowed     { cursor: not-allowed; }
.all-scroll      { cursor: all-scroll; }
.col-resize      { cursor: col-resize; }
.row-resize      { cursor: row-resize; }
.n-resize        { cursor: n-resize; }
.e-resize        { cursor: e-resize; }
.s-resize        { cursor: s-resize; }
.w-resize        { cursor: w-resize; }
.ns-resize       { cursor: ns-resize; }
.ew-resize       { cursor: ew-resize; }
.ne-resize       { cursor: ne-resize; }
.nw-resize       { cursor: nw-resize; }
.se-resize       { cursor: se-resize; }
.sw-resize       { cursor: sw-resize; }
.nesw-resize     { cursor: nesw-resize; }
.nwse-resize     { cursor: nwse-resize; }

You can also have the cursor be an image:

.img-cur {
   cursor: url(images/cursor.png), auto;
}

I think it would be smart to only show the hand/pointer cursor when JavaScript is available. So people will not have the feeling they can click on something that is not clickable.

To achieve that you could use the JavaScript libary jQuery to add the CSS to the element like so

$("li").css({"cursor":"pointer"});

Or chain it directly to the click handler.

Or when modernizer in combination with <html class="no-js"> is used, the CSS would look like this:

.js li { cursor: pointer; }

You can also use the following style:

li {
    cursor: grabbing;
}

Use for li:

li:hover {
    cursor: pointer;
}

See more cursor properties with examples after running snippet option:

An animation showing a cursor hovering over a div of each class

_x000D_
_x000D_
.auto          { cursor: auto; }_x000D_
.default       { cursor: default; }_x000D_
.none          { cursor: none; }_x000D_
.context-menu  { cursor: context-menu; }_x000D_
.help          { cursor: help; }_x000D_
.pointer       { cursor: pointer; }_x000D_
.progress      { cursor: progress; }_x000D_
.wait          { cursor: wait; }_x000D_
.cell          { cursor: cell; }_x000D_
.crosshair     { cursor: crosshair; }_x000D_
.text          { cursor: text; }_x000D_
.vertical-text { cursor: vertical-text; }_x000D_
.alias         { cursor: alias; }_x000D_
.copy          { cursor: copy; }_x000D_
.move          { cursor: move; }_x000D_
.no-drop       { cursor: no-drop; }_x000D_
.not-allowed   { cursor: not-allowed; }_x000D_
.all-scroll    { cursor: all-scroll; }_x000D_
.col-resize    { cursor: col-resize; }_x000D_
.row-resize    { cursor: row-resize; }_x000D_
.n-resize      { cursor: n-resize; }_x000D_
.e-resize      { cursor: e-resize; }_x000D_
.s-resize      { cursor: s-resize; }_x000D_
.w-resize      { cursor: w-resize; }_x000D_
.ns-resize     { cursor: ns-resize; }_x000D_
.ew-resize     { cursor: ew-resize; }_x000D_
.ne-resize     { cursor: ne-resize; }_x000D_
.nw-resize     { cursor: nw-resize; }_x000D_
.se-resize     { cursor: se-resize; }_x000D_
.sw-resize     { cursor: sw-resize; }_x000D_
.nesw-resize   { cursor: nesw-resize; }_x000D_
.nwse-resize   { cursor: nwse-resize; }_x000D_
_x000D_
.cursors > div {_x000D_
    float: left;_x000D_
    box-sizing: border-box;_x000D_
    background: #f2f2f2;_x000D_
    border:1px solid #ccc;_x000D_
    width: 20%;_x000D_
    padding: 10px 2px;_x000D_
    text-align: center;_x000D_
    white-space: nowrap;_x000D_
    &:nth-child(even) {_x000D_
       background: #eee;_x000D_
    }_x000D_
    &:hover {_x000D_
       opacity: 0.25_x000D_
    }_x000D_
}
_x000D_
<h1>Example of cursor</h1>_x000D_
_x000D_
<div class="cursors">_x000D_
    <div class="auto">auto</div>_x000D_
    <div class="default">default</div>_x000D_
    <div class="none">none</div>_x000D_
    <div class="context-menu">context-menu</div>_x000D_
    <div class="help">help</div>_x000D_
    <div class="pointer">pointer</div>_x000D_
    <div class="progress">progress</div>_x000D_
    <div class="wait">wait</div>_x000D_
    <div class="cell">cell</div>_x000D_
    <div class="crosshair">crosshair</div>_x000D_
    <div class="text">text</div>_x000D_
    <div class="vertical-text">vertical-text</div>_x000D_
    <div class="alias">alias</div>_x000D_
    <div class="copy">copy</div>_x000D_
    <div class="move">move</div>_x000D_
    <div class="no-drop">no-drop</div>_x000D_
    <div class="not-allowed">not-allowed</div>_x000D_
    <div class="all-scroll">all-scroll</div>_x000D_
    <div class="col-resize">col-resize</div>_x000D_
    <div class="row-resize">row-resize</div>_x000D_
    <div class="n-resize">n-resize</div>_x000D_
    <div class="s-resize">s-resize</div>_x000D_
    <div class="e-resize">e-resize</div>_x000D_
    <div class="w-resize">w-resize</div>_x000D_
    <div class="ns-resize">ns-resize</div>_x000D_
    <div class="ew-resize">ew-resize</div>_x000D_
    <div class="ne-resize">ne-resize</div>_x000D_
    <div class="nw-resize">nw-resize</div>_x000D_
    <div class="se-resize">se-resize</div>_x000D_
    <div class="sw-resize">sw-resize</div>_x000D_
    <div class="nesw-resize">nesw-resize</div>_x000D_
    <div class="nwse-resize">nwse-resize</div>_x000D_
</div>
_x000D_
_x000D_
_x000D_


just using CSS to set customize the cursor pointer


/* Keyword value */
cursor: pointer;
cursor: auto;

/* URL, with a keyword fallback */
cursor: url(hand.cur), pointer;

/* URL and coordinates, with a keyword fallback */
cursor: url(cursor1.png) 4 12, auto;
cursor: url(cursor2.png) 2 2, pointer;

/* Global values */
cursor: inherit;
cursor: initial;
cursor: unset;

/* 2 URLs and coordinates, with a keyword fallback */

cursor: url(one.svg) 2 2, url(two.svg) 5 5, progress;

demo

Note: cursor support for many format icons!

such as .cur, .png, .svg, .jpeg, .webp, and so on

_x000D_
_x000D_
li:hover{
  cursor: url("https://cdn.xgqfrms.xyz/cursor/mouse.cur"), pointer;
  color: #0f0;
  background: #000;
}


/*

li:hover{
  cursor: url("../icons/hand.cur"), pointer;
}

*/

li{
  height: 30px;
  width: 100px;
  background: #ccc;
  color: #fff;
  margin: 10px;
  text-align: center;
  list-style: none;
}
_x000D_
<ul>
  <li>a</li>
  <li>b</li>
  <li>c</li>
</ul>
_x000D_
_x000D_
_x000D_

refs

https://developer.mozilla.org/en-US/docs/Web/CSS/cursor


Just for completeness:

cursor: -webkit-grab;

It also gives a hand, the one you know when moving the view of an image around.

It is quite useful if you want to emulate grab behavior using jQuery and mousedown.

Enter image description here


You can use one of the following:

li:hover
{
 cursor: pointer;
}

or

li
{
 cursor: pointer;
}

Working example 1:

_x000D_
_x000D_
    li:hover_x000D_
    {_x000D_
     cursor: pointer;_x000D_
    }
_x000D_
<ul>_x000D_
  <li>foo</li>_x000D_
  <li>bar</li>_x000D_
</ul>
_x000D_
_x000D_
_x000D_

Working example 2:

_x000D_
_x000D_
    li_x000D_
    {_x000D_
     cursor: pointer;_x000D_
    }
_x000D_
<ul>_x000D_
  <li>foo</li>_x000D_
  <li>bar</li>_x000D_
</ul>
_x000D_
_x000D_
_x000D_


All of the other responses suggest using the standard CSS pointer, however, there are two methods:

  1. Apply the CSS property cursor:pointer; to the elements. (This is the default style when a cursor hovers over a button.)

  2. Apply the CSS property cursor:url(pointer.png); using a custom graphic for your pointer. This may be more desirable if you want to ensure that the user experience is identical on all platforms (instead of allowing the browser/OS decide what your pointer cursor should look like). Note that fallback options may be added in case the image is not found, including secondary urls or any of the other options i.e. cursor:url(pointer.png,fallback.png,pointer);

Of course these may be applied to the list items in this manner li{cursor:pointer;}, as a class .class{cursor:pointer;}, or as a value for the style attribute of each element style="cursor:pointer;".


Use:

li:hover {
    cursor: pointer;
}

Other valid values (which hand is not) for the current HTML specification can be viewed here.


Check the following. I get it from W3Schools.

_x000D_
_x000D_
.alias { cursor: alias; }
.all-scroll { cursor: all-scroll; }
.auto { cursor: auto; }
.cell { cursor: cell; }
.context-menu { cursor: context-menu; }
.col-resize { cursor: col-resize; }
.copy { cursor: copy; }
.crosshair { cursor: crosshair; }
.default { cursor: default; }
.e-resize { cursor: e-resize; }
.ew-resize { cursor: ew-resize; }
.grab {
  cursor: -webkit-grab;
  cursor: grab;
}
.grabbing {
  cursor: -webkit-grabbing;
  cursor: grabbing;
}
.help { cursor: help; }
.move { cursor: move; }
.n-resize { cursor: n-resize; }
.ne-resize { cursor: ne-resize; }
.nesw-resize { cursor: nesw-resize; }
.ns-resize { cursor: ns-resize; }
.nw-resize { cursor: nw-resize; }
.nwse-resize { cursor: nwse-resize; }
.no-drop { cursor: no-drop; }
.none { cursor: none; }
.not-allowed { cursor: not-allowed; }
.pointer { cursor: pointer; }
.progress { cursor: progress; }
.row-resize { cursor: row-resize; }
.s-resize { cursor: s-resize; }
.se-resize { cursor: se-resize; }
.sw-resize { cursor: sw-resize; }
.text { cursor: text; }
.url { cursor: url(myBall.cur), auto; }
.w-resize { cursor: w-resize; }
.wait { cursor: wait; }
.zoom-in { cursor: zoom-in; }
.zoom-out { cursor: zoom-out; }
_x000D_
<!DOCTYPE html>
<html>

<body>
  <h1>The cursor property</h1>
  <p>Mouse over the words to change the mouse cursor.</p>
  <p class="alias">alias</p>
  <p class="all-scroll">all-scroll</p>
  <p class="auto">auto</p>
  <p class="cell">cell</p>
  <p class="context-menu">context-menu</p>
  <p class="col-resize">col-resize</p>
  <p class="copy">copy</p>
  <p class="crosshair">crosshair</p>
  <p class="default">default</p>
  <p class="e-resize">e-resize</p>
  <p class="ew-resize">ew-resize</p>
  <p class="grab">grab</p>
  <p class="grabbing">grabbing</p>
  <p class="help">help</p>
  <p class="move">move</p>
  <p class="n-resize">n-resize</p>
  <p class="ne-resize">ne-resize</p>
  <p class="nesw-resize">nesw-resize</p>
  <p class="ns-resize">ns-resize</p>
  <p class="nw-resize">nw-resize</p>
  <p class="nwse-resize">nwse-resize</p>
  <p class="no-drop">no-drop</p>
  <p class="none">none</p>
  <p class="not-allowed">not-allowed</p>
  <p class="pointer">pointer</p>
  <p class="progress">progress</p>
  <p class="row-resize">row-resize</p>
  <p class="s-resize">s-resize</p>
  <p class="se-resize">se-resize</p>
  <p class="sw-resize">sw-resize</p>
  <p class="text">text</p>
  <p class="url">url</p>
  <p class="w-resize">w-resize</p>
  <p class="wait">wait</p>
  <p class="zoom-in">zoom-in</p>
  <p class="zoom-out">zoom-out</p>
</body>

</html>
_x000D_
_x000D_
_x000D_


Using an HTML Hack

Note: this is not recommended as it is considered bad practice

Wrapping the content in an anchor tag containing an href attribute will work without explicitly applying the cursor: pointer; property with the side effect of anchor properties (amended with CSS):

_x000D_
_x000D_
<a href="#" style="text-decoration: initial; color: initial;"><div>This is bad practice, but it works.</div></a>
_x000D_
_x000D_
_x000D_


Simply just do something like this:

li { 
  cursor: pointer;
}

I apply it on your code to see how it works:

_x000D_
_x000D_
li {_x000D_
  cursor: pointer;_x000D_
}
_x000D_
<ul>_x000D_
  <li>foo</li>_x000D_
  <li>goo</li>_x000D_
</ul>
_x000D_
_x000D_
_x000D_

Note: Also DO not forget you can have any hand cursor with customised cursor, you can create fav hand icon like this one for example:

_x000D_
_x000D_
div {_x000D_
  display: block;_x000D_
  width: 400px;_x000D_
  height: 400px;_x000D_
  background: red;_x000D_
  cursor: url(http://findicons.com/files/icons/1840/free_style/128/hand.png) 4 12, auto;_x000D_
}
_x000D_
<div>_x000D_
</div>
_x000D_
_x000D_
_x000D_


You do not require jQuery for this, simply use the following CSS content:

li {cursor: pointer}

And voilĂ ! Handy.


<style>
.para{
    color: black;
}
.para:hover{
    cursor: pointer;
    color: blue;
}
</style>
<div class="para">

In the above HTML code [:hover] is used to indicate that the following style must be applied only on hovering or keeping the mouse cursor on it.

There are several types of cursors available in CSS:

View the below code for types of cursor:

<style>
.alias {cursor: alias;}
.all-scroll {cursor: all-scroll;}
.auto {cursor: auto;}
.cell {cursor: cell;}
.context-menu {cursor: context-menu;}
.col-resize {cursor: col-resize;}
.copy {cursor: copy;}
.crosshair {cursor: crosshair;}
.default {cursor: default;}
.e-resize {cursor: e-resize;}
.ew-resize {cursor: ew-resize;}
.grab {cursor: -webkit-grab; cursor: grab;}
.grabbing {cursor: -webkit-grabbing; cursor: grabbing;}
.help {cursor: help;}
.move {cursor: move;}
.n-resize {cursor: n-resize;}
.ne-resize {cursor: ne-resize;}
.nesw-resize {cursor: nesw-resize;}
.ns-resize {cursor: ns-resize;}
.nw-resize {cursor: nw-resize;}
.nwse-resize {cursor: nwse-resize;}
.no-drop {cursor: no-drop;}
.none {cursor: none;}
.not-allowed {cursor: not-allowed;}
.pointer {cursor: pointer;}
.progress {cursor: progress;}
.row-resize {cursor: row-resize;}
.s-resize {cursor: s-resize;}
.se-resize {cursor: se-resize;}
.sw-resize {cursor: sw-resize;}
.text {cursor: text;}
.url {cursor: url(myBall.cur),auto;}
.w-resize {cursor: w-resize;}
.wait {cursor: wait;}
.zoom-in {cursor: zoom-in;}
.zoom-out {cursor: zoom-out;}
</style>

Click the below link for viewing how the cursor property acts:

https://www.w3schools.com/cssref/tryit.asp?filename=trycss_cursor


You can use the code below:

li:hover { cursor: pointer; }