Skip to content

Spotlight Gradient

A copy-paste animated gradients component in pure HTML, CSS & vanilla JS. Zero dependencies, framework-agnostic, MIT-licensed.

Animated GradientsHTMLJavaScriptCSSany framework

Copy into your project

HTML
<!-- Spotlight Gradient -->
<div class="nuda-gradient-spotlight" role="img" aria-label="Cursor-following spotlight gradient">
  <span class="nuda-gradient-spotlight__label">Move your cursor</span>
</div>
JavaScript
/* Spotlight Gradient — vanilla JS
   Updates CSS custom properties from the pointer position. */

(function () {
  document.querySelectorAll(".nuda-gradient-spotlight").forEach(function (el) {
    el.addEventListener("pointermove", function (e) {
      var r = el.getBoundingClientRect();
      el.style.setProperty("--gradient-spotlight-x", ((e.clientX - r.left) / r.width) * 100 + "%");
      el.style.setProperty("--gradient-spotlight-y", ((e.clientY - r.top) / r.height) * 100 + "%");
    });
  });
})();
CSS
.nuda-gradient-spotlight {
  --gradient-spotlight-x: 50%;
  --gradient-spotlight-y: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 240px;
  height: 140px;
  border-radius: 14px;
  background: #09090b;
  border: 1px solid #27272a;
  overflow: hidden;
  cursor: crosshair;
}

.nuda-gradient-spotlight::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(160px circle at var(--gradient-spotlight-x) var(--gradient-spotlight-y),rgba(228,255,84,.45),transparent 60%);
  transition: background .08s linear;
}

.nuda-gradient-spotlight__label {
  position: relative;
  color: #a1a1aa;
  font: 600 14px/1 system-ui,sans-serif;
  pointer-events: none;
}

@media (prefers-reduced-motion:reduce) {
  .nuda-gradient-spotlight::before {
    transition: none;
  }
}

How to use Spotlight Gradient

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More animated gradients components

← Browse all NudaUI components