Copied!
Guide

How to make a custom cursor with CSS and JavaScript

The dot-and-ring cursor you see on portfolio sites is two small elements that follow the pointer at different speeds. Here is how to build it without lag, and when to leave the normal cursor alone.

← Blog
Title card: Custom cursor. Preview of the Cursor follower states element from the Enrichr Library.

December 4, 2026

3 min readDot, ring and hover states

To make a custom cursor, add a small fixed element to the page, store the pointer position on pointermove, and move the element to that position every animation frame with a transform. A second, larger ring that only covers part of the remaining distance each frame gives the trailing effect. The free Enrichr Library has five finished cursors to copy.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

What is the basic pattern?

<div class="cur-dot"></div>
<div class="cur-ring"></div>
.cur-dot, .cur-ring {
  position: fixed; left: 0; top: 0;
  border-radius: 50%;
  pointer-events: none;      /* never block clicks */
  z-index: 9999;
  display: none;
}
.cur-dot  { width: 8px;  height: 8px;  margin: -4px;  background: #111; }
.cur-ring { width: 36px; height: 36px; margin: -18px; border: 1px solid #111;
            transition: scale 0.2s; }
.cur-ring.is-link { scale: 1.6; }

@media (hover: hover) and (pointer: fine) {
  .cur-dot, .cur-ring { display: block; }
}
const dot = document.querySelector(".cur-dot");
const ring = document.querySelector(".cur-ring");
let x = 0, y = 0, rx = 0, ry = 0;

addEventListener("pointermove", (e) => { x = e.clientX; y = e.clientY; });

addEventListener("pointerover", (e) => {
  ring.classList.toggle("is-link", !!e.target.closest("a, button"));
});

(function frame() {
  rx += (x - rx) * 0.15;     // the ring covers 15% of the gap each frame
  ry += (y - ry) * 0.15;
  dot.style.transform  = `translate3d(${x}px, ${y}px, 0)`;
  ring.style.transform = `translate3d(${rx}px, ${ry}px, 0)`;
  requestAnimationFrame(frame);
})();

The line rx += (x - rx) * 0.15 is a lerp. A smaller number gives a lazier ring. A larger one makes it stick to the dot.

How do I make the cursor invert what is under it?

Give the dot a white background and mix-blend-mode: difference. White in difference mode flips every colour beneath it, so the cursor stays visible on light and dark sections alike.

Which finished cursors can I copy?

ElementWhat it does
Cursor follower statesA dot and lagging ring that grows over links and shows a label on cards and sliders.
Blend mode cursorA dot that inverts what is beneath it and grows over links, for fine pointers only.
Jiggle cursor dotA see-through dot that wobbles like jelly when you move fast.
Invert ripple cursorA big circle that inverts everything beneath it, with a rippling edge.
Refractive glass lensA glass lens that follows the pointer and bends the page behind it.

When should I not use a custom cursor?

If you hide the real cursor with cursor: none, do it only inside the same media query, so a failed script never leaves the visitor with no cursor at all.

Where to go next

FAQ

How do I make a custom cursor that follows the mouse?

Add a small fixed element, listen for pointermove to store the pointer position, and on each animation frame move the element toward that position with a CSS transform.

Why does my custom cursor lag or stutter?

You are probably animating left and top, or using a CSS transition on every mouse event. Move it with transform: translate3d() inside requestAnimationFrame instead.

Can I just use the CSS cursor property?

Yes, for a static image: cursor: url(cursor.png) 8 8, auto. The numbers set the hot spot. It cannot animate or react to what is under it, which is why sites use an element instead.

Should I hide the real cursor?

Only where your own cursor is running, and never on text fields. People need the text caret to see where they are typing.