Tutorial: Getting a Crosshair Cursor

Updated:

Ever wanted to know how to get a crosshair cursor on your web page-- or just a different cursor altogether? Then check out this mini-tutorial. 


 

Sometimes you may have come across a web site where you saw the arrow cursor turn into this for a cursor over any link. 

How was this done? With good, ol' CSS. If you don't know CSS at all, no problem. I can show you a small snippet of code you can use that is very easy to remember and will get you this effect. 

How is it done?
All you have to do is insert this bit of code [below, in dark red] inside of your <head></head> tag:
<head>
<style>
<!--
a {cursor:crosshair;}
-->
</style>
</head>
That's it! Now the arrow cursor will turn into a crosshair whenever someone mouses over any link on your home page.
Other options
Option one: eliminating arrow cursor entirely
This is cool, of course. But what if you want to have the crosshair appear as the default cursor of your web site and eliminate the arrow cursor entirely? Then you would add one small additional bit to your coding ["body,"]:
 
<head>
<style>
<!--
body, a {cursor:crosshair;}
-->
</style>
</head>
Option two: causing selected links to trigger crosshair
What if you only want the crosshair for specific links, and not for the entire page? Then only put this bit of code inside every <a href></a> tag where you want the crosshair to appear:
 
<a href="page.html" style="cursor: crosshair;">

One last thing

Are you so excited by all this that you wish you had more cursors to add to your web pages? If so, you're in luck. Through the magic of CSS, you can add a number of different cursor styles to your web pages besides the crosshair. You can even add your own image for a cursor, if you like! For an extended list of them, you can visit EchoEcho, which lists them all. However, keep in mind that not all of these cursors are cross-browser or backwards compatible, and may only show up in the latest browsers.
 
 

Back to Tutorials | Home