Skip to content

Image Reveal Cursor on Hover

Tailwind CSS project list where hovering a row reveals a photo that follows the cursor with smooth easing and tilt, plus keyboard and touch fallbacks.

Live preview

Open in new tab

Code

An editorial project list built with Tailwind CSS where hovering a row reveals a photo that follows the mouse cursor. The preview glides behind the pointer with smooth easing, tilts with the movement and cross-fades between projects. It fits portfolio sites, design studios and agency case-study indexes.

How it works

The root is section.irc-reveal. The list (ul.irc-list) contains one link per project: a.irc-item with a data-irc-index, the large .irc-name title, a type column and an arrow. A single floating preview, div.irc-preview with data-irc-preview, sits at the end of the section. Its .irc-frame holds one img.irc-img per project, linked by data-irc-img.

The script listens to pointermove on the root and converts the cursor position into coordinates relative to the section. A requestAnimationFrame loop moves the preview a fraction of the remaining distance each frame (linear interpolation), sets translate3d() and a rotation based on the horizontal speed, and stops as soon as the preview settles. pointerenter on a row adds .is-current to that row and its photo and .is-active to the root; pointerleave on the list hides the frame again. In style.css, .is-active scales and fades in .irc-frame, .irc-img.is-current cross-fades the photo with a slight zoom-out, and the other rows dim to --irc-dim.

On first load (pointer devices only) the row whose index matches data-irc-default is already previewed beside its title, so the photo is visible before any interaction. When the pointer enters another row, the preview glides from that spot to the cursor and normal following takes over.

On devices without hover (@media (hover: none)) the floating preview is hidden and a small inline .irc-thumb image appears in every row instead, so touch users still see each project.

Customization

  • data-irc-ease on .irc-reveal: add a value between 0.05 (lazy, floaty) and 1 (sticks to the cursor); the default is 0.16.
  • data-irc-tilt on .irc-reveal: maximum rotation in degrees while moving; the default is 10.
  • h-[375px] w-[300px] on .irc-preview: change the preview size or ratio, e.g. h-[240px] w-[360px] for landscape photos.
  • --irc-dim in style.css: opacity of the rows that are not previewed; use 1 to disable dimming.
  • data-irc-default on .irc-reveal: index of the project shown on load; remove the attribute to start with the preview hidden.
  • Add a row by copying an li and adding a matching img.irc-img; keep data-irc-index and data-irc-img in sync.

Accessibility

Each project is a real link with a visible name, so the list works with a keyboard and screen readers on its own. The floating preview is aria-hidden="true" and pointer-events-none, because it only repeats what the link says. When a row receives keyboard focus the preview appears next to it, and every link shows an orange focus-visible outline. Under prefers-reduced-motion: reduce the preview jumps straight to the cursor without easing, tilt or zoom.

Usage notes

The photos come from Unsplash; replace them with your own project images. The demo links use href="#", which the script ignores; point them to real pages.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Image Reveal Cursor on Hover – Tailwind CSS cursor effects component screenshot
Image Reveal Cursor on Hover · Tailwind CSS Cursor Effects

More Cursor Effects

Custom Cursor Follower – Pure CSS cursor effects preview

Custom Cursor Follower

Smooth custom cursor with a dot and an eased ring that grows on links, shows a label over cards and inverts the headline, in CSS and vanilla JS.