October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Build a Crosshair Cursor Effect with HTML, CSS & JavaScript

Use CSS cursor: crosshair for a simple marker, or build a custom pointer-following overlay with HTML, CSS, and JavaScript that does not block page controls.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a standard crosshair, CSS alone is enough: apply cursor: crosshair to the area where it should appear. If you want a custom graphic that follows the pointer or trails behind it, add a decorative HTML element and position it with JavaScript. The custom element should remain a visual layer, not interfere with the page’s links, buttons, or other controls.

Choose the right kind of crosshair

There are two practical approaches. Use the browser’s native crosshair for a simple, dependable pointer on a particular region. Use a custom cursor image or a JavaScript-positioned overlay when you need a distinct shape, a follow effect, or animation.

As an Amazon Associate I earn from qualifying purchases.

Approach Best for Tradeoff
CSS cursor: crosshair A standard crosshair in a particular region Its appearance and behavior are browser-provided. MDN’s cursor reference lists it as a predefined keyword.
CSS cursor image A custom cursor graphic without a separate tracking element Requires a fallback keyword; image dimensions and hotspot behavior can vary by browser. MDN documents the cursor image syntax and limits.
JavaScript-positioned overlay A shape that follows, trails, or animates with the pointer Needs pointer tracking, hit-testing safeguards, fallback behavior, and care with motion preferences and devices.

Use the native CSS crosshair

Apply the cursor to only the region where it makes sense, rather than changing it indiscriminately across the page. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.drawing-area {
  cursor: crosshair;
}

MDN notes that a cursor should communicate the mouse operation available at the current location, such as selecting text, activating a control, or resizing content. Keep the usual cursor on text, links, and buttons when a crosshair would mislead users.

#1 Best Overall
Sale
Logitech G305 Lightspeed Wireless Gaming Mouse - Black
  • The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
  • Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
  • G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
  • Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
  • The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere

Use a custom cursor image

If a static custom crosshair is enough, CSS supports an image cursor with a keyword fallback. The optional numbers set the hotspot—the active point—relative to the image’s top-left corner:

.drawing-area {
  cursor: url("/images/crosshair.png") 16 16, crosshair;
}

Here, 16 16 places the hotspot 16 pixels from the image’s left edge and 16 pixels from its top edge. Change those coordinates to match the point that should align with the pointer. Keep the fallback keyword after the image URL so the browser has another cursor to use if the image cannot be used.

Rank #2
Sale
Logitech G502 Hero Wired Gaming Mouse - Black
  • HERO Gaming Sensor: Next generation HERO mouse sensor delivers precision tracking up to 25600 DPI with zero smoothing, filtering or acceleration
  • 11 programmable buttons and dual mode hyper-fast scroll wheel: The Logitech wired gaming mouse gives you fully customizable control over your gameplay
  • Adjustable weights: Match your playing style. Arrange up to five 3.6 g weights for a personalized weight and balance configuration
  • LIGHTSYNC technology: Logitech G LIGHTSYNC technology provides fully customizable RGB lighting that can also synchronize with your gaming (requires Logitech Gaming Software)
  • Mechanical Switch Button Tensioning: A metal spring tensioning system and metal pivot hinges are built into left and right computer gaming mouse buttons for a crisp, clean click feel with rapid click feedback

Cursor image dimensions are not uniformly supported. MDN recommends 32 by 32 pixels and notes a default restriction of 128 by 128 pixels in Firefox and Chromium; these are documentation notes, not guarantees for every browser or version. See MDN’s cursor reference for details.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a crosshair that follows the pointer

A separate element gives you more control over the crosshair’s appearance and movement. This example creates a decorative overlay, starts it when a mouse or pen moves over the page, and leaves the system cursor available as a fallback.

Rank #3
Sale
Logitech G305 Lightspeed Wireless Gaming Mouse - White
  • Next-gen 12,000 DPI HERO optical sensor delivers unrivaled gaming performance, accuracy and power efficiency
  • Advanced LIGHTSPEED wireless gaming mouse for super-fast 1 ms response time and faster than wired performance
  • Ultra-long battery life gives you up to 250 hours of continuous gaming on a single AA battery
  • Lightweight mechanical design and classic shape for maximum maneuverability, durability and comfort
  • Compact, portable design with convenient built-in storage for included USB wireless receiver

1. Add the decorative element

<div class="pointer-crosshair" aria-hidden="true"></div>

The element is hidden from assistive technology because it is decoration, not content or a control.

2. Style and position it

.pointer-crosshair {
  position: fixed;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  border: 1px solid currentColor;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
}

.pointer-crosshair::before,
.pointer-crosshair::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.pointer-crosshair::before {
  width: 1px;
  height: 8px;
  left: 50%;
  top: -5px;
  transform: translateX(-50%);
  box-shadow: 0 26px currentColor;
}

