SHARE
Facebook X Pinterest WhatsApp

Create Custom Cursors With JavaScript and CSS3

Written By
thumbnail
Michael Rohde
Michael Rohde
Aug 5, 2011

When developing your website, you might be scratching your head wondering what you can do to customize your site further. One possibility that can add some flavor and zest to your site while at the same time reinforcing branding, is to use a custom cursor. Your custom cursor can be any image that you choose.

For example, why not use a miniature version of your logo or company name? It’s best however, to keep it within the realm of usability and not be so jarring as to distract your visitor. A custom cursor should remain useful while showing to your visitors that this site invested a little extra time and code to provide a unique experience.

Let’s start with the JavaScript code for jQuery that will allow the arrow to follow the cursor. You’ll want to place this code within the <head> tags of your HTML page.

<script type="text/javascript">
 	$(document).ready(function(){
      	$('#test-area').mouseout(function(){
           	$('#mycursor').hide();
           	return >false;
      	});
      	$('#test-area').mouseenter(function(){
           	$('#mycursor').show();
           	return >false;
      	});
      	$('#test-area').mousemove(function(e){
           	$('#mycursor').css('left', e.clientX - 20).css('top', e.clientY + 7);
      	});
});
</script>

Now for the CSS. First, let’s create an area for where the custom cursor will appear:

#test-area {
 	height: 200px;
 	border: 3px dashed #CCCCCC;
 	background: #FFFFFF;
 	padding: 20px;
 	cursor: url(./blank.cur), none;
}

That code is pretty basic enough. You might notice that it sets the cursor to use an image file that is blank in the very last line.

Here is the CSS code for the custom cursor:

#mycursor {
 	cursor: none;
 	width: 97px;
 	height: 137px;
 	background: url("images/custom-cursor.jpg") no-repeat left top;
 	position: absolute;
 	display: none;
 	top: 0;
 	left: 0;
 	z-index: 10000;
}

You will want to adjust the width and height to match your custom cursor. You’ll also want to update the path to the image.

Now, to add the custom cursor to your HTML page:

<div id="test-area">
     Move mouse over this area.
</div>
<div id="mycursor"></div>

Originally, I learned this code from ajaxblender. Unfortunately, I was not able to recreate this code for use on my CSS playground. Everything worked except the custom cursor never appeared. Instead, the cursor simply disappeared while I hovered over the test area. Perhaps you will have better luck than me and this will serve as inspiration for you to improve your site.

Recommended for you...

Importing Custom Less Styles at Run-time in Angular
Rob Gravelle
Jun 14, 2022
Setting CSS Values from Less Variables in Angular
Rob Gravelle
Jun 4, 2022
Color Manipulation with JavaScript
Rob Gravelle
May 21, 2022
An Introduction to CSS-in-JS
Rob Gravelle
May 14, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.