# Spotlight reveal

Subtle web animation sketch from [https://mighil.com/animations](https://mighil.com/animations).

- **Live demo:** https://mighil.com/animations/spotlight-reveal
- **Standalone HTML:** https://mighil.com/animations/spotlight-reveal?download=1
- **This file:** https://mighil.com/animations/spotlight-reveal/spotlight-reveal.md
- **Technique:** `mask`

## What it does

A soft spotlight follows the cursor over the text.

## Instructions for AI / coding agents

Implement this micro-interaction in the user's stack (vanilla HTML, React, Vue, Svelte, etc.).

1. Use the **HTML** as the DOM structure (adapt JSX/templates as needed; keep class names and ids).
2. Include the **Theme** CSS (or map the same variables into the host design system). It switches light/dark with `prefers-color-scheme`.
3. Apply the **CSS** as-is when possible. It uses `var(--text-color)`, `var(--heading-color)`, `var(--background-color)`, etc. from the theme so both modes work.
4. Run the **JavaScript** after the markup mounts. Prefer `DOMContentLoaded` or a framework `useEffect` / `onMount`.
5. Keep motion respectful of `prefers-reduced-motion` if the snippet already checks it.
6. Do not depend on mighil.com runtime or fonts. Theme variables are enough for color.
7. If porting to a component, expose the interactive root via a ref and preserve accessibility attributes (`aria-*`, `role`, `button` types).

## Theme (auto light / dark)

```css
/* Auto light / dark — follows prefers-color-scheme */
:root{
  color-scheme: light dark;
  --text-color: hsl(0, 0%, 18%);
  --heading-color: hsl(0, 0%, 18%);
  --background-color: hsl(0, 0%, 99%);
  --bg-color: hsl(0, 0%, 99%);
  --link-color: hsl(0, 0%, 18%);
  --visited-color: hsl(0, 0%, 18%);
  --blockquote-color: hsl(0, 0%, 18%);
  --code-bg-color: hsl(0, 0%, 95%);
  --code-color: hsl(0, 0%, 18%);
  --sub-color: hsl(0, 0%, 29%);
}
@media (prefers-color-scheme: dark){
:root{
  --text-color: hsl(35, 25%, 85%);
  --heading-color: hsl(35.2, 32.6%, 82.5%);
  --background-color: hsl(60, 2.2%, 8.8%);
  --bg-color: hsl(60, 2.2%, 8.8%);
  --link-color: hsl(34.7, 55.3%, 79.8%);
  --visited-color: hsla(34.7, 55.3%, 79.8%, 0.85);
  --blockquote-color: hsl(35, 30%, 75%);
  --code-bg-color: hsl(30, 5%, 7.8%);
  --code-color: limegreen;
  --sub-color: hsla(34.7, 24.7%, 84.9%, 0.78);
}
}
```

## HTML

```html
<div class="spot" id="spot">
        <div class="spot-dim">Motion should explain state, not decorate it. Move your pointer to read.</div>
        <div class="spot-lit" id="spot-lit">Motion should explain state, not decorate it. Move your pointer to read.</div>
      </div>
```

## CSS

```css
.spot{
  width:min(100%,320px);padding:18px 16px;border-radius:10px;position:relative;overflow:hidden;
  border:1px solid color-mix(in srgb,var(--text-color) 10%,transparent);
  font-size:.95rem;line-height:1.55;cursor:crosshair;
}

.spot-dim{color:color-mix(in srgb,var(--text-color) 30%,transparent)}

.spot-lit{
  position:absolute;inset:0;padding:18px 16px;pointer-events:none;color:var(--text-color);
  -webkit-mask-image:radial-gradient(circle 58px at var(--x,50%) var(--y,40%),#000 20%,transparent 70%);
  mask-image:radial-gradient(circle 58px at var(--x,50%) var(--y,40%),#000 20%,transparent 70%);
}
```

## JavaScript

```js
// Spotlight
  const spot = document.getElementById('spot');
  const spotLit = document.getElementById('spot-lit');
  if (spot && spotLit) {
    const move = (e) => {
      const r = spot.getBoundingClientRect();
      const x = ((e.clientX - r.left) / r.width) * 100;
      const y = ((e.clientY - r.top) / r.height) * 100;
      spotLit.style.setProperty('--x', x + '%');
      spotLit.style.setProperty('--y', y + '%');
    };
    spot.addEventListener('pointermove', move);
    spot.addEventListener('pointerenter', move);
  }
```

---

_Source: https://mighil.com/animations/spotlight-reveal_
