# Cursor-following tooltip

> A small label that sticks to the cursor and follows it around an area, popping in when you enter.

- Category: [Tooltips](https://library.aimran.es/components/tooltips)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-tip-follow
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

A tooltip that follows the mouse is great over anything people explore with the pointer: a floor plan of an office or venue (“You are here”), an interactive map or the plot area of a chart. The label pops in when the cursor enters, then glides along with it. A few lines of JavaScript track the position.

It needs a mouse to make sense; on phones it only shows up where the finger taps. Keep the label to two or three words, since a long text chasing the cursor quickly becomes annoying.

## Code

### HTML

```html
<div class="uv-tf">Move your mouse here<span>You are here</span></div>
```

### CSS

```css
.uv-tf {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uv-tf {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: grid;
  place-items: center;
  width: 16em;
  height: 9em;
  border-radius: 1.2em;
  font-size: var(--s);
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  background: color-mix(in srgb,var(--fg) 5%,transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent);
  cursor: crosshair;
}

.uv-tf span {
  position: absolute;
  left: var(--x,50%);
  top: var(--y,50%);
  padding: .45em .8em;
  border-radius: 999px;
  font-size: .75em;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
  background: var(--c1);
  box-shadow: 0 8px 20px -8px var(--c1);
  transform: translate(-50%,-160%) scale(.6);
  opacity: 0;
  pointer-events: none;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.2s / var(--k)),left .08s linear,top .08s linear;
}

.uv-tf:hover span {
  transform: translate(-50%,-160%) scale(1);
  opacity: 1;
}
```

### JavaScript

```js
document.querySelectorAll(".uv-tf").forEach(el => {
  el.addEventListener("pointermove",e=>{const r=el.getBoundingClientRect();el.style.setProperty("--x",e.clientX-r.left+"px");el.style.setProperty("--y",e.clientY-r.top+"px")})
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-tf {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: grid;
  place-items: center;
  width: 16em;
  height: 9em;
  border-radius: 1.2em;
  font-size: var(--s);
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  background: color-mix(in srgb,var(--fg) 5%,transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent);
  cursor: crosshair;
}

.uv-tf span {
  position: absolute;
  left: var(--x,50%);
  top: var(--y,50%);
  padding: .45em .8em;
  border-radius: 999px;
  font-size: .75em;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
  background: var(--c1);
  box-shadow: 0 8px 20px -8px var(--c1);
  transform: translate(-50%,-160%) scale(.6);
  opacity: 0;
  pointer-events: none;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.2s / var(--k)),left .08s linear,top .08s linear;
}

.uv-tf:hover span {
  transform: translate(-50%,-160%) scale(1);
  opacity: 1;
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  el.addEventListener("pointermove",e=>{const r=el.getBoundingClientRect();el.style.setProperty("--x",e.clientX-r.left+"px");el.style.setProperty("--y",e.clientY-r.top+"px")})
}

export default function TipFollow() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-tf">Move your mouse here<span>You are here</span></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Cursor-following tooltip” block (Tooltips) from AIMRAN Library to my project.

## What it is
A small label that sticks to the cursor and follows it around an area, popping in when you enter.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "You are here"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uv-tf {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: grid;
  place-items: center;
  width: 16em;
  height: 9em;
  border-radius: 1.2em;
  font-size: var(--s);
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  background: color-mix(in srgb,var(--fg) 5%,transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent);
  cursor: crosshair;
}

.uv-tf span {
  position: absolute;
  left: var(--x,50%);
  top: var(--y,50%);
  padding: .45em .8em;
  border-radius: 999px;
  font-size: .75em;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
  background: var(--c1);
  box-shadow: 0 8px 20px -8px var(--c1);
  transform: translate(-50%,-160%) scale(.6);
  opacity: 0;
  pointer-events: none;
  transition: transform calc(0.3s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.2s / var(--k)),left .08s linear,top .08s linear;
}

.uv-tf:hover span {
  transform: translate(-50%,-160%) scale(1);
  opacity: 1;
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  el.addEventListener("pointermove",e=>{const r=el.getBoundingClientRect();el.style.setProperty("--x",e.clientX-r.left+"px");el.style.setProperty("--y",e.clientY-r.top+"px")})
}

export default function TipFollow() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-tf">Move your mouse here<span>You are here</span></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
