How to change the cursor into a hand when a user hovers over a list item?
Asked Answered
S

28

2373

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.

Sturgeon answered 21/6, 2010 at 19:45 Comment(4)
FYI, I retagged your question by removing "jquery" and adding "css" to more accurately reflect the nature of your question and the answer to it.Gilda
A good reference list for changing the cursor to a hand and other icons available in css. javascriptkit.com/dhtmltutors/csscursors.shtmlFideliafidelio
If there is a click handler that is added with JavaScript also the css for the mouse pointer should be added with JavaScript. So the user does not think he or she could click where it is not possible. I added an appropriate answer for this.Ananna
Did you try cursor: grabHilariahilario
C
3826

In light of the passage of time, as people have mentioned, you can now safely just use:

li { cursor: pointer; }
Chlamydospore answered 21/6, 2010 at 19:50 Comment(7)
It's worth noting that just doing cursor: pointer is good enough for everything above IE 5.5: quirksmode.org/css/cursor.htmlHarrus
It's funny how pointer!=cursor and hand!=pointer, adding even more to the confusion. :)Subset
Of note, quirksmode.org/css/user-interface/cursor.html#note (referenced in an earlier comment) states that hand must come after pointer. I recommend using just pointer - IE 5.5 is deader than IE 6.Pontoon
@EdwardBlack it used to be required for odd browsers that weren't standards compliant, the answer was updated long ago to reflect the new way which is simply just pointer this question is over 5 years old btw.Chlamydospore
Indeed. Even if you run IE in IE5 compatibility mode, cursor:pointer still works. So if there ever was an excuse to use cursor:hand, there no longer is.Needy
And according to CSS 3.0 Validation "cursor:hand" is not a valid value for cursor. We should use just cursor:pointerStephaniestephannie
Just use this in whatever HTML element you want the cursor pointer on hoverStannary
J
542

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

.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; }

.cursors > div {
    float: left;
    box-sizing: border-box;
    background: #f2f2f2;
    border:1px solid #ccc;
    width: 20%;
    padding: 10px 2px;
    text-align: center;
    white-space: nowrap;
    &:nth-child(even) {
       background: #eee;
    }
    &:hover {
       opacity: 0.25
    }
}
<h1>Example of cursor</h1>

<div class="cursors">
    <div class="auto">auto</div>
    <div class="default">default</div>
    <div class="none">none</div>
    <div class="context-menu">context-menu</div>
    <div class="help">help</div>
    <div class="pointer">pointer</div>
    <div class="progress">progress</div>
    <div class="wait">wait</div>
    <div class="cell">cell</div>
    <div class="crosshair">crosshair</div>
    <div class="text">text</div>
    <div class="vertical-text">vertical-text</div>
    <div class="alias">alias</div>
    <div class="copy">copy</div>
    <div class="move">move</div>
    <div class="no-drop">no-drop</div>
    <div class="not-allowed">not-allowed</div>
    <div class="all-scroll">all-scroll</div>
    <div class="col-resize">col-resize</div>
    <div class="row-resize">row-resize</div>
    <div class="n-resize">n-resize</div>
    <div class="s-resize">s-resize</div>
    <div class="e-resize">e-resize</div>
    <div class="w-resize">w-resize</div>
    <div class="ns-resize">ns-resize</div>
    <div class="ew-resize">ew-resize</div>
    <div class="ne-resize">ne-resize</div>
    <div class="nw-resize">nw-resize</div>
    <div class="se-resize">se-resize</div>
    <div class="sw-resize">sw-resize</div>
    <div class="nesw-resize">nesw-resize</div>
    <div class="nwse-resize">nwse-resize</div>
</div>
Jimenez answered 4/1, 2017 at 11:21 Comment(4)
Off topic, Using which software you did that gif animation? Waiting..@Santosh KhalseDygert
@Dygert check ShareX - record a gifEleonoraeleonore
I felt this was a useful reminder of cursors and added the code as a tool. Here's a link to the code above: spragucm.com/web-css-cursor-pointersCrucial
Awesome animation! @Dygert - Peek is also good for recording gifs of an area of your screen. github.com/phw/peekLorenzetti
R
187

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

li {cursor: pointer}

And voilà! Handy.

Resupine answered 21/6, 2010 at 19:47 Comment(0)
H
86

Use:

li:hover {
    cursor: pointer;
}

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

Hierarchy answered 7/1, 2013 at 11:50 Comment(5)
I don't understand what the use of the :hover pseudo class is in this case. Is there any advantage for specifying a different cursor when the mouse does not hover the element? Also I read that li:hover does not work in IE6.Sectarianize
I suppose :hover is just for specificity, @Robert. I can't test for support in any version of MSIE, sorry, but it wouldn't surprise me if it didn't work! :PHierarchy
why is hand in the top answer, even though it is not working?Iselaisenberg
@EdwardBlack cursor: hand is deprecated and not in the css spec. it's like from ie5-6 era. use only pointer.Sidsida
I'd just like to point out that (in Chrome at least) specifying element:hover will take priority, but happen after element. What I mean by this is if cursor is specified in both element:hover and element the cursor specified in element will flash on the screen for a second before turning to the cursor in :hover. While this isn't important for li elements as they have no default cursor to start with, if someone wants to change the cursor on an element that already has one (like with a elements) they should do so without the :hover specifier.Ferris
D
52

