Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using external images for CSS custom cursors

Tags:

html

css

cursor

Is it possible to use external image URLs for CSS custom cursors? The following example doesn't work:

HTML:

<div class="test">TEST</div> 

CSS:

.test {   background:gray;   width:200px;   height:200px;   cursor:url('http://upload.wikimedia.org/wikipedia/commons/d/de/POL_apple.jpg'); } 

Fiddle: http://jsfiddle.net/wNKcU/4/

like image 296
Yarin Avatar asked Aug 31 '13 18:08

Yarin


People also ask

How do I make an image a cursor in CSS?

Answer: Use the CSS cursor propertygif or . png (for Firefox, Chrome, Safari) and . cur for (for Internet Explorer). After that apply the cursor property with a comma-separated list of URLs pointing to these cursor images.

Can I use SVG as cursor CSS?

To change the default mouse cursor using an external image, you need to: Create an SVG image; Convert it to data URI so that you can use it in CSS.

How do I customize my cursor in CSS?

Now how do I use CSS to customize a mouse cursor? To use this, you just have to tell CSS what image you intend to use and point the cursor property to the image URL using the url value. From the code snippet above, you can see I set this on the document body, so it can apply to the cursor no matter where it moves.


2 Answers

It wasn't working because your image was too big - there are restrictions on the image dimensions. In Firefox, for example, the size limit is 128x128px. See this page for more details.

Additionally, you also have to add in auto.

jsFiddle demo here - note that's an actual image, and not a default cursor.

.test {    background:gray;    width:200px;    height:200px;    cursor:url(http://www.javascriptkit.com/dhtmltutors/cursor-hand.gif), auto;  }
<div class="test">TEST</div>
like image 77
Josh Crozier Avatar answered Sep 21 '22 12:09

Josh Crozier


I would put this as a comment, but I don't have the rep for it. What Josh Crozier answered is correct, but for IE .cur and .ani are the only supported formats for this. So you should probably have a fallback just in case:

.test {     cursor:url("http://www.javascriptkit.com/dhtmltutors/cursor-hand.gif"), url(foo.cur), auto; } 
like image 41
CFraser Avatar answered Sep 19 '22 12:09

CFraser