.pointer-crosshair::after {
  width: 8px;
  height: 1px;
  top: 50%;
  left: -5px;
  transform: translateY(-50%);
  box-shadow: 26px 0 currentColor;
}

position: fixed and viewport coordinates keep the overlay aligned with the pointer while the page scrolls. The centering transform makes its center the active point. The initial zero opacity prevents an element fixed at the top-left corner from flashing before pointer movement.

Rank #4
Sale
Razer Basilisk V3 Customizable RGB Wired Ergonomic Gaming Mouse, Black
  • ICONIC ERGONOMIC DESIGN WITH THUMB REST — PC gaming mouse favored by millions worldwide with a form factor that perfectly supports the hand while its buttons are optimally positioned for quick and easy access
  • 11 PROGRAMMABLE BUTTONS — Assign macros and secondary functions across 11 programmable buttons to execute essential actions like push-to-talk, ping, and more
  • HYPERSCROLL TILT WHEEL — Speed through content with a scroll wheel that free-spins until its stopped or switch to tactile mode for more precision and satisfying feedback that’s ideal for cycling through weapons or skills
  • 11 RAZER CHROMA RGB LIGHTING ZONES — Customize each zone from over 16.8 million colors and countless lighting effects, all while it reacts dynamically with over 150 Chroma integrated games
  • OPTICAL MOUSE SWITCHES GEN 2 — With zero unintended misclicks these switches provide crisp, responsive execution at a blistering 0.2ms actuation speed for up to 70 million clicks

3. Update it from pointer events

const crosshair = document.querySelector(".pointer-crosshair");

window.addEventListener("pointermove", (event) => {
  if (event.pointerType === "touch") return;

  crosshair.style.left = `${event.clientX}px`;
  crosshair.style.top = `${event.clientY}px`;
  crosshair.style.opacity = "1";
});

clientX and clientY are viewport coordinates, matching the fixed positioning. Pointer Events cover mouse, pen, and touch; this example skips touch because a mouse-following decoration generally has no useful role on a touch-only screen. If your design should support a different set of devices, choose the behavior deliberately rather than assuming every pointer is a mouse.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Keep the overlay from blocking interaction

The pointer-events: none rule is essential: it lets pointer events target the content underneath the crosshair instead of the decorative element. Without it, the overlay can interfere with links, buttons, and hover states. MDN explains this behavior in its pointer-events reference.

Best Value
Sale
Redragon M612 Wired RGB Optical Gaming Mouse 8000 DPI Remapping Keys
  • Pentakill, 5 DPI Levels - Geared with 5 redefinable DPI levels (default as: 500/1000/2000/3000/4000), easy to switch between different game needs. Dedicated demand of DPI options between 500-8000 is also available to be processed by software.
  • Any Button is Reassignable - 11 programmable buttons are all editable with customizable tactical keybinds in whatever game or work you are engaging. 1 rapid fire + 2 side macro buttons offer you a better gaming and working experience.
  • Comfort Grip with Details - The skin-friendly frosted coating is the main comfort grip of the mouse surface, which offers you the most enjoyable fingerprint-free tactility. The left side equipped with rubber texture strengthened the friction and made the mouse easier to control.
  • 5 Decent Backlit Modes - Turn the backlit on and make some kills in your gaming battlefield. The hyped dynamic RGB backlit vibe will never let you down when decorating your gaming space, it would be better with other Redragon accessories with lights on.
  • Fatigue Killer with Ergonomic Design - Solid frame with a streamlined and general claw-grip design offers a satisfying and comfortable gaming experience with less fatigue even though after hours of use.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Add a trailing effect without ignoring reduced motion

A follow effect can be softened with a CSS transition, but movement should respect the visitor’s system preference. One option is to enable a short transition only when reduced motion has not been requested:

@media (prefers-reduced-motion: no-preference) {
  .pointer-crosshair {
    transition: left 80ms linear, top 80ms linear, opacity 120ms ease;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pointer-crosshair {
    transition: none;
  }
}

The prefers-reduced-motion media feature lets a site adapt movement to the visitor’s preference. For more background, see MDN’s reduced-motion reference.

Check the effect across devices and interactions

  • Do not replace useful cursor meaning: keep text selection, links, buttons, and resize affordances understandable.
  • Maintain contrast: choose a crosshair that remains visible over the page’s backgrounds, and avoid obscuring text or important controls.
  • Keep a fallback: a native cursor or CSS fallback remains useful if the custom element or its JavaScript is unavailable.
  • Account for device differences: Pointer Events include mouse, pen, and touch. On iPadOS, a pointer device uses a circular pointer by default, and MDN notes that only the text cursor value changes its appearance by default. Do not assume desktop cursor styling will look identical there. See MDN’s cursor reference and Pointer Events documentation.

The browser-provided crosshair is the simplest choice when it meets the need. A custom overlay is appropriate when its distinct appearance or movement adds value, provided it stays decorative and does not get in the way of the interface.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.