VibeFX
Live preview · fully interactive

The prompt

Build a sliding pill nav.

## Look
Nav background #12121a, radius 999px, padding 4px. Links 14px, inactive #8a8a99, active #f2f2f7, padding 8px 14px. The pill is #7c6cff, radius 999px. Page #08080d. Labels: Build, Motion, Price.

## Behavior
On click, set the pill width to the link width and translateX to the link’s offset inside the nav. Prevent navigation.

## Design tokens
- Pill #7c6cff; nav #12121a; inactive #8a8a99; active #f2f2f7; page #08080d.

## Motion
- Transition transform and width 0.35s, easing cubic-bezier(0.16, 1, 0.3, 1).

## 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; padding: 16px; } nav { position: relative; display: flex; flex-wrap: wrap; gap: 4px; background: #12121a; border-radius: 999px; padding: 4px; } a { position: relative; z-index: 1; color: #8a8a99; text-decoration: none; padding: 8px 14px; font-size: 14px; } a.on { color: #f2f2f7; } i { position: absolute; top: 4px; bottom: 4px; left: 4px; border-radius: 999px; background: #7c6cff; transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), width 0.35s cubic-bezier(0.16, 1, 0.3, 1); }
  @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"><i id="pill"></i><a class="on" href="#build">Build</a><a href="#motion">Motion</a><a href="#price">Price</a></nav></main>

<script>

  var pill = document.getElementById("pill");
  var links = document.querySelectorAll("#nav a");
  function move(link) {
    var nav = document.getElementById("nav").getBoundingClientRect();
    var r = link.getBoundingClientRect();
    pill.style.width = r.width + "px";
    pill.style.transform = "translateX(" + (r.left - nav.left - 4) + "px)";
    links.forEach(function (a) { a.classList.toggle("on", a === link); });
  }
  links.forEach(function (a) { a.addEventListener("click", function (e) { e.preventDefault(); move(a); }); });
  move(links[0]);
</script>
</body>
</html>

About this effect

A highlight pill translates to the clicked link over 0.35s. The links stay in one row and wrap on a 390px screen.

Similar effects