Use

cursor: pointer;
cursor: hand;

if you want to have a crossbrowser result!

Dig answered 27/10, 2011 at 7:34 Comment(3)
This is 2018, and cursor:hand is no longer needed for cross-browser development right?Wolfie
@Haramoz - yeah, cursor: hand is largely obsolete, now. Hasn't been around since IE 5.5.Gothurd
It will generate error in css validatorRemake
M
49

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;
}
Monroemonroy answered 11/9, 2014 at 7:51 Comment(2)
It is not an answer to the question.Knisley
this maybe not the direct answer to the question but this is a very good guideline. thanks by the way!Fontanez
A
24

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; }
Ananna answered 2/3, 2014 at 12:40 Comment(0)
D
23
li:hover {cursor: hand; cursor: pointer;}
Dew answered 5/6, 2013 at 21:52 Comment(0)
F
22

For complete cross browser, use:

cursor: pointer;
cursor: hand;
Ferule answered 5/12, 2012 at 19:46 Comment(0)
M
22

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

Manic answered 18/8, 2016 at 15:19 Comment(0)
C
20

You can change it either on hover or just specify cursor:pointer on list item, both will work.

ul li {
  cursor: pointer;
}

Alternatively

ul li:hover {
  cursor: pointer;
}
Communism answered 21/7, 2021 at 9:33 Comment(0)
P
17

Simply put this code.

li{cursor: pointer;}
Phile answered 25/11, 2021 at 8:23 Comment(0)
G
16

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

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

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

Gothurd answered 23/7, 2014 at 2:25 Comment(0)
S
15

Simply just do something like this:

li { 
  cursor: pointer;
}

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

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

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:

div {
  display: block;
  width: 400px;
  height: 400px;
  background: red;
  cursor: url(http://findicons.com/files/icons/1840/free_style/128/hand.png) 4 12, auto;
}
<div>
</div>
Sublieutenant answered 21/6, 2017 at 12:50 Comment(0)
D
13
ul li:hover{
   cursor: pointer;
}
Duluth answered 21/12, 2014 at 18:34 Comment(0)
V
11

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;".

Ventage answered 27/2, 2016 at 5:25 Comment(0)
A
10

Use:

ul li:hover{
   cursor: pointer;
}

For more mouse events, check CSS cursor property.

Ankle answered 3/2, 2016 at 6:48 Comment(1)
Duplicate answer. Should've added the link as an edit to the other answer dated Dec. 21, 2014 by user3776645.Gothurd
P
7

You can use one of the following:

li:hover
{
 cursor: pointer;
}

or

li
{
 cursor: pointer;
}

Working example 1:

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

Working example 2:

    li
    {
     cursor: pointer;
    }
<ul>
  <li>foo</li>
  <li>bar</li>
</ul>
Pleiad answered 13/5, 2018 at 10:29 Comment(0)
T
6

For a basic hand symbol:

Try

cursor: pointer 

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

cursor: grab
Torrance answered 24/12, 2015 at 4:13 Comment(0)
R
5

You can use the code below:

li:hover { cursor: pointer; }

Ricky answered 6/6, 2018 at 9:54 Comment(0)
D
5

Check the following. I get it from W3Schools.

.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; }
<!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>
Dictate answered 29/9, 2018 at 5:48 Comment(0)
D
4

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):

<a href="#" style="text-decoration: initial; color: initial;"><div>This is bad practice, but it works.</div></a>
Dateline answered 19/6, 2016 at 11:19 Comment(2)
This does not work. Anchor tags only have a pointer cursor with underline and a different colour if they have a href.Candice
"How can I make the cursor a hand when a user hovers over a list item?" - For this particular question, it does. But as pointed out by @sandrooco not a good practice.Dateline
H
4

You can also use the following style:

li {
    cursor: grabbing;
}
Hippomenes answered 14/9, 2017 at 11:22 Comment(0)
K
4

You can just use CSS style for this.

li { cursor: pointer; }
Kalahari answered 23/5, 2023 at 2:6 Comment(0)
R
4

css

li:hover { cursor:pointer }

bootsrap

<a href="#" class="pe-auto">This link</a> 
Rangoon answered 26/9, 2023 at 9:37 Comment(0)
B
2

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

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;
}
<ul>
  <li>a</li>
  <li>b</li>
  <li>c</li>
</ul>

refs

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

Belovo answered 29/8, 2019 at 9:48 Comment(0)
H
1
<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

Huskamp answered 4/7, 2020 at 5:54 Comment(0)
E
1

it's equivalent class in tailwindcss is `cursor-pointer'.

Expertism answered 28/2, 2023 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.