CSS Custom Cursors
Remember the Web 1.0 days where you had to customize your site in every way possible? You abused the scrollbars in Internet Explorer, of course, but the most popular external service I can remember was CometCursor. CometCursor let you create and use loads of custom cursors for your site. Now we probably laugh at that in hindsight but there may be times when you'd like to customize a cursor, and CSS lets you do it quite easily!
The CSS
The cursor CSS property accepts a series of cursors, and using a url() value allows you to set a custom CSS cursor:
body {
cursor: url('some-cursor.ico'), default;
}
It's always best to have a backup native cursor like default, much as you set broader font-family's when styling text. Also note that Firefox scales the cursor down to a smaller size whereas Chrome currently allows a larger original size.
Now don't go doing this willy nilly, use a custom cursor in places where you think important, like a magnifying glass + or - over zoomable images and such.
![Designing for Simplicity]()
Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...
![CSS Animations Between Media Queries]()
CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...
![CSS Counters]()
Counters. They were a staple of the Geocities / early web scene that many of us "older" developers grew up with; a feature then, the butt of web jokes now. CSS has implemented its own type of counter, one more sane and straight-forward than the ole...
![HTML5’s window.postMessage API]()
One of the little known HTML5 APIs is the window.postMessage API. window.postMessage allows for sending data messages between two windows/frames across domains. Essentially window.postMessage acts as cross-domain AJAX without the server shims. Let's take a look at how window.postMessage works and how you...
How do you specify what is the clicking point? Must be part of the file format or it can be defined in the CSS for other image formats (as PNG or GIF)?
It’s probably worth noting that the keyword fallback is mandatory, and, your also able to use
.pngfiles as icons.I’ve used these about a year ago for math teaching tools. Take note that the hit point is always set to the top left point however you can change that when creating the ICO file
The cursor disappears when you right click. Any workaround?
@Filip It doesn’t for me – Firefox Nightly
ouh … and some more links:
http://mdn.io/css_cursor
https://developer.mozilla.org/en-US/docs/Web/CSS/cursor/url
I didn’t know that this is standard, that we can use .ico files as cursors. How neat :) Thanks for sharing.
How about browser support? Does it work in IE9+ and other browsers? Thanks.
All — the API is as old as me.
The demo does not work for me in IE 9-11.
Try an actual browser.
Unfortunately this seems not to work in any of my browsers; I use Windows 8.1, and use Google Chrome, Firefox and the default IExplorer as some of the possible browser I use. I’ve tried all and none managed to render the icon.
IF I lost it somewhere, feel free to give a shout and advice me. Please and thank you.
/*Syntax*/ body { cursor: url("C:\Users\User\Documents\Notepadd\Antivirus.ico"), default; /*We've set our custom cursor and also the default fall-back cursor*/ }It’s probably the fact that your icon is using a filesystem path rather than a path which the webserver is serving.
Mr Anthony do you have any advice on what I can do to make the icon render.. I’m still just developing the website.
Any help would be appreciated, Thanks.
@Mdabuko, just upload your icon file to a folder on your site, then point to it in your URL, like:
I would suggest you use relative paths as apposed to absolute paths,
so if you place your HTML document in the same folder as your .ico file.
Try:
body { cursor: url('Antivirus.ico'), default; }or if your .ico file is in a folder within your html document directory.
body { cursor: ur('Resources/Antivirus.ico'), default; }I hope this help.
There are size restrictions to the image:
“In Gecko (Firefox) the limit of the cursor size is 128×128px. Larger cursor images are ignored. However, you should limit yourself to the size 32×32 for maximum compatibility with operating systems and platforms.”
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_User_Interface/Using_URL_values_for_the_cursor_property#Limitations
Nice one.can we use other extensions for image or ico only?
PNG is also acceptable, I believe.
since .ico is a container for both .png and .bmp files, would these formats work?
Small issue: the default div doesn’t have the “cursor: default” style applied so when you hover the text, the cursor changes to text cursor type. When cursor: default is applied on an element, it should always be the default arrow cursor.
Any way to fix the pixelation when the cursor size is scaled up?