VibeFX
Live preview · fully interactive

The prompt

Build a sliding underline nav.

## Look
Links 15px #f2f2f7, gap 18px. Underline 2px #c4b5fd. Labels Library, Pricing, Skills. Page #08080d.

## Behavior
On pointer enter, set the line width and translateX to that link. On leave, return to the first link.

## Design tokens
- Line #c4b5fd; text #f2f2f7; page #08080d.

## Motion
- Transition width and transform 0.3s ease.

## Constraints
- Single self-contained HTML file. No libraries.
- Honor prefers-reduced-motion: reduce by skipping the loop and leaving a readable static frame
- Readable at 390px width with no horizontal page scroll

The code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  html, body { min-height: 100%; }
  body {
    background: #08080d; color: #f2f2f7; font-family: Inter, system-ui, sans-serif;
    min-height: 100vh; overflow: hidden;
  }
  .hint { position: absolute; left: 16px; top: 16px; z-index: 5; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #8a8a99; }
  main { min-height: 100vh; display: grid; place-items: center; } nav { position: relative; display: flex; gap: 18px; } a { color: #f2f2f7; text-decoration: none; font-size: 15px; padding: 8px 0; } u { position: absolute; left: 0; bottom: 0; height: 2px; width: 20px; background: #c4b5fd; text-decoration: none; transition: transform 0.3s ease, width 0.3s ease; }
  @media (max-width: 420px) {
    .hint { font-size: 10px; letter-spacing: 0.08em; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  }
</style>
</head>
<body>
<main><nav id="nav"><a href="#one">Library</a><a href="#two">Pricing</a><a href="#three">Skills</a><u id="line"></u></nav></main>

<script>

  var line = document.getElementById("line");
  var nav = document.getElementById("nav");
  var links = nav.querySelectorAll("a");
  function place(link) {
    var base = nav.getBoundingClientRect();
    var r = link.getBoundingClientRect();
    line.style.width = r.width + "px";
    line.style.transform = "translateX(" + (r.left - base.left) + "px)";
  }
  links.forEach(function (a) {
    a.addEventListener("pointerenter", function () { place(a); });
  });
  nav.addEventListener("pointerleave", function () { place(links[0]); });
  place(links[0]);
</script>
</body>
</html>

About this effect

A 2px line translates and resizes to the hovered item over 0.3s. Leaving the nav returns it to the current link.

Similar effects