CSS Hover Effects and Magnetic Buttons

Updated 2026-10-15. 15 effects.

Good hover effects confirm that something is clickable without getting in the way. Most need only CSS transitions on transform and opacity under :hover and :focus-visible. A magnetic button adds a few lines of script that shift it slightly toward the pointer and spring it back when the pointer leaves.

Match the effect to the job. Primary calls to action can carry the most motion, such as a magnetic pull or a colour fill, because there is usually one per screen. Navigation links want something quieter like an underline that sweeps in, and cards in a grid suit a small lift so the whole grid does not shimmer at once.

Every effect also runs on keyboard focus, because a hover state that only a mouse can see leaves keyboard users guessing. On touch screens the hover styles are kept behind a hover: hover media query so a tap does not leave a button stuck in its hovered look.

Compare them

EffectBuilt withSize (gzipped)Running costBrowser support
Arrow Button Where a Twin Arrow Slides InCSS only1.6 KBTwo small SVG arrows per button move by transform; the only script pauses the loop when off screen.All current browsers
Book Cover Tilt With Spine and Page DepthCSS and a small script3.1 KBOne frame loop writes a single rotation and moves one highlight layer, and it stops once the book settles or scrolls out of view.All current browsers
Button Fill Rising From the Pointer Entry PointCSS and a small script1.9 KBA scaled circle and a label crossfade per button; the script only places the circle on enter and leave.All current browsers
Concert Ticket Tilt With Foil Seal and StubCSS and a small script3 KBWhile the ticket moves, each frame writes three transforms and one opacity; the loop ends once it settles and stays off while the section is out of view.All current browsers
Image Card Zoom With Caption Sliding UpCSS only1.7 KBA slow scale on each photo plus a caption translate and two opacity fades, with no script at all.All current browsers
Link Underline Sweeping In From the Entry SideCSS and a small script1.7 KBEach line is one scaled pseudo-element; the script only sets a transform origin on enter and leave plus a slow timer for the demo.All current browsers
Magnetic Icon Buttons in a Floating ToolbarCSS and a small script2.3 KBA single frame loop reads five button positions and writes five transforms, paused when the bar is off screen.All current browsers
Magnetic Pill Button With Parallax LabelCSS and a small script1.7 KBOne small frame loop writes two transforms and stops whenever the section scrolls out of view.All current browsers
Magnetic Social Icon RowCSS and a small script2.5 KBFive small transforms per frame while visible, measured from five bounding boxes; the loop stops off screen.All current browsers
Product Cards Lift With Shadow and Quick AddCSS only2.4 KBHover changes only transforms and the opacity of a pre-painted shadow layer; a small timer runs the demo until someone interacts.All current browsers
Property Listing Card Tilt With Floating LayersCSS and a small script2.8 KBA frame loop writes one rotation and one highlight transform while the card is moving, then stops until the next pointer or focus change.All current browsers
Service List With a Photo That Follows the PointerCSS and a small script2.6 KBOne frame loop moves a single preview by transform and stops, along with the demo timer, when the list is off screen.All current browsers
Split Colour Button With a Sliding Second ColourCSS only1.8 KBTwo transforms per button on hover; a short timer only runs the demo until someone interacts.All current browsers
Text Roll Button With Letters Rolling UpCSS only1.5 KBEach letter is one translated span with its copy drawn by a pseudo-element; the only script pauses the loop off screen.All current browsers
Tilt Card With a Moving Glare LayerCSS and a small script2.2 KBA frame loop writes two rotations, one translate and one opacity, and it stops while the section is off screen.All current browsers

Arrow Button Where a Twin Arrow Slides In

Two navy calls to action for a sailing school, a solid pill with a round arrow chip and a plain text link, where the arrow shoots out to the right and an identical twin glides in from the left. Because both arrows match, the loop on the first button resets invisibly. It suits any forward action such as booking or reading on.

<section class="w3arr">
  <div class="w3arr-wrap">
    <p class="w3arr-kicker">Harbour Tide Sailing School</p>
    <h2 class="w3arr-title">Learn to sail a dinghy in four Saturday mornings.</h2>
    <p class="w3arr-copy">Small boats, two learners per instructor, and a warm clubhouse to dry off in. Lifejackets and wetsuits are on us.</p>
    <div class="w3arr-row">
      <a class="w3arr-btn w3arr-solid w3arr-demo" href="#">Choose a start date
        <span class="w3arr-box w3arr-chip"><svg class="w3arr-a" aria-hidden="true" viewBox="0 0 20 20"><path d="M4 10h12M11 5l5 5-5 5"/></svg><svg class="w3arr-b" aria-hidden="true" viewBox="0 0 20 20"><path d="M4 10h12M11 5l5 5-5 5"/></svg></span>
      </a>
      <a class="w3arr-btn w3arr-text" href="#">See what a lesson covers
        <span class="w3arr-box"><svg class="w3arr-a" aria-hidden="true" viewBox="0 0 20 20"><path d="M4 10h12M11 5l5 5-5 5"/></svg><svg class="w3arr-b" aria-hidden="true" viewBox="0 0 20 20"><path d="M4 10h12M11 5l5 5-5 5"/></svg></span>
      </a>
    </div>
  </div>
</section>
<style>
  /* Change these: navy background, light colour, swap speed, and the idle loop length. */
  .w3arr { --w3arr-navy: #0f1d33; --w3arr-light: #e8edf5; --w3arr-speed: .45s; --w3arr-loop: 2.8s; }
  .w3arr { background: var(--w3arr-navy); color: var(--w3arr-light); padding: 80px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3arr-wrap { max-width: 48rem; margin: 0 auto; }
  .w3arr-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .25em; text-transform: uppercase; color: #9fb3d1; }
  .w3arr-title { margin: 16px 0 0; font-size: clamp(30px, 5vw, 48px); font-weight: 600; line-height: 1.15; letter-spacing: -.02em; }
  .w3arr-copy { margin: 20px 0 0; max-width: 36rem; font-size: 16px; line-height: 1.65; color: #b9c6da; }
  .w3arr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 20px 32px; margin-top: 40px; }
  .w3arr-btn { display: inline-flex; align-items: center; font-size: 16px; font-weight: 600; text-decoration: none; }
  .w3arr-solid { gap: 16px; height: 56px; padding: 0 8px 0 28px; border-radius: 999px; background: var(--w3arr-light); color: var(--w3arr-navy); }
  .w3arr-text { gap: 8px; height: 48px; color: var(--w3arr-light); }
  .w3arr-btn:focus-visible { outline: 2px solid var(--w3arr-light); outline-offset: 4px; }
  .w3arr-box { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 20px; height: 20px; }
  .w3arr-chip { width: 40px; height: 40px; border-radius: 50%; background: var(--w3arr-navy); color: var(--w3arr-light); }
  .w3arr-box svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--w3arr-speed) cubic-bezier(.65,0,.35,1); }
  .w3arr-b { position: absolute; inset: 0; margin: auto; transform: translateX(-160%); }
  .w3arr-btn:focus-visible .w3arr-a { transform: translateX(160%); }
  .w3arr-btn:focus-visible .w3arr-b { transform: none; }
  @media (hover: hover) and (pointer: fine) {
    .w3arr-btn:hover .w3arr-a { transform: translateX(160%); }
    .w3arr-btn:hover .w3arr-b { transform: none; }
  }
  /* idle demo on the first button: swap, then reset while both arrows look identical */
  @keyframes w3arr-out { 0%, 45% { transform: none; } 62% { transform: translateX(160%); } 62.1%, 100% { transform: none; } }
  @keyframes w3arr-in { 0%, 45% { transform: translateX(-160%); } 62% { transform: none; } 62.1%, 100% { transform: translateX(-160%); } }
  .w3arr-demo .w3arr-a { animation: w3arr-out var(--w3arr-loop) cubic-bezier(.65,0,.35,1) infinite; }
  .w3arr-demo .w3arr-b { animation: w3arr-in var(--w3arr-loop) cubic-bezier(.65,0,.35,1) infinite; }
  .w3arr:hover .w3arr-demo svg, .w3arr:focus-within .w3arr-demo svg { animation: none; }
  .w3arr[data-paused] svg { animation-play-state: paused; }
  @media (prefers-reduced-motion: reduce) {
    .w3arr-demo .w3arr-a, .w3arr-demo .w3arr-b { animation: none; }
    .w3arr-box svg { transition: none; }
  }
</style>
<script>
  (function () {
    /* only pauses the idle loop while the section is off screen */
    var root = document.querySelector(".w3arr");
    if (!root) return;
    new IntersectionObserver(function (en) { root.toggleAttribute("data-paused", !en[0].isIntersecting); }).observe(root);
  })();
</script>

With reduced motion: The arrows stay put, the idle loop is off, and hover simply keeps the arrow in place.

Running cost: Two small SVG arrows per button move by transform; the only script pauses the loop when off screen.

  • Change `--w3arr-speed` for the swap and `--w3arr-loop` for the idle cycle on the first button.
  • Recolour with `--w3arr-navy` and `--w3arr-light`, or swap the arrow path for a chevron.
  • Remove the `w3arr-demo` class to turn the idle loop off.

Book Cover Tilt With Spine and Page Depth

A hardback built from real 3D faces: a cloth cover, a spine with its title, a block of page edges and a paper band that floats a few pixels above the cover. It turns toward the pointer while keeping its spine in view, so it reads as an object on a shelf. Suits a publisher, bookshop or author page next to the blurb.

<section class="w4bkc">
  <div class="w4bkc-wrap">
    <div class="w4bkc-stage">
      <span class="w4bkc-floor" aria-hidden="true"></span>
      <a href="#" class="w4bkc-book" aria-label="The Salt Marsh Year by Edie Calloway, view the book">
        <span class="w4bkc-back" aria-hidden="true"></span>
        <span class="w4bkc-spine" aria-hidden="true"><span>The Salt Marsh Year · Calloway</span></span>
        <span class="w4bkc-pages" aria-hidden="true"></span>
        <span class="w4bkc-cover" aria-hidden="true">
          <span class="w4bkc-face">
            <span class="w4bkc-series">Fernhill Press</span>
            <span class="w4bkc-name">The Salt Marsh Year</span>
            <svg class="w4bkc-art" viewBox="0 0 180 92" fill="none" stroke="#f3ead8" stroke-width="1.2" stroke-linecap="round">
              <circle cx="132" cy="30" r="16"/>
              <path d="M0 78 Q45 70 90 78 T180 76"/>
              <path d="M0 88 Q45 82 90 88 T180 86" opacity=".6"/>
              <path d="M22 78 L18 44 M28 78 L30 50 M34 78 L40 40 M150 76 L146 52 M156 76 L160 46"/>
            </svg>
            <span class="w4bkc-author">Edie Calloway</span>
          </span>
          <span class="w4bkc-hl"></span>
        </span>
        <span class="w4bkc-band" aria-hidden="true">A year of tides and weather</span>
        <span class="w4bkc-ring" aria-hidden="true"></span>
      </a>
    </div>
    <div>
      <p class="w4bkc-kicker">Fernhill Press · Autumn list</p>
      <h2 class="w4bkc-title">The Salt Marsh Year</h2>
      <p class="w4bkc-copy">Edie Calloway walked the same mile of estuary every morning for twelve months and wrote down the birds, the mud and the light. This is that notebook, set in type.</p>
      <ul class="w4bkc-facts">
        <li><b>Hardback</b>, cloth spine</li>
        <li><b>312</b> pages</li>
        <li><b>£18</b></li>
      </ul>
      <a href="#" class="w4bkc-cta">Read the first chapter</a>
    </div>
  </div>
</section>
<style>
  /* Change these: --w4bkc-paper (page), --w4bkc-cover (cloth colour), --w4bkc-thick (how thick the book is). */
.w4bkc { --w4bkc-paper: #efe6d6; --w4bkc-cover: #24433d; --w4bkc-ink: #2a2520; --w4bkc-cream: #f3ead8; --w4bkc-thick: 36px;
    background: var(--w4bkc-paper); color: var(--w4bkc-ink); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w4bkc-wrap { max-width: 60rem; margin: 0 auto; display: grid; gap: 56px; align-items: center; }
  @media (min-width: 768px) { .w4bkc-wrap { grid-template-columns: 1fr 1fr; } }
  .w4bkc-stage { position: relative; display: flex; justify-content: center; padding: 10px 0 34px; perspective: 1100px; touch-action: pan-y; }
  .w4bkc-floor { position: absolute; left: 50%; bottom: 14px; width: 260px; height: 34px; margin-left: -130px; border-radius: 50%;
    background: radial-gradient(closest-side, rgba(60, 40, 20, .32), rgba(60, 40, 20, 0)); }
  .w4bkc-book { position: relative; display: block; width: 236px; height: 340px; transform-style: preserve-3d; transform: rotateY(24deg);
    color: inherit; text-decoration: none; outline: none; will-change: transform; }
  .w4bkc-ring { position: absolute; inset: -10px; border: 3px solid #24433d; border-radius: 10px; opacity: 0; transform: translateZ(calc(var(--w4bkc-thick) / 2 + 12px)); pointer-events: none; }
  .w4bkc-book:focus-visible .w4bkc-ring { opacity: 1; }
  .w4bkc-cover, .w4bkc-back { position: absolute; inset: 0; border-radius: 2px 6px 6px 2px; }
  .w4bkc-cover { transform: translateZ(calc(var(--w4bkc-thick) / 2)); overflow: hidden; background: var(--w4bkc-cover); color: var(--w4bkc-cream);
    box-shadow: inset 6px 0 10px -4px rgba(0, 0, 0, .45); }
  .w4bkc-back { transform: translateZ(calc(var(--w4bkc-thick) / -2)); background: #1b322d; box-shadow: 18px 26px 40px -10px rgba(50, 30, 10, .45); }
  .w4bkc-spine { position: absolute; left: 0; top: 0; width: var(--w4bkc-thick); height: 100%; transform-origin: left center;
    transform: translateZ(calc(var(--w4bkc-thick) / -2)) rotateY(-90deg); background: linear-gradient(90deg, #1a302b, #2c5049 45%, #1d3631);
    display: flex; align-items: center; justify-content: center; }
  .w4bkc-spine span { writing-mode: vertical-rl; transform: rotate(180deg); font-family: Georgia, serif; font-size: 12px; letter-spacing: .14em; color: var(--w4bkc-cream); white-space: nowrap; }
  .w4bkc-pages { position: absolute; right: 0; top: 3px; width: calc(var(--w4bkc-thick) - 4px); height: calc(100% - 6px); transform-origin: right center;
    transform: translateZ(calc(var(--w4bkc-thick) / -2 + 2px)) rotateY(90deg); background: repeating-linear-gradient(90deg, #f6f0e2 0 2px, #ddd2bd 2px 3px); }
  .w4bkc-face { position: absolute; inset: 14px; border: 1px solid rgba(243, 234, 216, .45); display: flex; flex-direction: column; padding: 22px 18px 58px; }
  .w4bkc-series { font-size: 10px; letter-spacing: .28em; text-transform: uppercase; opacity: .8; }
  .w4bkc-name { margin-top: 18px; font-family: Georgia, "Times New Roman", serif; font-size: 34px; line-height: 1.02; }
  .w4bkc-art { margin-top: auto; width: 100%; height: 76px; }
  .w4bkc-author { margin-top: 10px; font-size: 11px; letter-spacing: .24em; text-transform: uppercase; }
  .w4bkc-hl { position: absolute; inset: -60%; pointer-events: none; opacity: .2;
    background: radial-gradient(circle at 50% 50%, rgba(255, 248, 230, .5), rgba(255, 248, 230, 0) 38%); }
  .w4bkc-band { position: absolute; left: -2px; right: -4px; bottom: 30px; height: 40px; transform: translateZ(calc(var(--w4bkc-thick) / 2 + 9px));
    background: #c9733f; color: #fff7ec; display: flex; align-items: center; justify-content: center; font-size: 11px; letter-spacing: .2em; text-transform: uppercase;
    box-shadow: 0 10px 14px -8px rgba(0, 0, 0, .5); }
  .w4bkc-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: #6b5a44; }
  .w4bkc-title { margin: 14px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(32px, 4.4vw, 46px); font-weight: 400; line-height: 1.08; }
  .w4bkc-copy { margin: 18px 0 0; max-width: 27rem; font-size: 16px; line-height: 1.65; color: #4a4034; }
  .w4bkc-facts { margin: 22px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 14px; color: #4a4034; }
  .w4bkc-facts b { color: var(--w4bkc-ink); font-weight: 600; }
  .w4bkc-cta { display: inline-flex; align-items: center; min-height: 46px; margin-top: 28px; padding: 0 22px; border-radius: 999px; background: var(--w4bkc-ink);
    color: var(--w4bkc-paper); font-size: 15px; font-weight: 600; text-decoration: none; }
  .w4bkc-cta:hover { background: #24433d; }
  .w4bkc-cta:focus-visible { outline: 3px solid #24433d; outline-offset: 3px; }
  @media (prefers-reduced-motion: reduce) { .w4bkc-book { transform: rotateX(-4deg) rotateY(26deg) !important; will-change: auto; } .w4bkc-hl { transform: translate(-12%, -16%) !important; } }
</style>
<script>
(function () {
  /* Change these: MAX tilt in degrees, BASE resting turn that shows the spine, EASE follow speed. */
  var MAX = 13, BASE = 24, EASE = 0.08;
  var root = document.querySelector(".w4bkc");
  if (!root || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
  var card = root.querySelector(".w4bkc-book"), hl = root.querySelector(".w4bkc-hl");
  var tx = 0, ty = 0, x = 0, y = 0, idle = true, f = 0, vis = true, tm = 0;
  function cl(v) { return Math.max(-1, Math.min(1, v)); }
  function go() { if (!f && vis) f = requestAnimationFrame(tick); }
  function aim(e) {
    var r = card.getBoundingClientRect();
    tx = cl((e.clientX - r.left) / r.width * 2 - 1); ty = cl((e.clientY - r.top) / r.height * 2 - 1);
    idle = false; go();
  }
  function flat() { tx = ty = 0; go(); }
  function tick(now) {
    f = 0;
    /* idle demo: a slow sway until a real pointer, finger or focus arrives */
    if (idle) { tx = Math.sin(now / 2300) * 0.7; ty = Math.sin(now / 1700 + 1) * 0.45; }
    x += (tx - x) * EASE; y += (ty - y) * EASE;
    card.style.transform = "rotateX(" + (-y * MAX).toFixed(2) + "deg) rotateY(" + (BASE + x * MAX).toFixed(2) + "deg)";
    hl.style.transform = "translate(" + (x * 22).toFixed(1) + "%," + (y * 22).toFixed(1) + "%)";
    hl.style.opacity = (0.18 + 0.6 * Math.min(1, Math.hypot(x, y))).toFixed(3);
    if (idle || Math.abs(tx - x) + Math.abs(ty - y) > 0.002) go();
  }
  root.addEventListener("pointermove", function (e) { if (e.pointerType == "mouse" || e.buttons) aim(e); });
  root.addEventListener("pointerdown", function (e) { clearTimeout(tm); aim(e); });
  root.addEventListener("pointerup", function (e) { if (e.pointerType != "mouse") tm = setTimeout(flat, 700); });
  root.addEventListener("pointerleave", function (e) { if (e.pointerType == "mouse") flat(); });
  root.addEventListener("pointercancel", flat);
  card.addEventListener("focus", function () { idle = false; tx = 0.5; ty = -0.4; go(); });
  card.addEventListener("blur", flat);
  new IntersectionObserver(function (en) {
    vis = en[0].isIntersecting;
    if (vis) go(); else { cancelAnimationFrame(f); f = 0; }
  }).observe(root);
  go();
})();
</script>

With reduced motion: The book stands still at a fixed three-quarter turn with its spine and paper band in view and the highlight resting near the top corner.

Running cost: One frame loop writes a single rotation and moves one highlight layer, and it stops once the book settles or scrolls out of view.

  • Change `--w4bkc-thick` to make the book thinner or chunkier; the spine, page block and band all follow it.
  • Set `BASE_TURN` (React) or `BASE` (HTML) for how far the book turns at rest, and `MAX_TILT` for the extra turn toward the pointer.
  • Swap `--w4bkc-cover` and the band colour `#c9733f` to match a real jacket.

Button Fill Rising From the Pointer Entry Point

Three outline pill buttons for a dry-garden designer, where a terracotta circle grows out of the exact point the mouse crossed the border and shrinks back toward wherever it leaves. Keyboard focus fills from the centre. The first button fills and empties from a new edge every couple of seconds so the effect reads in a still preview.

<section class="w3fil">
  <div class="w3fil-wrap">
    <p class="w3fil-kicker">Redclay Gardens</p>
    <h2 class="w3fil-title">Dry gardens that look after themselves.</h2>
    <p class="w3fil-copy">Gravel beds, grasses and Mediterranean shrubs, planned for clay soil and hot summers, then left to settle.</p>
    <div class="w3fil-row">
      <a class="w3fil-btn" href="#"><span class="w3fil-dot" aria-hidden="true"></span><span class="w3fil-off">Book a garden visit</span><span class="w3fil-on" aria-hidden="true">Book a garden visit</span></a>
      <a class="w3fil-btn" href="#"><span class="w3fil-dot" aria-hidden="true"></span><span class="w3fil-off">See planting plans</span><span class="w3fil-on" aria-hidden="true">See planting plans</span></a>
      <a class="w3fil-btn" href="#"><span class="w3fil-dot" aria-hidden="true"></span><span class="w3fil-off">Ask about upkeep</span><span class="w3fil-on" aria-hidden="true">Ask about upkeep</span></a>
    </div>
  </div>
</section>
<style>
  /* Change these: background, fill colour, text colour on the fill, fill speed. */
  .w3fil { --w3fil-bg: #f6ebe1; --w3fil-fill: #a4452b; --w3fil-on: #fdf6ef; --w3fil-speed: .55s; }
  .w3fil { background: var(--w3fil-bg); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3fil-wrap { max-width: 48rem; margin: 0 auto; text-align: center; }
  .w3fil-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .25em; text-transform: uppercase; color: #8a3a24; }
  .w3fil-title { margin: 16px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(30px, 5vw, 48px); font-weight: 400; line-height: 1.15; color: #3a1d14; }
  .w3fil-copy { margin: 20px auto 0; max-width: 32rem; font-size: 16px; line-height: 1.65; color: #5e4136; }
  .w3fil-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 40px; }
  .w3fil-btn { position: relative; isolation: isolate; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; height: 56px; padding: 0 28px; border: 2px solid var(--w3fil-fill); border-radius: 999px; color: #5a2414; font-size: 16px; font-weight: 600; text-decoration: none; }
  @media (max-width: 639px) { .w3fil-row { flex-direction: column; align-items: center; } .w3fil-btn { width: 256px; padding: 0; } }
  .w3fil-dot { position: absolute; left: 50%; top: 50%; z-index: -1; width: 230%; aspect-ratio: 1; border-radius: 50%; background: var(--w3fil-fill); transform: translate(-50%, -50%) scale(0); transition: transform var(--w3fil-speed) cubic-bezier(.3,.7,.2,1); }
  .w3fil-on { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--w3fil-on); opacity: 0; transition: opacity .3s ease; }
  .w3fil-off { transition: opacity .3s ease; }
  .w3fil-btn[data-on] .w3fil-dot, .w3fil-btn:focus-visible .w3fil-dot { transform: translate(-50%, -50%) scale(1); }
  .w3fil-btn[data-on] .w3fil-on, .w3fil-btn:focus-visible .w3fil-on { opacity: 1; }
  .w3fil-btn[data-on] .w3fil-off, .w3fil-btn:focus-visible .w3fil-off { opacity: 0; }
  .w3fil-btn:focus-visible { outline: 2px solid #5a2414; outline-offset: 4px; }
  @media (hover: hover) and (pointer: fine) {
    .w3fil-btn:hover .w3fil-dot { transform: translate(-50%, -50%) scale(1); }
    .w3fil-btn:hover .w3fil-on { opacity: 1; }
    .w3fil-btn:hover .w3fil-off { opacity: 0; }
  }
  @media (prefers-reduced-motion: reduce) { .w3fil-dot, .w3fil-on, .w3fil-off { transition: none; } }
</style>
<script>
  (function () {
    /* Change this: ms between idle fills on the first button. */
    var DEMO_EVERY = 1800;
    var root = document.querySelector(".w3fil");
    if (!root) return;
    var btns = [].slice.call(root.querySelectorAll(".w3fil-btn"));
    /* puts the circle where the pointer crossed the edge, then CSS scales it */
    function place(b, x, y) { var d = b.querySelector(".w3fil-dot"); d.style.left = x + "px"; d.style.top = y + "px"; }
    function at(e) { var b = e.currentTarget, r = b.getBoundingClientRect(); place(b, e.clientX - r.left, e.clientY - r.top); return b; }
    btns.forEach(function (b) {
      b.addEventListener("pointerenter", function (e) { if (e.pointerType === "mouse") at(e).setAttribute("data-on", ""); });
      b.addEventListener("pointerleave", function (e) { if (e.pointerType === "mouse") at(e).removeAttribute("data-on"); });
      b.addEventListener("focus", function () { place(b, b.offsetWidth / 2, b.offsetHeight / 2); });
    });
    var demo = btns[0], edges = [[0, .5], [.5, 0], [1, .5], [.5, 1]], n = 0, timer = 0, busy = false;
    var reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
    function step() {
      if (busy) return;
      var e = edges[n++ % 4];
      place(demo, e[0] * demo.offsetWidth, e[1] * demo.offsetHeight);
      demo.toggleAttribute("data-on");
    }
    function hold() { if (!busy) { busy = true; demo.removeAttribute("data-on"); } }
    function resume() { busy = false; }
    root.addEventListener("pointerenter", hold); root.addEventListener("focusin", hold);
    root.addEventListener("pointerleave", resume); root.addEventListener("focusout", resume);
    new IntersectionObserver(function (en) {
      clearInterval(timer);
      if (en[0].isIntersecting && !reduce) timer = setInterval(step, DEMO_EVERY);
    }).observe(root);
    if (!reduce) step();
  })();
</script>

With reduced motion: The terracotta fill and light label switch on instantly, without the growing circle or the idle demo.

Running cost: A scaled circle and a label crossfade per button; the script only places the circle on enter and leave.

  • Recolour with `--w3fil-fill` for the circle and `--w3fil-on` for the label shown on top of it.
  • Change `--w3fil-speed` for a slower bloom, or `DEMO_EVERY` for the idle rhythm.
  • Keep the circle `width` at 230% or more on wide buttons so its edge never shows in a corner.

Concert Ticket Tilt With Foil Seal and Stub

A paper concert ticket with a torn-off stub, cut notches and a round gold foil seal that stands proud of the paper. As the ticket tips toward the pointer, a bright band slides across the foil while a softer light crosses the paper, which is what sells the metal. Fits a booking confirmation, an order page or an event landing section.

<section class="w4tkt">
  <p class="w4tkt-kicker">Harbour Street Hall</p>
  <h2 class="w4tkt-title">See you on Friday, Sam.</h2>
  <p class="w4tkt-copy">Show this at the door on your phone or on paper. Doors open at half past seven and the trio starts at eight.</p>
  <div class="w4tkt-stage">
    <a href="#" class="w4tkt-card" aria-label="Ticket: Mira Okafor Trio at Harbour Street Hall, Friday 14 November, doors 19:30, row F seat 12. Open ticket">
      <span class="w4tkt-base" aria-hidden="true">
        <span class="w4tkt-hl"></span>
        <span class="w4tkt-perf"></span>
        <span class="w4tkt-notch t"></span>
        <span class="w4tkt-notch b"></span>
      </span>
      <span class="w4tkt-main" aria-hidden="true">
        <span class="w4tkt-venue">Harbour Street Hall</span>
        <span class="w4tkt-act">Mira Okafor Trio</span>
        <span class="w4tkt-sub">Two sets, interval at nine</span>
        <span class="w4tkt-when">
          <span><b>Date</b>Fri 14 Nov</span>
          <span><b>Doors</b>19:30</span>
          <span><b>Row</b>F, stalls</span>
        </span>
      </span>
      <span class="w4tkt-seal" aria-hidden="true">
        <span class="w4tkt-shine"></span>
        <svg viewBox="0 0 24 24"><path d="M9 18V6l10-2v12"/><circle cx="6.5" cy="18" r="2.5"/><circle cx="16.5" cy="16" r="2.5"/></svg>
      </span>
      <span class="w4tkt-stub" aria-hidden="true">
        <span class="w4tkt-admit">Admit one</span>
        <span class="w4tkt-seat">F12</span>
        <span class="w4tkt-bars"></span>
      </span>
    </a>
  </div>
  <a href="#" class="w4tkt-cta">Download as PDF</a>
</section>
<style>
  /* Change these: --w4tkt-bg (night blue; set the .w4tkt-notch background to the colour behind the ticket), --w4tkt-paper (ticket stock), --w4tkt-foil (seal gold). */
.w4tkt { --w4tkt-bg: #0f1b2d; --w4tkt-paper: #f4efe4; --w4tkt-ink: #14202f; --w4tkt-foil: #c9a45c;
    background: radial-gradient(80% 70% at 50% 20%, #1b2c45, var(--w4tkt-bg) 70%); color: #eef1f6; padding: 64px 18px 72px;
    font-family: ui-sans-serif, system-ui, sans-serif; text-align: center; overflow: hidden; }
  .w4tkt-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .24em; text-transform: uppercase; color: #d9c08a; }
  .w4tkt-title { margin: 12px 0 0; font-size: clamp(28px, 4vw, 40px); font-weight: 650; letter-spacing: -.02em; line-height: 1.15; }
  .w4tkt-copy { margin: 12px auto 0; max-width: 30rem; font-size: 16px; line-height: 1.6; color: #c3cbd8; }
  .w4tkt-stage { display: flex; justify-content: center; margin-top: 40px; perspective: 1000px; touch-action: pan-y; }
  .w4tkt-card { position: relative; display: grid; grid-template-columns: 1fr 112px; width: 100%; max-width: 540px; min-height: 210px; color: var(--w4tkt-ink);
    text-align: left; text-decoration: none; transform-style: preserve-3d; will-change: transform; outline: none; }
  .w4tkt-base { position: absolute; inset: 0; border-radius: 16px; overflow: hidden; background: var(--w4tkt-paper);
    box-shadow: 0 30px 50px -22px rgba(0, 0, 0, .7); }
  .w4tkt-card:focus-visible .w4tkt-base { outline: 3px solid #f4efe4; outline-offset: 6px; }
  .w4tkt-base::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(20, 32, 47, .035) 0 1px, transparent 1px 4px); }
  .w4tkt-perf { position: absolute; top: 14px; bottom: 14px; right: 112px; border-left: 2px dashed rgba(20, 32, 47, .28); }
  .w4tkt-notch { position: absolute; right: 101px; width: 22px; height: 22px; border-radius: 50%; background: #16263e; }
  .w4tkt-notch.t { top: -11px; } .w4tkt-notch.b { bottom: -11px; }
  .w4tkt-hl { position: absolute; inset: -70%; opacity: .15; pointer-events: none; background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .9), rgba(255, 255, 255, 0) 30%); }
  .w4tkt-main { position: relative; padding: 24px 24px 22px; transform: translateZ(18px); display: flex; flex-direction: column; }
  .w4tkt-venue { font-size: 11px; font-weight: 650; letter-spacing: .22em; text-transform: uppercase; color: #6a5520; }
  .w4tkt-act { margin-top: 10px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(24px, 4.6vw, 32px); line-height: 1.05; padding-right: 64px; }
  .w4tkt-sub { margin-top: 8px; font-size: 14px; color: #3b4859; }
  .w4tkt-when { margin-top: auto; padding-top: 18px; display: flex; flex-wrap: wrap; gap: 4px 20px; font-size: 13px; color: #3b4859; }
  .w4tkt-when b { display: block; font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: #6b7685; font-weight: 600; }
  .w4tkt-seal { position: absolute; right: 128px; top: 20px; width: 60px; height: 60px; border-radius: 50%; overflow: hidden; transform: translateZ(46px);
    background: radial-gradient(circle at 35% 30%, #f3dfa8, var(--w4tkt-foil) 45%, #8a6a2c); box-shadow: 0 10px 16px -8px rgba(20, 15, 5, .7);
    display: flex; align-items: center; justify-content: center; }
  .w4tkt-seal svg { position: relative; width: 30px; height: 30px; fill: none; stroke: #4a3711; stroke-width: 1.6; stroke-linecap: round; }
  .w4tkt-shine { position: absolute; inset: -40%; opacity: .5; background: linear-gradient(105deg, transparent 40%, rgba(255, 252, 238, .9) 50%, transparent 60%); }
  .w4tkt-stub { position: relative; padding: 22px 12px; transform: translateZ(26px); display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 10px; }
  .w4tkt-admit { font-size: 10px; font-weight: 650; letter-spacing: .2em; text-transform: uppercase; color: #6b7685; }
  .w4tkt-seat { font-family: ui-monospace, Menlo, monospace; font-size: 28px; font-weight: 600; }
  .w4tkt-bars { width: 72px; height: 34px; background: repeating-linear-gradient(90deg, var(--w4tkt-ink) 0 2px, transparent 2px 4px, var(--w4tkt-ink) 4px 5px, transparent 5px 8px); }
  .w4tkt-cta { display: inline-flex; align-items: center; min-height: 46px; margin-top: 40px; padding: 0 22px; border-radius: 999px; border: 1px solid rgba(244, 239, 228, .5);
    color: #f4efe4; font-size: 15px; font-weight: 600; text-decoration: none; }
  .w4tkt-cta:hover { background: rgba(244, 239, 228, .1); }
  .w4tkt-cta:focus-visible { outline: 3px solid #f4efe4; outline-offset: 3px; }
  @media (max-width: 480px) { .w4tkt-card { grid-template-columns: 1fr 88px; } .w4tkt-perf { right: 88px; } .w4tkt-notch { right: 77px; }
    .w4tkt-seal { right: 98px; width: 48px; height: 48px; } .w4tkt-act { padding-right: 46px; } .w4tkt-main { padding: 20px 16px 18px; } .w4tkt-seat { font-size: 22px; } .w4tkt-bars { width: 56px; } }
  @media (prefers-reduced-motion: reduce) { .w4tkt-card { transform: rotateX(6deg) rotateY(-5deg) !important; will-change: auto; } .w4tkt-hl, .w4tkt-shine { transform: none !important; } }
</style>
<script>
(function () {
  /* Change these: MAX tilt in degrees at the edge, EASE follow speed. */
  var MAX = 11, EASE = 0.085;
  var root = document.querySelector(".w4tkt");
  if (!root || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
  var card = root.querySelector(".w4tkt-card"), hl = root.querySelector(".w4tkt-hl"), foil = root.querySelector(".w4tkt-shine");
  var tx = 0, ty = 0, x = 0, y = 0, idle = true, f = 0, vis = true, tm = 0;
  function cl(v) { return Math.max(-1, Math.min(1, v)); }
  function go() { if (!f && vis) f = requestAnimationFrame(tick); }
  function aim(e) {
    var r = card.getBoundingClientRect();
    tx = cl((e.clientX - r.left) / r.width * 2 - 1); ty = cl((e.clientY - r.top) / r.height * 2 - 1);
    idle = false; go();
  }
  function flat() { tx = ty = 0; go(); }
  function tick(now) {
    f = 0;
    /* idle demo: a side-to-side rock so the foil seal catches the light */
    if (idle) { tx = Math.sin(now / 1900) * 0.8; ty = Math.cos(now / 2700) * 0.4; }
    x += (tx - x) * EASE; y += (ty - y) * EASE;
    card.style.transform = "rotateX(" + (-y * MAX).toFixed(2) + "deg) rotateY(" + (x * MAX).toFixed(2) + "deg)";
    hl.style.transform = "translate(" + (x * 26).toFixed(1) + "%," + (y * 20).toFixed(1) + "%)";
    hl.style.opacity = (0.1 + 0.3 * Math.min(1, Math.hypot(x, y))).toFixed(3);
    foil.style.transform = "translateX(" + (x * 45).toFixed(1) + "%)";
    if (idle || Math.abs(tx - x) + Math.abs(ty - y) > 0.002) go();
  }
  root.addEventListener("pointermove", function (e) { if (e.pointerType == "mouse" || e.buttons) aim(e); });
  root.addEventListener("pointerdown", function (e) { clearTimeout(tm); aim(e); });
  root.addEventListener("pointerup", function (e) { if (e.pointerType != "mouse") tm = setTimeout(flat, 700); });
  root.addEventListener("pointerleave", function (e) { if (e.pointerType == "mouse") flat(); });
  root.addEventListener("pointercancel", flat);
  card.addEventListener("focus", function () { idle = false; tx = 0.6; ty = 0.35; go(); });
  card.addEventListener("blur", flat);
  new IntersectionObserver(function (en) {
    vis = en[0].isIntersecting;
    if (vis) go(); else { cancelAnimationFrame(f); f = 0; }
  }).observe(root);
  go();
})();
</script>

With reduced motion: The ticket rests at one small fixed angle with the gold seal, stub and seat number in place and no moving shine.

Running cost: While the ticket moves, each frame writes three transforms and one opacity; the loop ends once it settles and stays off while the section is out of view.

  • Set `--w4tkt-bg` for the night blue, and give `.w4tkt-notch` the colour right behind the ticket so the two notches keep looking cut out.
  • Change the `translateZ(46px)` on `.w4tkt-seal` for how far the foil seal lifts off the paper.
  • Edit the venue, act, date and seat spans; the stub width is the `112px` column in `.w4tkt-card`.

Image Card Zoom With Caption Sliding Up

Tall photo cards for a set of lakeside cabins: on hover the picture eases slightly closer while the caption rises and a second line with beds and price fades in under the name. The first card rests in that state so a still preview explains itself. On phones and tablets the detail line is always shown.

<section class="w3zoo">
  <div class="w3zoo-wrap">
    <p class="w3zoo-kicker">Hollow Pine Stays</p>
    <h2 class="w3zoo-title">Three cabins, one lake each.</h2>
    <ul class="w3zoo-grid">
      <li><a class="w3zoo-card w3zoo-demo" href="#"><img class="w3zoo-img" src="https://images.pexels.com/photos/17006057/pexels-photo-17006057.jpeg?auto=compress&cs=tinysrgb&w=900" alt="Two wooden cabins on a snowy lakeshore under misty mountains, reflected in still water" loading="lazy" width="600" height="800"><span class="w3zoo-base" aria-hidden="true"></span><span class="w3zoo-shade" aria-hidden="true"></span><span class="w3zoo-cap"><span class="w3zoo-name">Lakeshore Hut</span><span class="w3zoo-detail">Sleeps 4 · wood stove · from $180 a night</span></span></a></li>
      <li><a class="w3zoo-card" href="#"><img class="w3zoo-img" src="https://images.pexels.com/photos/19499666/pexels-photo-19499666.jpeg?auto=compress&cs=tinysrgb&w=900" alt="Wooden lodges at the edge of a clear green lake surrounded by dense pine forest" loading="lazy" width="600" height="800"><span class="w3zoo-base" aria-hidden="true"></span><span class="w3zoo-shade" aria-hidden="true"></span><span class="w3zoo-cap"><span class="w3zoo-name">Green Water Lodge</span><span class="w3zoo-detail">Sleeps 6 · private jetty · from $240 a night</span></span></a></li>
      <li><a class="w3zoo-card" href="#"><img class="w3zoo-img" src="https://images.pexels.com/photos/34408249/pexels-photo-34408249.jpeg?auto=compress&cs=tinysrgb&w=900" alt="Weathered timber cottage beside a fenced meadow and a mountain lake in autumn" loading="lazy" width="600" height="800"><span class="w3zoo-base" aria-hidden="true"></span><span class="w3zoo-shade" aria-hidden="true"></span><span class="w3zoo-cap"><span class="w3zoo-name">Alm Cottage</span><span class="w3zoo-detail">Sleeps 2 · meadow terrace · from $130 a night</span></span></a></li>
    </ul>
  </div>
</section>
<style>
  /* Change these: page colour, zoom amount, how far the caption travels, zoom duration. */
  .w3zoo { --w3zoo-bg: #1d2a22; --w3zoo-zoom: 1.07; --w3zoo-rise: 30px; --w3zoo-speed: .9s; }
  .w3zoo { background: var(--w3zoo-bg); color: #eef0e8; padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3zoo-wrap { max-width: 64rem; margin: 0 auto; }
  .w3zoo-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .25em; text-transform: uppercase; color: #b7c4a8; }
  .w3zoo-title { margin: 12px 0 0; font-size: clamp(30px, 4vw, 36px); font-weight: 600; letter-spacing: -.02em; }
  .w3zoo-grid { list-style: none; margin: 40px 0 0; padding: 0; display: grid; gap: 20px; }
  @media (min-width: 640px) { .w3zoo-grid { grid-template-columns: repeat(3, 1fr); } }
  .w3zoo-card { position: relative; display: block; aspect-ratio: 3 / 4; overflow: hidden; border-radius: 16px; background: #2c3b31; color: #fff; text-decoration: none; }
  .w3zoo-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform var(--w3zoo-speed) cubic-bezier(.2,.7,.2,1); }
  .w3zoo-base { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: linear-gradient(to top, rgba(0,0,0,.7), transparent); }
  .w3zoo-shade { position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.6), rgba(0,0,0,.1) 50%, transparent); opacity: 0; transition: opacity .6s ease; }
  .w3zoo-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 20px; transform: translateY(var(--w3zoo-rise)); transition: transform .6s cubic-bezier(.2,.7,.2,1); }
  .w3zoo-name { display: block; font-size: 20px; font-weight: 600; }
  .w3zoo-detail { display: block; margin-top: 4px; font-size: 14px; color: rgba(255,255,255,.9); opacity: 0; transition: opacity .45s ease .05s; }
  .w3zoo-card:focus-visible { outline: 2px solid #eef0e8; outline-offset: 4px; }
  .w3zoo-card:focus-visible .w3zoo-img, .w3zoo-demo .w3zoo-img { transform: scale(var(--w3zoo-zoom)); }
  .w3zoo-card:focus-visible .w3zoo-shade, .w3zoo-demo .w3zoo-shade, .w3zoo-card:focus-visible .w3zoo-detail, .w3zoo-demo .w3zoo-detail { opacity: 1; }
  .w3zoo-card:focus-visible .w3zoo-cap, .w3zoo-demo .w3zoo-cap { transform: none; }
  /* the first card rests in its hovered look until the grid is hovered or focused */
  .w3zoo-grid:focus-within .w3zoo-demo:not(:focus-visible) .w3zoo-img { transform: none; }
  .w3zoo-grid:focus-within .w3zoo-demo:not(:focus-visible) .w3zoo-cap { transform: translateY(var(--w3zoo-rise)); }
  .w3zoo-grid:focus-within .w3zoo-demo:not(:focus-visible) .w3zoo-shade, .w3zoo-grid:focus-within .w3zoo-demo:not(:focus-visible) .w3zoo-detail { opacity: 0; }
  @media (hover: hover) and (pointer: fine) {
    .w3zoo-grid:hover .w3zoo-demo:not(:hover) .w3zoo-img { transform: none; }
    .w3zoo-grid:hover .w3zoo-demo:not(:hover) .w3zoo-cap { transform: translateY(var(--w3zoo-rise)); }
    .w3zoo-grid:hover .w3zoo-demo:not(:hover) .w3zoo-shade, .w3zoo-grid:hover .w3zoo-demo:not(:hover) .w3zoo-detail { opacity: 0; }
    .w3zoo-card:hover .w3zoo-img { transform: scale(var(--w3zoo-zoom)); }
    .w3zoo-card:hover .w3zoo-cap { transform: none; }
    .w3zoo-card:hover .w3zoo-shade, .w3zoo-card:hover .w3zoo-detail { opacity: 1; }
  }
  /* touch screens have no hover, so the detail line is simply shown */
  @media (hover: none), (prefers-reduced-motion: reduce) {
    .w3zoo-img, .w3zoo-cap, .w3zoo-detail, .w3zoo-shade { transition: none; }
    .w3zoo-grid .w3zoo-card .w3zoo-cap, .w3zoo-grid .w3zoo-card .w3zoo-img { transform: none; }
    .w3zoo-grid .w3zoo-card .w3zoo-detail, .w3zoo-grid .w3zoo-card .w3zoo-shade { opacity: 1; }
  }
</style>

With reduced motion: Photos hold their size and every caption shows its name and detail line from the start.

Running cost: A slow scale on each photo plus a caption translate and two opacity fades, with no script at all.

  • Set `--w3zoo-zoom` for how close the photo moves and `--w3zoo-rise` for the caption's travel.
  • Swap photos and lines in the `cabins` array, keeping a 3 by 4 frame so nothing shifts while loading.
  • Drop the `w3zoo-demo` class from the first card to start every card at rest.

Link Underline Sweeping In From the Entry Side

A bookshop footer whose links draw a rust underline that grows from whichever side the mouse came in and slides away toward the side it left by. A short script reads the entry and exit edge and swaps the transform origin. While nobody is pointing, the line walks from link to link so the footer shows what it does.

<footer class="w3und">
  <div class="w3und-wrap">
    <div>
      <h2 class="w3und-name">Marrow &amp; Quill Books</h2>
      <p class="w3und-copy">A small shop of new and secondhand books on Ferry Lane. Kettle always on.</p>
    </div>
    <nav class="w3und-nav" aria-label="Footer">
      <div><h3 class="w3und-h">Visit</h3><ul><li><a class="w3und-a" href="#">Opening hours</a></li><li><a class="w3und-a" href="#">Find the shop</a></li><li><a class="w3und-a" href="#">Reading room</a></li></ul></div>
      <div><h3 class="w3und-h">Read</h3><ul><li><a class="w3und-a" href="#">New this month</a></li><li><a class="w3und-a" href="#">Staff shelves</a></li><li><a class="w3und-a" href="#">Poetry corner</a></li></ul></div>
      <div><h3 class="w3und-h">Join</h3><ul><li><a class="w3und-a" href="#">Book club</a></li><li><a class="w3und-a" href="#">Gift cards</a></li><li><a class="w3und-a" href="#">Write to us</a></li></ul></div>
    </nav>
  </div>
</footer>
<style>
  /* Change these: paper colour, ink colour, underline colour and sweep speed. */
  .w3und { --w3und-paper: #f4efe6; --w3und-ink: #2b2620; --w3und-line: #9a3b25; --w3und-speed: .45s; }
  .w3und { background: var(--w3und-paper); color: var(--w3und-ink); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3und-wrap { max-width: 56rem; margin: 0 auto; display: grid; gap: 48px; }
  @media (min-width: 768px) { .w3und-wrap { grid-template-columns: 1.2fr 2fr; } }
  .w3und-name { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 30px; font-weight: 400; line-height: 1.2; }
  .w3und-copy { margin: 16px 0 0; max-width: 20rem; font-size: 16px; line-height: 1.65; color: #5b5248; }
  .w3und-nav { display: grid; grid-template-columns: repeat(2, 1fr); gap: 32px; }
  @media (min-width: 640px) { .w3und-nav { grid-template-columns: repeat(3, 1fr); } }
  .w3und-h { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: #6b5f52; }
  .w3und-nav ul { list-style: none; margin: 16px 0 0; padding: 0; }
  .w3und-nav li + li { margin-top: 8px; }
  .w3und-a { position: relative; display: inline-block; padding: 6px 0; color: inherit; font-size: 18px; text-decoration: none; }
  .w3und-a::after { content: ""; position: absolute; left: 0; right: 0; bottom: 4px; height: 2px; background: var(--w3und-line); transform: scaleX(0); transform-origin: var(--w3und-o, left); transition: transform var(--w3und-speed) cubic-bezier(.65,0,.35,1); }
  .w3und-a[data-on]::after, .w3und-a:focus-visible::after { transform: scaleX(1); }
  .w3und-a:focus-visible { outline: 2px solid var(--w3und-ink); outline-offset: 4px; border-radius: 2px; }
  @media (hover: hover) and (pointer: fine) { .w3und-a:hover::after { transform: scaleX(1); } }
  @media (prefers-reduced-motion: reduce) { .w3und-a::after { transition: none; } }
</style>
<script>
  (function () {
    /* Change this: ms between idle demo steps. */
    var DEMO_EVERY = 1500;
    var root = document.querySelector(".w3und");
    if (!root) return;
    var links = [].slice.call(root.querySelectorAll(".w3und-a"));
    function side(a, e) { var r = a.getBoundingClientRect(); return e.clientX < r.left + r.width / 2 ? "left" : "right"; }
    links.forEach(function (a) {
      /* the line grows from the side the pointer came in and leaves toward the side it went out */
      a.addEventListener("pointerenter", function (e) { a.style.setProperty("--w3und-o", side(a, e)); a.setAttribute("data-on", ""); });
      a.addEventListener("pointerleave", function (e) { a.style.setProperty("--w3und-o", side(a, e)); a.removeAttribute("data-on"); });
    });
    var i = 0, timer = 0, busy = false, reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
    function step() {
      if (busy) return;
      var prev = links[(i + links.length - 1) % links.length];
      prev.style.setProperty("--w3und-o", "right"); prev.removeAttribute("data-on");
      links[i].style.setProperty("--w3und-o", "left"); links[i].setAttribute("data-on", "");
      i = (i + 1) % links.length;
    }
    function hold() { if (!busy) { busy = true; links.forEach(function (a) { a.removeAttribute("data-on"); }); } }
    function resume() { busy = false; }
    root.addEventListener("pointerenter", hold); root.addEventListener("focusin", hold);
    root.addEventListener("pointerleave", resume); root.addEventListener("focusout", resume);
    new IntersectionObserver(function (en) {
      clearInterval(timer);
      if (en[0].isIntersecting && !reduce) { step(); timer = setInterval(step, DEMO_EVERY); }
    }).observe(root);
  })();
</script>

With reduced motion: Underlines appear and disappear at once with no sweep, and the idle walk through the links never starts.

Running cost: Each line is one scaled pseudo-element; the script only sets a transform origin on enter and leave plus a slow timer for the demo.

  • Recolour the line with `--w3und-line` and change its pace with `--w3und-speed`.
  • Slow or speed the idle walk through the links with `DEMO_EVERY` in milliseconds.
  • Edit the link names in the `groups` array (React) or the list items (HTML).

Magnetic Icon Buttons in a Floating Toolbar

A rounded toolbar of five outline icons sits under a field note on a cool grey page. Each icon nudges toward the mouse when it comes close, lifts onto a white disc and shows its name in a small dark tag. A pretend pointer glides along the bar at rest, so the effect is visible before anyone touches it.

<section class="w3nav">
  <div class="w3nav-card">
    <p class="w3nav-date">Thursday, 14 March</p>
    <h2 class="w3nav-title">Site visit, Larch Street</h2>
    <p class="w3nav-copy">Measure the back stairs again before ordering treads. Ask Mira about the lead time on the oak.</p>
    <div class="w3nav-lines" aria-hidden="true"><span></span><span></span></div>
    <nav class="w3nav-bar" aria-label="Workspace">
      <a class="w3nav-btn" href="#" aria-label="Notes" aria-current="page"><span class="w3nav-bg" aria-hidden="true"></span><span class="w3nav-dot" aria-hidden="true"></span><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M5 4h10l4 4v12H5z M15 4v4h4 M8 12h8 M8 16h6"/></svg><span class="w3nav-tip" aria-hidden="true">Notes</span></a>
      <a class="w3nav-btn" href="#" aria-label="Search"><span class="w3nav-bg" aria-hidden="true"></span><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M11 4a7 7 0 1 1 0 14a7 7 0 0 1 0-14z M16 16l4 4"/></svg><span class="w3nav-tip" aria-hidden="true">Search</span></a>
      <a class="w3nav-btn" href="#" aria-label="Calendar"><span class="w3nav-bg" aria-hidden="true"></span><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M4 6h16v14H4z M4 10h16 M8 3v5 M16 3v5"/></svg><span class="w3nav-tip" aria-hidden="true">Calendar</span></a>
      <a class="w3nav-btn" href="#" aria-label="Inbox"><span class="w3nav-bg" aria-hidden="true"></span><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M4 13l3-8h10l3 8v6H4z M4 13h5l1 2h4l1-2h5"/></svg><span class="w3nav-tip" aria-hidden="true">Inbox</span></a>
      <a class="w3nav-btn" href="#" aria-label="Settings"><span class="w3nav-bg" aria-hidden="true"></span><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M12 9a3 3 0 1 1 0 6a3 3 0 0 1 0-6z M12 3v3 M12 18v3 M3 12h3 M18 12h3 M5.6 5.6l2.1 2.1 M16.3 16.3l2.1 2.1 M5.6 18.4l2.1-2.1 M16.3 7.7l2.1-2.1"/></svg><span class="w3nav-tip" aria-hidden="true">Settings</span></a>
    </nav>
  </div>
</section>
<style>
  /* Change these: page tint, ink colour, size of each icon button. */
  .w3nav { --w3nav-bg: #e9edf1; --w3nav-ink: #1e293b; --w3nav-size: 48px; }
  .w3nav { background: var(--w3nav-bg); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3nav-card { max-width: 36rem; margin: 0 auto; padding: 32px 24px; border-radius: 24px; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.06), 0 12px 40px rgba(15,23,42,.08); }
  .w3nav-date { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: #475569; }
  .w3nav-title { margin: 12px 0 0; font-size: 24px; font-weight: 600; letter-spacing: -.01em; color: #0f172a; }
  .w3nav-copy { margin: 12px 0 0; font-size: 16px; line-height: 1.65; color: #475569; }
  .w3nav-lines span { display: block; height: 10px; margin-top: 8px; border-radius: 99px; background: #f1f5f9; width: 92%; }
  .w3nav-lines span + span { width: 75%; }
  .w3nav-lines { margin-top: 24px; }
  .w3nav-bar { display: flex; gap: 6px; width: fit-content; margin: 48px auto 0; padding: 8px; border: 1px solid #e2e8f0; border-radius: 999px; background: #f8fafc; }
  .w3nav-btn { position: relative; display: flex; align-items: center; justify-content: center; width: var(--w3nav-size); height: var(--w3nav-size); border-radius: 50%; color: #334155; will-change: transform; }
  .w3nav-btn svg { position: relative; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .w3nav-bg { position: absolute; inset: 0; border-radius: 50%; background: #fff; box-shadow: 0 4px 14px rgba(15,23,42,.14); }
  .w3nav-dot { position: absolute; bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: var(--w3nav-ink); }
  .w3nav-tip { position: absolute; top: -36px; left: 50%; padding: 4px 8px; border-radius: 6px; background: var(--w3nav-ink); color: #fff; font-size: 12px; font-weight: 500; white-space: nowrap; pointer-events: none; transform: translate(-50%, 6px); }
  .w3nav-bg, .w3nav-tip { opacity: 0; transition: opacity .25s ease, transform .25s ease; }
  .w3nav-btn[data-near] .w3nav-bg, .w3nav-btn:focus-visible .w3nav-bg { opacity: 1; }
  .w3nav-btn[data-near] .w3nav-tip, .w3nav-btn:focus-visible .w3nav-tip { opacity: 1; transform: translate(-50%, 0); }
  .w3nav-btn:focus-visible { outline: 2px solid var(--w3nav-ink); outline-offset: 3px; }
  @media (hover: hover) and (pointer: fine) {
    .w3nav-btn:hover .w3nav-bg { opacity: 1; }
    .w3nav-btn:hover .w3nav-tip { opacity: 1; transform: translate(-50%, 0); }
  }
  @media (max-width: 400px) { .w3nav-bar { gap: 2px; } }
  @media (prefers-reduced-motion: reduce) { .w3nav-btn { transform: none !important; will-change: auto; } .w3nav-bg, .w3nav-tip { transition: none; } }
</style>
<script>
  (function () {
    /* Change these: how strongly icons lean in, and the reach in px around each icon. */
    var PULL = 0.4, RADIUS = 60;
    var bar = document.querySelector(".w3nav-bar");
    if (!bar || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
    var list = [].slice.call(bar.querySelectorAll(".w3nav-btn"));
    var pos = list.map(function () { return { x: 0, y: 0 }; });
    var px = 0, py = 0, live = false, frame = 0, visible = true;
    if (matchMedia("(hover: hover) and (pointer: fine)").matches) {
      bar.addEventListener("pointermove", function (e) { if (e.pointerType === "mouse") { live = true; px = e.clientX; py = e.clientY; } });
      bar.addEventListener("pointerleave", function () { live = false; });
    }
    function tick(now) {
      var b = bar.getBoundingClientRect();
      /* idle demo: a pretend pointer glides along the bar */
      if (!live && bar.contains(document.activeElement)) { px = py = -9999; }
      else if (!live) { px = b.left + b.width / 2 + Math.sin(now / 1600) * b.width * 0.42; py = b.top + b.height / 2 - 10; }
      var best = -1, bestD = RADIUS * 0.55;
      list.forEach(function (btn, i) {
        var r = btn.getBoundingClientRect(), p = pos[i];
        var dx = px - (r.left + r.width / 2 - p.x), dy = py - (r.top + r.height / 2 - p.y), d = Math.hypot(dx, dy), near = d < RADIUS;
        p.x += ((near ? dx * PULL : 0) - p.x) * 0.15;
        p.y += ((near ? dy * PULL : 0) - p.y) * 0.15;
        btn.style.transform = "translate(" + p.x.toFixed(2) + "px," + p.y.toFixed(2) + "px)";
        if (d < bestD) { bestD = d; best = i; }
      });
      list.forEach(function (btn, i) { btn.toggleAttribute("data-near", i === best); });
      frame = requestAnimationFrame(tick);
    }
    function play() { if (!frame && visible) frame = requestAnimationFrame(tick); }
    new IntersectionObserver(function (en) {
      visible = en[0].isIntersecting;
      if (visible) play(); else { cancelAnimationFrame(frame); frame = 0; }
    }).observe(bar);
    play();
  })();
</script>

With reduced motion: The icons hold still in their row, and hover or focus simply shows a white backing and a name tag.

Running cost: A single frame loop reads five button positions and writes five transforms, paused when the bar is off screen.

  • Adjust `PULL` for how far icons lean and `RADIUS` for how close the mouse must be before they react.
  • Swap the icons by editing the `d` path strings in the `tools` array, keeping the 24 by 24 grid.
  • Change `--w3nav-size` to make every button bigger or smaller without touching the script.

Magnetic Pill Button With Parallax Label

A cream pill on a dark wine-bar section leans toward the mouse once it comes within reach, and the words inside travel a little further than the pill itself, so the label seems to float above it. Until a mouse arrives the pill drifts in a slow loop. Use it for the one booking or signup action on a quiet page.

<section class="w3mag">
  <div class="w3mag-inner">
    <p class="w3mag-kicker">Halden Wine Room</p>
    <h2 class="w3mag-title">Twelve seats at the counter, open until one.</h2>
    <p class="w3mag-copy">Natural wines by the glass, small plates from a wood oven, and a list that changes every Thursday.</p>
    <div class="w3mag-stage">
      <a class="w3mag-pill" href="#"><span class="w3mag-glow" aria-hidden="true"></span><span class="w3mag-label">Reserve a seat</span></a>
    </div>
    <p class="w3mag-note">Walk-ins welcome before seven.</p>
  </div>
</section>
<style>
  /* Change these: page colour, pill colour, hover fill colour. */
  .w3mag { --w3mag-bg: #15171b; --w3mag-pill: #efe9df; --w3mag-fill: #c9b892; }
  .w3mag { overflow: hidden; background: var(--w3mag-bg); color: var(--w3mag-pill); padding: 88px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3mag-inner { max-width: 48rem; margin: 0 auto; display: flex; flex-direction: column; align-items: center; text-align: center; }
  .w3mag-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .3em; text-transform: uppercase; color: var(--w3mag-fill); }
  .w3mag-title { margin: 20px 0 0; font-size: clamp(30px, 5vw, 48px); font-weight: 600; line-height: 1.15; letter-spacing: -.02em; }
  .w3mag-copy { margin: 20px 0 0; max-width: 32rem; font-size: 16px; line-height: 1.65; color: #bdb6aa; }
  .w3mag-stage { display: flex; align-items: center; justify-content: center; width: 100%; height: 160px; margin-top: 56px; }
  .w3mag-pill { position: relative; display: inline-flex; align-items: center; height: 64px; padding: 0 48px; border-radius: 999px; overflow: hidden; background: var(--w3mag-pill); color: var(--w3mag-bg); font-size: 16px; font-weight: 600; text-decoration: none; will-change: transform; }
  .w3mag-glow { position: absolute; inset: 0; border-radius: inherit; background: var(--w3mag-fill); opacity: 0; transition: opacity .35s ease; }
  .w3mag-label { position: relative; display: inline-block; }
  .w3mag-pill:focus-visible { outline: 2px solid var(--w3mag-pill); outline-offset: 5px; }
  .w3mag-pill:focus-visible .w3mag-glow { opacity: 1; }
  @media (hover: hover) and (pointer: fine) { .w3mag-pill:hover .w3mag-glow { opacity: 1; } }
  .w3mag-note { margin: 0; font-size: 14px; color: #a39c90; }
  @media (prefers-reduced-motion: reduce) { .w3mag-pill, .w3mag-label { transform: none !important; will-change: auto; } }
</style>
<script>
  (function () {
    /* Change these: how far the pill follows, how far the label follows (more = deeper), reach in px. */
    var PULL = 0.35, LABEL_PULL = 0.55, REACH = 90;
    var root = document.querySelector(".w3mag");
    if (!root || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
    var pill = root.querySelector(".w3mag-pill"), label = root.querySelector(".w3mag-label");
    var tx = 0, ty = 0, x = 0, y = 0, frame = 0, visible = true, live = false, hot = false;
    if (matchMedia("(hover: hover) and (pointer: fine)").matches) {
      root.addEventListener("pointermove", function (e) {
        if (e.pointerType !== "mouse") return;
        live = true;
        var r = pill.getBoundingClientRect(), dx = e.clientX - r.left - r.width / 2, dy = e.clientY - r.top - r.height / 2;
        hot = Math.abs(dx) < r.width / 2 + REACH && Math.abs(dy) < r.height / 2 + REACH;
        tx = hot ? dx : 0; ty = hot ? dy : 0;
      });
      root.addEventListener("pointerleave", function () { live = false; hot = false; });
    }
    function tick(now) {
      /* idle demo: circles the pill until a real mouse arrives */
      if (!live) { tx = Math.sin(now / 1300) * 60; ty = Math.cos(now / 1700) * 26; }
      else if (!hot) { tx = 0; ty = 0; }
      x += (tx - x) * 0.12; y += (ty - y) * 0.12;
      pill.style.transform = "translate(" + (x * PULL).toFixed(2) + "px," + (y * PULL).toFixed(2) + "px)";
      label.style.transform = "translate(" + (x * (LABEL_PULL - PULL)).toFixed(2) + "px," + (y * (LABEL_PULL - PULL)).toFixed(2) + "px)";
      frame = requestAnimationFrame(tick);
    }
    function play() { if (!frame && visible) frame = requestAnimationFrame(tick); }
    new IntersectionObserver(function (en) {
      visible = en[0].isIntersecting;
      if (visible) play(); else { cancelAnimationFrame(frame); frame = 0; }
    }).observe(root);
    play();
  })();
</script>

With reduced motion: The pill stays fixed in place and only its fill colour changes on hover or focus.

Running cost: One small frame loop writes two transforms and stops whenever the section scrolls out of view.

  • Raise `PULL` for a stronger lean and widen the gap to `LABEL_PULL` for more depth between label and pill.
  • Set `REACH` to the distance in pixels at which the pull switches on.
  • Recolour through `--w3mag-bg`, `--w3mag-pill` and `--w3mag-fill` in the HTML version.

A follow block for a print studio on warm sand: five round outline icons, each with its name printed underneath, lean toward the mouse as it comes near and fill with terracotta when it is close. The glyph inside moves a little further than its circle, which gives the pull some depth. A pretend pointer drifts along the row until a real one arrives.

<section class="w7mag" data-w7mag aria-label="Follow Kestrel Print Studio">
  <div class="w7mag-in">
    <p class="w7mag-eye">Kestrel Print Studio</p>
    <h2 class="w7mag-h">Follow the presses between visits</h2>
    <p class="w7mag-p">New prints, open studio dates and the occasional misprint sale, wherever you prefer to hear about them.</p>
    <ul class="w7mag-row">
      <li><a class="w7mag-i" href="#"><span class="w7mag-disc"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="2" /><path d="M3.5 6.5 12 13l8.5-6.5" /></svg></span><span class="w7mag-lab">Newsletter</span></a></li>
      <li><a class="w7mag-i" href="#"><span class="w7mag-disc"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 8h3l2-3h6l2 3h3v11H4z" /><circle cx="12" cy="13" r="3.5" /></svg></span><span class="w7mag-lab">Photo diary</span></a></li>
      <li><a class="w7mag-i" href="#"><span class="w7mag-disc"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="3" width="6" height="11" rx="3" /><path d="M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21" /></svg></span><span class="w7mag-lab">Podcast</span></a></li>
      <li><a class="w7mag-i" href="#"><span class="w7mag-disc"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="3" /><path d="M10 9.5v5l4.5-2.5z" /></svg></span><span class="w7mag-lab">Videos</span></a></li>
      <li><a class="w7mag-i" href="#"><span class="w7mag-disc"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 21s-6.5-6-6.5-11a6.5 6.5 0 0 1 13 0c0 5-6.5 11-6.5 11z" /><circle cx="12" cy="10" r="2.3" /></svg></span><span class="w7mag-lab">Find the studio</span></a></li>
    </ul>
  </div>
</section>

<style>
  /* Change these: --w7mag-bg, --w7mag-ink, --w7mag-clay (fill colour), --w7mag-size (disc size). Pull strength and reach are in the script. */
  .w7mag { --w7mag-bg: #efe5d6; --w7mag-ink: #2e2219; --w7mag-clay: #b4532a; --w7mag-size: 64px;
    position: relative; padding: 64px 20px 72px; background: var(--w7mag-bg); color: var(--w7mag-ink); text-align: center;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  .w7mag-in { max-width: 44rem; margin: 0 auto; }
  .w7mag-eye { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: #8e3d1b; }
  .w7mag-h { margin: 12px 0 0; font-family: Georgia, "Iowan Old Style", serif; font-weight: 400; font-size: clamp(1.9rem, 4.6vw, 3rem); line-height: 1.08; letter-spacing: -.015em; }
  .w7mag-p { margin: 14px auto 0; max-width: 30rem; font-size: 16px; line-height: 1.6; color: #5c4a3c; }
  .w7mag-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px 22px; margin: 40px 0 0; padding: 0; list-style: none; }
  .w7mag-i { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 88px; padding: 6px 0; border-radius: 12px; color: var(--w7mag-ink); text-decoration: none; outline: none; }
  .w7mag-disc { position: relative; display: grid; place-items: center; width: var(--w7mag-size); height: var(--w7mag-size); border-radius: 50%; border: 1.5px solid rgba(46,34,25,.3); will-change: transform; }
  .w7mag-disc::before { content: ""; position: absolute; inset: -1.5px; border-radius: 50%; background: var(--w7mag-clay); transform: scale(0); transition: transform .45s cubic-bezier(.2,.8,.2,1); }
  .w7mag-disc svg { position: relative; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; transition: color .3s; will-change: transform; }
  .w7mag-lab { font-size: 13px; font-weight: 600; }
  .w7mag-i:hover .w7mag-disc::before, .w7mag-i:focus-visible .w7mag-disc::before, .w7mag-i[data-near] .w7mag-disc::before { transform: scale(1); }
  .w7mag-i:hover svg, .w7mag-i:focus-visible svg, .w7mag-i[data-near] svg { color: #fff6ec; }
  .w7mag-i:focus-visible .w7mag-disc { box-shadow: 0 0 0 3px var(--w7mag-bg), 0 0 0 5px var(--w7mag-ink); }
  @media (prefers-reduced-motion: reduce) { .w7mag-disc::before { transition: none; } }
</style>

<script>
(function () {
  var root = document.querySelector("[data-w7mag]");
  if (!root) return;
  var off = [];
  //BODY-START
  var REACH = 110, PULL = .38, INNER = .18, IDLE_AFTER = 2500; // px of reach, disc pull, extra icon pull, ms before the demo resumes
  if (matchMedia("(prefers-reduced-motion: reduce)").matches) return;
  var items = [].slice.call(root.querySelectorAll(".w7mag-i")).map(function (a) {
    return { a: a, d: a.querySelector(".w7mag-disc"), s: a.querySelector("svg"), x: 0, y: 0 };
  });
  var px = -9999, py = -9999, real = 0, raf = 0, seen = true;
  function tick(t) {
    raf = requestAnimationFrame(tick);
    if (!real || t - real > IDLE_AFTER) {
      // A pretend pointer drifts along the row so the preview shows the pull.
      var f = items[0].d.getBoundingClientRect(), l = items[items.length - 1].d.getBoundingClientRect();
      px = f.left + (l.right - f.left) * (.5 + .55 * Math.sin(t * .0009)); py = f.top + f.height / 2 + 14 * Math.sin(t * .002);
    }
    items.forEach(function (it) {
      var r = it.d.getBoundingClientRect(), cx = r.left + r.width / 2 - it.x, cy = r.top + r.height / 2 - it.y;
      var dx = px - cx, dy = py - cy, near = Math.hypot(dx, dy) < REACH * .6, k = Math.max(0, 1 - Math.hypot(dx, dy) / REACH);
      it.x += (dx * PULL * k - it.x) * .18; it.y += (dy * PULL * k - it.y) * .18;
      it.d.style.transform = "translate(" + it.x.toFixed(2) + "px," + it.y.toFixed(2) + "px)";
      it.s.style.transform = "translate(" + (it.x * INNER / PULL).toFixed(2) + "px," + (it.y * INNER / PULL).toFixed(2) + "px)";
      if (!real || t - real > IDLE_AFTER) it.a.toggleAttribute("data-near", near); else it.a.removeAttribute("data-near");
    });
  }
  function move(e) { if (e.pointerType === "touch") return; px = e.clientX; py = e.clientY; real = performance.now(); }
  function leave() { px = py = -9999; real = performance.now(); }
  function focus() { px = py = -9999; real = performance.now() + 4000; }
  root.addEventListener("pointermove", move);
  root.addEventListener("pointerleave", leave);
  root.addEventListener("focusin", focus);
  off.push(function () {
    root.removeEventListener("pointermove", move); root.removeEventListener("pointerleave", leave); root.removeEventListener("focusin", focus);
    items.forEach(function (it) { it.d.style.transform = it.s.style.transform = ""; it.a.removeAttribute("data-near"); });
  });
  function play() { if (!raf && seen) raf = requestAnimationFrame(tick); }
  function stop() { cancelAnimationFrame(raf); raf = 0; }
  var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; if (seen) play(); else stop(); });
  io.observe(root);
  off.push(stop, function () { io.disconnect(); });
  play();
  //BODY-END
})();
</script>

With reduced motion: Icons stay put; hover and focus still fill each disc with colour.

Running cost: Five small transforms per frame while visible, measured from five bounding boxes; the loop stops off screen.

  • Strengthen or soften the pull with `PULL`, and the extra glyph shift with `INNER`.
  • Widen the area that reacts with `REACH`; keep it below the gap between icons so only one leans at a time.
  • Change the fill with `--w7mag-clay` and the disc size with `--w7mag-size`.

Product Cards Lift With Shadow and Quick Add

A three-product shelf for a homeware shop on deep olive. Pointing at a card raises it, eases the photo in slightly and fades in a long soft shadow that was painted in advance, while an add to basket bar slides up over the bottom of the picture. Tabbing into a card does the same. On touch screens the add button is simply always visible.

<section class="w7crd" data-w7crd aria-label="Hollow Lane homeware, new in">
  <div class="w7crd-in">
    <div class="w7crd-top">
      <h2 class="w7crd-h">New in the kitchen</h2>
      <a class="w7crd-all" href="#">Shop all homeware</a>
    </div>
    <ul class="w7crd-grid">
      <li class="w7crd-c">
        <div class="w7crd-img"><img src="https://images.pexels.com/photos/31785816/pexels-photo-31785816.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A speckled deep blue stoneware mug on a wooden table" width="800" height="800" loading="eager" />
          <div class="w7crd-bar"><button class="w7crd-add" type="button">Add to basket</button></div></div>
        <div class="w7crd-txt"><h3><a href="#">Tidepool mug</a></h3><p>Reactive glaze, 340 ml</p><p class="w7crd-pr">£24</p></div>
      </li>
      <li class="w7crd-c">
        <div class="w7crd-img"><img src="https://images.pexels.com/photos/7233906/pexels-photo-7233906.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A lit candle in a dark stoneware pot surrounded by dried flowers and matches" width="800" height="800" loading="eager" />
          <div class="w7crd-bar"><button class="w7crd-add" type="button">Add to basket</button></div></div>
        <div class="w7crd-txt"><h3><a href="#">Hearth candle</a></h3><p>Cedar and fig, 40 hour burn</p><p class="w7crd-pr">£32</p></div>
      </li>
      <li class="w7crd-c">
        <div class="w7crd-img"><img src="https://images.pexels.com/photos/12480291/pexels-photo-12480291.jpeg?auto=compress&cs=tinysrgb&w=800" alt="A white mug with a blue glazed rim beside a matching blue spoon" width="800" height="800" loading="eager" />
          <div class="w7crd-bar"><button class="w7crd-add" type="button">Add to basket</button></div></div>
        <div class="w7crd-txt"><h3><a href="#">Harbour mug and spoon</a></h3><p>Dipped rim, set of two</p><p class="w7crd-pr">£38</p></div>
      </li>
    </ul>
  </div>
</section>

<style>
  /* Change these: --w7crd-bg, --w7crd-card, --w7crd-lift (how far a card rises), --w7crd-shadow (colour of the hover shadow). */
  .w7crd { --w7crd-bg: #26322b; --w7crd-card: #f6f1e8; --w7crd-ink: #1f2420; --w7crd-lift: -10px; --w7crd-shadow: rgba(6,12,8,.55);
    padding: 56px 20px 64px; background: var(--w7crd-bg); font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  .w7crd-in { max-width: 66rem; margin: 0 auto; }
  .w7crd-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 20px; color: #f6f1e8; }
  .w7crd-h { margin: 0; font-family: Georgia, "Iowan Old Style", serif; font-weight: 400; font-size: clamp(1.7rem, 3.6vw, 2.4rem); }
  .w7crd-all { display: inline-flex; align-items: center; min-height: 44px; color: #e6d9bf; font-size: 15px; font-weight: 600; text-underline-offset: 4px; }
  .w7crd-all:focus-visible, .w7crd-txt a:focus-visible, .w7crd-add:focus-visible { outline: 3px solid #e6b85c; outline-offset: 3px; }
  .w7crd-grid { display: grid; gap: 22px; margin: 28px 0 0; padding: 0; list-style: none; }
  .w7crd-c { position: relative; border-radius: 10px; background: var(--w7crd-card); color: var(--w7crd-ink); transform: translateY(0); transition: transform .45s cubic-bezier(.2,.8,.2,1); }
  /* The big soft shadow is drawn once here; hover only fades it in. */
  .w7crd-c::after { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: 10px; box-shadow: 0 30px 50px -18px var(--w7crd-shadow), 0 10px 18px -10px var(--w7crd-shadow); opacity: 0; transition: opacity .45s ease; }
  .w7crd-img { position: relative; overflow: hidden; border-radius: 10px 10px 0 0; aspect-ratio: 1; background: #ddd3c3; }
  .w7crd-img img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .7s cubic-bezier(.2,.8,.2,1); }
  .w7crd-bar { position: absolute; left: 12px; right: 12px; bottom: 12px; transform: translateY(calc(100% + 14px)); transition: transform .45s cubic-bezier(.2,.8,.2,1); }
  .w7crd-add { width: 100%; min-height: 44px; border: 0; border-radius: 6px; background: var(--w7crd-ink); color: #f6f1e8; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
  .w7crd-add:hover { background: #3a463e; }
  .w7crd-txt { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 16px 18px 18px; }
  .w7crd-txt h3 { margin: 0; font-size: 16px; font-weight: 600; }
  .w7crd-txt a { color: inherit; text-decoration: none; }
  .w7crd-txt p { grid-column: 1; margin: 0; font-size: 14px; color: #535a54; }
  .w7crd-txt .w7crd-pr { grid-column: 2; grid-row: 1; font-size: 16px; font-weight: 600; color: var(--w7crd-ink); }
  .w7crd-c:hover, .w7crd-c:focus-within, .w7crd-c[data-demo] { transform: translateY(var(--w7crd-lift)); }
  .w7crd-c:hover::after, .w7crd-c:focus-within::after, .w7crd-c[data-demo]::after { opacity: 1; }
  .w7crd-c:hover img, .w7crd-c:focus-within img, .w7crd-c[data-demo] img { transform: scale(1.05); }
  .w7crd-c:hover .w7crd-bar, .w7crd-c:focus-within .w7crd-bar, .w7crd-c[data-demo] .w7crd-bar { transform: none; }
  @media (min-width: 720px) { .w7crd-grid { grid-template-columns: repeat(3, 1fr); } }
  /* Touch screens have no hover, so the add button is always shown. */
  @media (hover: none) { .w7crd-bar { transform: none; } }
  @media (prefers-reduced-motion: reduce) { .w7crd-c, .w7crd-c::after, .w7crd-img img, .w7crd-bar { transition: none; } .w7crd-c:hover img, .w7crd-c:focus-within img, .w7crd-c[data-demo] img { transform: none; } }
</style>

<script>
(function () {
  var root = document.querySelector("[data-w7crd]");
  if (!root) return;
  var off = [];
  //BODY-START
  var STEP = 1700; // ms each card stays lifted during the demo
  if (matchMedia("(prefers-reduced-motion: reduce)").matches) return;
  // Demo only: cards take turns lifting until someone points at, taps or tabs into the grid.
  var cards = root.querySelectorAll(".w7crd-c"), i = 1, timer = 0, seen = true, done = false;
  function clear() { cards.forEach(function (c) { c.removeAttribute("data-demo"); }); }
  function step() { clear(); cards[i++ % cards.length].setAttribute("data-demo", ""); timer = setTimeout(step, STEP); }
  function play() { if (!done && seen && !timer) step(); }
  function stop() { clearTimeout(timer); timer = 0; clear(); }
  function hand() { done = true; stop(); }
  ["pointerenter", "focusin", "touchstart"].forEach(function (n) { root.addEventListener(n, hand, { passive: true }); off.push(function () { root.removeEventListener(n, hand); }); });
  var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; if (seen) play(); else stop(); });
  io.observe(root);
  off.push(stop, function () { io.disconnect(); });
  play();
  //BODY-END
})();
</script>

With reduced motion: Cards still show the lifted state and add button on hover or focus, but switch instantly with no zoom or demo.

Running cost: Hover changes only transforms and the opacity of a pre-painted shadow layer; a small timer runs the demo until someone interacts.

  • Set how far a card rises with `--w7crd-lift` and the shadow tone with `--w7crd-shadow`.
  • Retune the shadow itself in `.w7crd-c::after`; it is drawn once, so heavier shadows cost nothing extra while hovering.
  • Swap products by editing each `li.w7crd-c`: photo, name link, short detail and price.

Property Listing Card Tilt With Floating Layers

A rental listing card whose parts sit at different depths: the photo floats above a white base, the details sit a little higher, and the price pill and move-in tag hover highest, so they slide against each other as the card tips toward the pointer. A soft light moves across the photo. On phones it tilts toward a pressed finger and eases flat after release.

<section class="w4prl">
  <div class="w4prl-wrap">
    <div>
      <p class="w4prl-kicker">Larkfield Lettings</p>
      <h2 class="w4prl-title">A yellow brick bungalow with green shutters, two streets from the beach.</h2>
      <p class="w4prl-copy">Single storey, south facing, with a tiled patio out front and a quiet lane behind. Unfurnished, pets considered.</p>
      <a href="#" class="w4prl-cta">Book a viewing</a>
    </div>
    <div class="w4prl-stage">
      <a href="#" class="w4prl-card" aria-label="7 Quayside Lane, Seacombe, two bedroom bungalow to let at 1,450 pounds a month, view listing">
        <span class="w4prl-base" aria-hidden="true"></span>
        <span class="w4prl-photo" aria-hidden="true">
          <img src="https://images.pexels.com/photos/32029072/pexels-photo-32029072.jpeg?auto=compress&cs=tinysrgb&w=1000" alt="Yellow brick bungalow with green shutters and a tiled patio" width="1000" height="667" loading="lazy">
          <span class="w4prl-hl"></span>
        </span>
        <span class="w4prl-price" aria-hidden="true">£1,450 <small>pcm</small></span>
        <span class="w4prl-tag" aria-hidden="true">From 1 Dec</span>
        <span class="w4prl-info" aria-hidden="true">
          <span class="w4prl-addr">7 Quayside Lane</span>
          <span class="w4prl-area">Seacombe, bungalow</span>
          <span class="w4prl-specs">
            <span><svg viewBox="0 0 20 20"><path d="M3 17V9h14v8M3 13h14M6 9V6h8v3"/></svg>2 bedrooms</span>
            <span><svg viewBox="0 0 20 20"><path d="M3 11h14v2a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4v-2ZM5 11V5a2 2 0 0 1 3-1"/></svg>1 bathroom</span>
            <span><svg viewBox="0 0 20 20"><path d="M3 3h14v14H3zM3 10h14M10 3v14"/></svg>Tiled patio</span>
          </span>
        </span>
      </a>
    </div>
  </div>
</section>
<style>
  /* Change these: --w4prl-bg (section), --w4prl-accent (green), and the translateZ values on .w4prl-price / .w4prl-photo / .w4prl-info for how far each layer floats. */
.w4prl { --w4prl-bg: #eef1f4; --w4prl-ink: #1c2530; --w4prl-muted: #4f5b69; --w4prl-accent: #2f6b4f;
    background: var(--w4prl-bg); color: var(--w4prl-ink); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }
  .w4prl-wrap { max-width: 62rem; margin: 0 auto; display: grid; gap: 48px; align-items: center; }
  @media (min-width: 820px) { .w4prl-wrap { grid-template-columns: 1fr 1.05fr; } }
  .w4prl-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: var(--w4prl-accent); }
  .w4prl-title { margin: 14px 0 0; font-size: clamp(28px, 3.8vw, 40px); font-weight: 650; line-height: 1.12; letter-spacing: -.02em; }
  .w4prl-copy { margin: 16px 0 0; max-width: 26rem; font-size: 16px; line-height: 1.65; color: var(--w4prl-muted); }
  .w4prl-stage { display: flex; justify-content: center; perspective: 1000px; touch-action: pan-y; padding: 8px 0 16px; }
  .w4prl-card { position: relative; display: block; width: 100%; max-width: 380px; padding: 14px 14px 20px; box-sizing: border-box; color: inherit; text-decoration: none;
    transform-style: preserve-3d; will-change: transform; outline: none; }
  .w4prl-base { position: absolute; inset: 0; border-radius: 22px; background: #fff; box-shadow: 0 1px 2px rgba(20, 30, 40, .08), 0 24px 50px -24px rgba(20, 30, 40, .35); }
  .w4prl-card:focus-visible .w4prl-base { outline: 3px solid var(--w4prl-accent); outline-offset: 5px; }
  .w4prl-photo { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: #c9b98e; transform: translateZ(26px);
    box-shadow: 0 14px 26px -16px rgba(20, 30, 40, .55); }
  .w4prl-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .w4prl-hl { position: absolute; inset: -60%; opacity: .15; pointer-events: none; background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 36%); }
  .w4prl-price { position: absolute; left: 26px; top: 26px; padding: 8px 14px; border-radius: 999px; background: var(--w4prl-ink); color: #fff; font-size: 15px; font-weight: 650;
    transform: translateZ(60px); box-shadow: 0 10px 20px -8px rgba(10, 20, 30, .6); }
  .w4prl-price small { font-weight: 500; opacity: .8; }
  .w4prl-tag { position: absolute; right: 26px; top: 28px; padding: 6px 11px; border-radius: 999px; background: #fff; color: var(--w4prl-accent); font-size: 12px; font-weight: 650;
    transform: translateZ(44px); box-shadow: 0 8px 16px -8px rgba(10, 20, 30, .45); }
  .w4prl-info { position: relative; display: block; padding: 18px 6px 0; transform: translateZ(34px); }
  .w4prl-addr { display: block; font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
  .w4prl-area { display: block; margin-top: 3px; font-size: 14px; color: var(--w4prl-muted); }
  .w4prl-specs { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #e3e7ec; font-size: 13.5px; color: #34404d; }
  .w4prl-specs span { display: inline-flex; align-items: center; gap: 6px; }
  .w4prl-specs svg { width: 18px; height: 18px; fill: none; stroke: var(--w4prl-accent); stroke-width: 1.6; stroke-linejoin: round; }
  .w4prl-cta { display: inline-flex; align-items: center; min-height: 46px; margin-top: 26px; padding: 0 22px; border-radius: 12px; background: var(--w4prl-accent); color: #fff;
    font-size: 15px; font-weight: 600; text-decoration: none; }
  .w4prl-cta:hover { background: #245540; }
  .w4prl-cta:focus-visible { outline: 3px solid var(--w4prl-ink); outline-offset: 3px; }
  @media (prefers-reduced-motion: reduce) { .w4prl-card { transform: rotateX(5deg) rotateY(-7deg) !important; will-change: auto; } .w4prl-hl { transform: translate(-14%, -18%) !important; opacity: .35 !important; } }
</style>
<script>
(function () {
  /* Change these: MAX tilt in degrees at the edge, EASE follow speed. */
  var MAX = 9, EASE = 0.09;
  var root = document.querySelector(".w4prl");
  if (!root || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
  var card = root.querySelector(".w4prl-card"), hl = root.querySelector(".w4prl-hl");
  var tx = 0, ty = 0, x = 0, y = 0, idle = true, f = 0, vis = true, tm = 0;
  function cl(v) { return Math.max(-1, Math.min(1, v)); }
  function go() { if (!f && vis) f = requestAnimationFrame(tick); }
  function aim(e) {
    var r = card.getBoundingClientRect();
    tx = cl((e.clientX - r.left) / r.width * 2 - 1); ty = cl((e.clientY - r.top) / r.height * 2 - 1);
    idle = false; go();
  }
  function flat() { tx = ty = 0; go(); }
  function tick(now) {
    f = 0;
    /* idle demo: a slow drift around the corners until real input arrives */
    if (idle) { tx = Math.cos(now / 2600) * 0.75; ty = Math.sin(now / 1900) * 0.6; }
    x += (tx - x) * EASE; y += (ty - y) * EASE;
    card.style.transform = "rotateX(" + (-y * MAX).toFixed(2) + "deg) rotateY(" + (x * MAX).toFixed(2) + "deg)";
    hl.style.transform = "translate(" + (x * 24).toFixed(1) + "%," + (y * 24).toFixed(1) + "%)";
    hl.style.opacity = (0.12 + 0.55 * Math.min(1, Math.hypot(x, y))).toFixed(3);
    if (idle || Math.abs(tx - x) + Math.abs(ty - y) > 0.002) go();
  }
  root.addEventListener("pointermove", function (e) { if (e.pointerType == "mouse" || e.buttons) aim(e); });
  root.addEventListener("pointerdown", function (e) { clearTimeout(tm); aim(e); });
  root.addEventListener("pointerup", function (e) { if (e.pointerType != "mouse") tm = setTimeout(flat, 700); });
  root.addEventListener("pointerleave", function (e) { if (e.pointerType == "mouse") flat(); });
  root.addEventListener("pointercancel", flat);
  card.addEventListener("focus", function () { idle = false; tx = -0.55; ty = -0.45; go(); });
  card.addEventListener("blur", flat);
  new IntersectionObserver(function (en) {
    vis = en[0].isIntersecting;
    if (vis) go(); else { cancelAnimationFrame(f); f = 0; }
  }).observe(root);
  go();
})();
</script>

With reduced motion: The listing sits at one fixed slight angle with its price pill, date tag and details already lifted off the card, and nothing follows the pointer.

Running cost: A frame loop writes one rotation and one highlight transform while the card is moving, then stops until the next pointer or focus change.

  • Raise or lower the `translateZ` values on `.w4prl-price`, `.w4prl-tag`, `.w4prl-photo` and `.w4prl-info` to spread the layers further apart or press them flatter.
  • Change `MAX_TILT` (React) or `MAX` (HTML) for the angle, and `--w4prl-accent` for the green used on icons, the tag and the button.
  • Edit the `specs` array (React) or the three spans in `.w4prl-specs` (HTML) to list other features.

Service List With a Photo That Follows the Pointer

A ruled list of pottery classes where a tilted photo of the matching class floats after the mouse as it moves down the rows, swapping pictures with a quick crossfade. Tabbing to a row parks the photo at its right end, and an idle demo steps through the rows. On phones each row simply carries a small thumbnail.

<section class="w3row">
  <div class="w3row-wrap">
    <p class="w3row-kicker">Tidewater Clay Studio</p>
    <h2 class="w3row-title">Ways to get your hands dirty</h2>
    <div class="w3row-list">
      <ul>
        <li><a class="w3row-a" href="#"><span class="w3row-no">01</span><img class="w3row-thumb" src="https://images.pexels.com/photos/6693557/pexels-photo-6693557.jpeg?auto=compress&cs=tinysrgb&w=800" alt="" aria-hidden="true" width="64" height="48" loading="lazy"><span class="w3row-name"><span class="w3row-n">Handbuilding evenings</span><span class="w3row-l">Pinch, coil and slab over six Tuesdays</span></span><span class="w3row-price">$210</span></a></li>
        <li><a class="w3row-a" href="#"><span class="w3row-no">02</span><img class="w3row-thumb" src="https://images.pexels.com/photos/34004100/pexels-photo-34004100.jpeg?auto=compress&cs=tinysrgb&w=800" alt="" aria-hidden="true" width="64" height="48" loading="lazy"><span class="w3row-name"><span class="w3row-n">Open studio membership</span><span class="w3row-l">Your own shelf, wheels and kiln space</span></span><span class="w3row-price">$95 a month</span></a></li>
        <li><a class="w3row-a" href="#"><span class="w3row-no">03</span><img class="w3row-thumb" src="https://images.pexels.com/photos/8063833/pexels-photo-8063833.jpeg?auto=compress&cs=tinysrgb&w=800" alt="" aria-hidden="true" width="64" height="48" loading="lazy"><span class="w3row-name"><span class="w3row-n">Glaze and firing service</span><span class="w3row-l">Bring finished pieces, collect them in a week</span></span><span class="w3row-price">From $6 a piece</span></a></li>
      </ul>
      <div class="w3row-pv" aria-hidden="true">
        <div class="w3row-in">
          <img src="https://images.pexels.com/photos/6693557/pexels-photo-6693557.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Hands shaping a small clay pot on a wooden table among tools and bisque pieces" width="256" height="192">
          <img src="https://images.pexels.com/photos/34004100/pexels-photo-34004100.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Rows of freshly thrown clay pots drying side by side in a workshop" width="256" height="192">
          <img src="https://images.pexels.com/photos/8063833/pexels-photo-8063833.jpeg?auto=compress&cs=tinysrgb&w=800" alt="Black and white photo of stacked ceramic bowls and small round pots" width="256" height="192">
        </div>
      </div>
    </div>
  </div>
</section>
<style>
  /* Change these: background, ink, rule colour, preview width. */
  .w3row { --w3row-bg: #f3ece4; --w3row-ink: #2a1f1a; --w3row-rule: #d9cabb; --w3row-pw: 256px; }
  .w3row { background: var(--w3row-bg); color: var(--w3row-ink); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3row-wrap { max-width: 56rem; margin: 0 auto; }
  .w3row-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .25em; text-transform: uppercase; color: #8a4b32; }
  .w3row-title { margin: 12px 0 0; font-size: clamp(30px, 4vw, 36px); font-weight: 600; letter-spacing: -.02em; }
  .w3row-list { position: relative; margin-top: 40px; }
  .w3row-list ul { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--w3row-rule); }
  .w3row-list li { border-bottom: 1px solid var(--w3row-rule); }
  .w3row-a { position: relative; z-index: 1; display: flex; align-items: center; gap: 16px; padding: 24px 0; color: inherit; text-decoration: none; }
  .w3row-a:focus-visible { outline: 2px solid var(--w3row-ink); outline-offset: 2px; }
  .w3row-no { width: 32px; flex-shrink: 0; font-family: ui-monospace, monospace; font-size: 14px; color: #7a5a48; }
  .w3row-name { flex: 1; min-width: 0; transition: transform .4s cubic-bezier(.2,.8,.2,1); }
  .w3row-n { display: block; font-size: clamp(20px, 3vw, 24px); font-weight: 600; }
  .w3row-l { display: block; margin-top: 4px; font-size: 15px; color: #5e4a3f; }
  .w3row-price { flex-shrink: 0; text-align: right; font-size: 15px; font-weight: 600; }
  .w3row-thumb { display: none; width: 64px; height: 48px; flex-shrink: 0; border-radius: 6px; object-fit: cover; }
  .w3row-a:focus-visible .w3row-name { transform: translateX(10px); }
  @media (hover: hover) and (pointer: fine) { .w3row-a:hover .w3row-name { transform: translateX(10px); } }
  .w3row-pv { position: absolute; left: 0; top: 0; z-index: 2; width: var(--w3row-pw); pointer-events: none; will-change: transform; }
  .w3row-in { position: relative; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 12px; background: var(--w3row-rule); box-shadow: 0 20px 40px -12px rgba(42,31,26,.45); opacity: 0; transform: scale(.85) rotate(-3deg); transition: opacity .35s ease, transform .5s cubic-bezier(.2,.8,.2,1); }
  .w3row-pv[data-on] .w3row-in { opacity: 1; transform: none; }
  .w3row-in img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .35s ease; }
  .w3row-in img[data-on] { opacity: 1; }
  @media (max-width: 640px) { .w3row-pv { width: 224px; } }
  /* touch and reduced motion: no follower, each row shows its own small photo */
  @media (hover: none), (pointer: coarse), (prefers-reduced-motion: reduce) {
    .w3row-pv { display: none; }
    .w3row-thumb { display: block; }
    .w3row-name { transition: none; }
  }
</style>
<script>
  (function () {
    /* Change these: how fast the photo catches the pointer (0 to 1), ms per row in the idle demo. */
    var FOLLOW = 0.14, DEMO_EVERY = 1900;
    var box = document.querySelector(".w3row-list");
    if (!box || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
    var pv = box.querySelector(".w3row-pv"), rows = [].slice.call(box.querySelectorAll("a")), imgs = [].slice.call(pv.querySelectorAll("img"));
    var tx = 0, ty = 0, x = -1, y = 0, live = false, focused = false, frame = 0, visible = true, timer = 0, n = 0;
    function show(i) { pv.toggleAttribute("data-on", i >= 0); imgs.forEach(function (im, k) { im.toggleAttribute("data-on", k === i); }); }
    /* parks the photo near the right end of a row (focus and idle demo) */
    function park(i) { var r = rows[i]; tx = box.clientWidth * 0.7; ty = r.offsetTop + r.offsetHeight / 2; show(i); }
    if (matchMedia("(hover: hover) and (pointer: fine)").matches) {
      box.addEventListener("pointermove", function (e) {
        if (e.pointerType !== "mouse") return;
        var b = box.getBoundingClientRect(); tx = e.clientX - b.left; ty = e.clientY - b.top; live = true;
      });
      box.addEventListener("pointerover", function (e) {
        if (e.pointerType !== "mouse") return;
        var i = rows.indexOf(e.target.closest("a")); if (i >= 0) show(i);
      });
      box.addEventListener("pointerleave", function () { live = false; show(-1); });
    }
    box.addEventListener("focusin", function (e) { var i = rows.indexOf(e.target); if (i >= 0) { focused = true; park(i); } });
    box.addEventListener("focusout", function () { focused = false; show(-1); });
    function demo() { if (!live && !focused) park(n++ % rows.length); }
    function tick() {
      if (x < 0) { x = tx; y = ty; }
      x += (tx - x) * FOLLOW; y += (ty - y) * FOLLOW;
      pv.style.transform = "translate(" + (x - pv.offsetWidth / 2).toFixed(1) + "px," + (y - pv.offsetHeight / 2).toFixed(1) + "px)";
      frame = requestAnimationFrame(tick);
    }
    function play() { if (!frame && visible) { frame = requestAnimationFrame(tick); timer = setInterval(demo, DEMO_EVERY); } }
    new IntersectionObserver(function (en) {
      visible = en[0].isIntersecting;
      if (visible) play(); else { cancelAnimationFrame(frame); frame = 0; clearInterval(timer); }
    }).observe(box);
    demo(); play();
  })();
</script>

With reduced motion: There is no floating photo; every row shows its own small picture beside the name instead.

Running cost: One frame loop moves a single preview by transform and stops, along with the demo timer, when the list is off screen.

  • Raise `FOLLOW` for a snappier photo or lower it for a lazier trail, and set `DEMO_EVERY` for the idle pace.
  • Change the preview size with `--w3row-pw`, keeping its 4 by 3 frame.
  • Edit names, lines, prices and photos in the `services` array.

Split Colour Button With a Sliding Second Colour

Three booking buttons for a wine bar on a bone background. On hover or keyboard focus a second colour slides in behind the label, from the left, from below or from the right, and the label changes colour exactly where the edge passes, so for a moment the word is split in two tones. The trick is a masked copy of the label moving against its own mask.

<section class="w7spl" data-w7spl aria-label="Lowtide Wine Bar bookings">
  <div class="w7spl-card">
    <p class="w7spl-eye">Lowtide Wine Bar</p>
    <h2 class="w7spl-h">Thirty bottles open by the glass, and a short menu to go with them</h2>
    <div class="w7spl-row">
      <a class="w7spl-b w7spl-a" href="#"><span class="w7spl-t">Book a table</span><span class="w7spl-m" aria-hidden="true"><span class="w7spl-t">Book a table</span></span></a>
      <a class="w7spl-b w7spl-o" href="#"><span class="w7spl-t">Tasting Thursdays</span><span class="w7spl-m" aria-hidden="true"><span class="w7spl-t">Tasting Thursdays</span></span></a>
      <a class="w7spl-b w7spl-u" href="#"><span class="w7spl-t">Gift a bottle</span><span class="w7spl-m" aria-hidden="true"><span class="w7spl-t">Gift a bottle</span></span></a>
    </div>
    <p class="w7spl-note">Walk-ins welcome at the bar until nine.</p>
  </div>
</section>

<style>
  /* Change these: --w7spl-ink, --w7spl-wine (second colour), --w7spl-bone (page), --w7spl-dur (slide time). */
  .w7spl { --w7spl-ink: #1c1a17; --w7spl-wine: #8c2f39; --w7spl-bone: #f1ebe1; --w7spl-dur: .55s;
    padding: 56px 20px; background: var(--w7spl-bone); color: var(--w7spl-ink); font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  .w7spl-card { max-width: 46rem; margin: 0 auto; text-align: center; }
  .w7spl-eye { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; color: var(--w7spl-wine); }
  .w7spl-h { margin: 14px 0 0; font-family: Georgia, "Iowan Old Style", serif; font-weight: 400; font-size: clamp(1.7rem, 4vw, 2.6rem); line-height: 1.15; letter-spacing: -.01em; }
  .w7spl-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: 34px; }
  .w7spl-b { position: relative; display: inline-grid; min-height: 52px; padding: 0 28px; place-items: center; overflow: hidden; border-radius: 4px; font-size: 15px; font-weight: 600; letter-spacing: .01em; text-decoration: none; isolation: isolate; }
  .w7spl-a { background: var(--w7spl-ink); color: var(--w7spl-bone); }
  .w7spl-o { box-shadow: inset 0 0 0 1.5px var(--w7spl-ink); color: var(--w7spl-ink); }
  .w7spl-u { background: #e3d7c5; color: var(--w7spl-ink); }
  /* The mask carries the second colour; its label moves the opposite way, so the text stays still and changes colour at the edge. */
  .w7spl-m { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; background: var(--w7spl-wine); color: #fbf3ea; transform: translateX(-101%); transition: transform var(--w7spl-dur) cubic-bezier(.7,0,.2,1); }
  .w7spl-m .w7spl-t { transform: translateX(101%); transition: transform var(--w7spl-dur) cubic-bezier(.7,0,.2,1); }
  .w7spl-o .w7spl-m { transform: translateY(101%); } .w7spl-o .w7spl-m .w7spl-t { transform: translateY(-101%); }
  .w7spl-u .w7spl-m { transform: translateX(101%); background: var(--w7spl-ink); } .w7spl-u .w7spl-m .w7spl-t { transform: translateX(-101%); }
  .w7spl-b:hover .w7spl-m, .w7spl-b:focus-visible .w7spl-m, .w7spl-b[data-demo] .w7spl-m,
  .w7spl-b:hover .w7spl-m .w7spl-t, .w7spl-b:focus-visible .w7spl-m .w7spl-t, .w7spl-b[data-demo] .w7spl-m .w7spl-t { transform: none; }
  .w7spl-b:focus-visible { outline: 3px solid var(--w7spl-wine); outline-offset: 3px; }
  .w7spl-note { margin: 22px 0 0; font-size: 14px; color: #5e564c; }
  @media (prefers-reduced-motion: reduce) { .w7spl-m, .w7spl-m .w7spl-t { transition: none; } }
</style>

<script>
(function () {
  var root = document.querySelector("[data-w7spl]");
  if (!root) return;
  var off = [];
  //BODY-START
  var STEP = 1500; // ms each button shows its second colour during the demo
  if (matchMedia("(prefers-reduced-motion: reduce)").matches) return;
  // Demo only: buttons take turns until someone points at, taps or tabs into the section.
  var btns = root.querySelectorAll(".w7spl-b"), i = 0, timer = 0, seen = true, done = false;
  function clear() { btns.forEach(function (b) { b.removeAttribute("data-demo"); }); }
  function step() { clear(); btns[i++ % btns.length].setAttribute("data-demo", ""); timer = setTimeout(step, STEP); }
  function play() { if (!done && seen && !timer) step(); }
  function stop() { clearTimeout(timer); timer = 0; clear(); }
  function hand() { done = true; stop(); }
  ["pointerenter", "focusin", "touchstart"].forEach(function (n) { root.addEventListener(n, hand, { passive: true }); off.push(function () { root.removeEventListener(n, hand); }); });
  var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; if (seen) play(); else stop(); });
  io.observe(root);
  off.push(stop, function () { io.disconnect(); });
  play();
  //BODY-END
})();
</script>

With reduced motion: Hover and focus switch each button to its second colour at once, with no slide and no demo.

Running cost: Two transforms per button on hover; a short timer only runs the demo until someone interacts.

  • Pick the incoming colour with `--w7spl-wine` and the slide length with `--w7spl-dur`.
  • Change the direction by swapping the `translateX` or `translateY` pair on `.w7spl-m` and its inner `.w7spl-t`; the two values must always be opposite.
  • Edit both copies of the label when changing button text.

Text Roll Button With Letters Rolling Up

A black pill and an outline pill for a coffee bar, where the label rolls upward and an identical copy rises from below. On the black button each letter starts a moment after the one before, so the word ripples; the outline button rolls as one piece for a calmer partner. The first button repeats the roll on its own every few seconds.

<section class="w3rol">
  <div class="w3rol-wrap">
    <p class="w3rol-kicker">Plainsong Coffee</p>
    <h2 class="w3rol-title">Order ahead, skip the queue on Mercer Street.</h2>
    <p class="w3rol-copy">Filter, espresso and a short list of pastries baked downstairs. Your cup is ready when the app says so.</p>
    <div class="w3rol-row">
      <a class="w3rol-btn w3rol-solid w3rol-demo" href="#"><span class="w3rol-sr">Start an order</span><span class="w3rol-line" aria-hidden="true"><span class="w3rol-c" style="--i:0" data-l="S">S</span><span class="w3rol-c" style="--i:1" data-l="t">t</span><span class="w3rol-c" style="--i:2" data-l="a">a</span><span class="w3rol-c" style="--i:3" data-l="r">r</span><span class="w3rol-c" style="--i:4" data-l="t">t</span><span class="w3rol-c" style="--i:5" data-l=" "> </span><span class="w3rol-c" style="--i:6" data-l="a">a</span><span class="w3rol-c" style="--i:7" data-l="n">n</span><span class="w3rol-c" style="--i:8" data-l=" "> </span><span class="w3rol-c" style="--i:9" data-l="o">o</span><span class="w3rol-c" style="--i:10" data-l="r">r</span><span class="w3rol-c" style="--i:11" data-l="d">d</span><span class="w3rol-c" style="--i:12" data-l="e">e</span><span class="w3rol-c" style="--i:13" data-l="r">r</span></span></a>
      <a class="w3rol-btn w3rol-ghost" href="#"><span class="w3rol-sr">See the menu</span><span class="w3rol-line" aria-hidden="true"><span class="w3rol-c" style="--i:0" data-l="See the menu">See the menu</span></span></a>
    </div>
  </div>
</section>
<style>
  /* Change these: button colour, delay between letters, roll speed, idle loop length. */
  .w3rol { --w3rol-ink: #0f172a; --w3rol-stagger: 22ms; --w3rol-speed: .5s; --w3rol-loop: 3.2s; }
  .w3rol { background: #fff; color: var(--w3rol-ink); padding: 80px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3rol-wrap { max-width: 48rem; margin: 0 auto; }
  .w3rol-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .25em; text-transform: uppercase; color: #475569; }
  .w3rol-title { margin: 16px 0 0; font-size: clamp(30px, 5vw, 48px); font-weight: 600; line-height: 1.15; letter-spacing: -.02em; }
  .w3rol-copy { margin: 20px 0 0; max-width: 36rem; font-size: 16px; line-height: 1.65; color: #475569; }
  .w3rol-row { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 40px; }
  .w3rol-btn { display: inline-flex; align-items: center; height: 56px; padding: 0 32px; border-radius: 999px; font-size: 16px; font-weight: 600; text-decoration: none; }
  .w3rol-solid { background: var(--w3rol-ink); color: #fff; }
  .w3rol-ghost { border: 1px solid #cbd5e1; color: var(--w3rol-ink); }
  .w3rol-btn:focus-visible { outline: 2px solid var(--w3rol-ink); outline-offset: 4px; }
  .w3rol-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .w3rol-line { display: inline-flex; overflow: hidden; line-height: 1.5em; height: 1.5em; }
  .w3rol-c { position: relative; display: inline-block; white-space: pre; transition: transform var(--w3rol-speed) cubic-bezier(.7,0,.2,1); transition-delay: calc(var(--i) * var(--w3rol-stagger)); }
  /* the duplicate sits right under each letter, hidden by the line's overflow */
  .w3rol-c::after { content: attr(data-l); position: absolute; left: 0; top: 100%; }
  .w3rol-btn:focus-visible .w3rol-c { transform: translateY(-100%); }
  @media (hover: hover) and (pointer: fine) { .w3rol-btn:hover .w3rol-c { transform: translateY(-100%); } }
  @keyframes w3rol-roll { 0%, 40% { transform: none; } 58% { transform: translateY(-100%); } 58.1%, 100% { transform: none; } }
  .w3rol-demo .w3rol-c { animation: w3rol-roll var(--w3rol-loop) cubic-bezier(.7,0,.2,1) infinite; animation-delay: calc(var(--i) * var(--w3rol-stagger)); }
  .w3rol:hover .w3rol-demo .w3rol-c, .w3rol:focus-within .w3rol-demo .w3rol-c { animation: none; }
  .w3rol[data-paused] .w3rol-c { animation-play-state: paused; }
  @media (prefers-reduced-motion: reduce) { .w3rol-c { transition: none; } .w3rol-demo .w3rol-c { animation: none; } }
</style>
<script>
  (function () {
    /* only pauses the idle loop while the section is off screen */
    var root = document.querySelector(".w3rol");
    if (!root) return;
    new IntersectionObserver(function (en) { root.toggleAttribute("data-paused", !en[0].isIntersecting); }).observe(root);
  })();
</script>

With reduced motion: Labels stay still and the idle roll on the first button never runs.

Running cost: Each letter is one translated span with its copy drawn by a pseudo-element; the only script pauses the loop off screen.

  • Set `--w3rol-stagger` (or `STAGGER` in React) to spread the ripple, and `--w3rol-speed` for each letter's roll.
  • Change `--w3rol-loop` for the idle rhythm, or remove `w3rol-demo` to stop it.
  • In the HTML version, keep each letter's `data-l` the same as its text so the copy matches.

Tilt Card With a Moving Glare Layer

A graphite membership card for a climbing gym that tips toward the mouse in 3D, with a soft white highlight sliding across its face like light on a real card. Only a few degrees of rotation are used, so it stays readable. At rest it rocks in a slow figure-of-eight, and on touch screens it keeps that slow rock since there is no pointer to follow.

<section class="w3tlt">
  <div class="w3tlt-wrap">
    <div class="w3tlt-text">
      <p class="w3tlt-kicker">Ashgrove Bouldering</p>
      <h2 class="w3tlt-title">One card for every wall in the city.</h2>
      <p class="w3tlt-copy">Unlimited visits to our three gyms, two guest passes a month and shoe hire included.</p>
    </div>
    <div class="w3tlt-stage">
      <a class="w3tlt-card" href="#" aria-label="Ashgrove all-gyms membership, 58 dollars a month, view details">
        <span class="w3tlt-lines" aria-hidden="true"></span>
        <span class="w3tlt-face" aria-hidden="true">
          <span class="w3tlt-top"><span class="w3tlt-brand">Ashgrove</span><svg viewBox="0 0 32 24"><path d="M2 22 L11 6 L17 15 L21 9 L30 22 Z"/></svg></span>
          <span><span class="w3tlt-plan">All gyms · monthly</span><span class="w3tlt-bottom"><span class="w3tlt-price">$58</span><span class="w3tlt-no">No. 0412</span></span></span>
        </span>
        <span class="w3tlt-glare" aria-hidden="true"></span>
      </a>
    </div>
  </div>
</section>
<style>
  /* Change these: page colour, accent gold, and the depth of the 3D view (perspective). */
  .w3tlt { --w3tlt-bg: #26282b; --w3tlt-gold: #d6c49a; --w3tlt-depth: 900px; }
  .w3tlt { background: var(--w3tlt-bg); color: #f1efe9; padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; }
  .w3tlt-wrap { max-width: 64rem; margin: 0 auto; display: grid; gap: 48px; align-items: center; }
  @media (min-width: 768px) { .w3tlt-wrap { grid-template-columns: 1fr 1fr; } }
  .w3tlt-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .25em; text-transform: uppercase; color: #b5b0a5; }
  .w3tlt-title { margin: 16px 0 0; font-size: clamp(30px, 4vw, 36px); font-weight: 600; line-height: 1.2; letter-spacing: -.02em; }
  .w3tlt-copy { margin: 20px 0 0; max-width: 28rem; font-size: 16px; line-height: 1.65; color: #c9c5bc; }
  .w3tlt-stage { display: flex; justify-content: center; perspective: var(--w3tlt-depth); }
  .w3tlt-card { position: relative; display: block; width: 100%; max-width: 24rem; aspect-ratio: 1.586; overflow: hidden; padding: 24px; box-sizing: border-box; border-radius: 16px; background: linear-gradient(135deg, #4a4d52, #2f3135 50%, #1b1c1f); color: #f1efe9; text-decoration: none; box-shadow: 0 30px 60px -20px rgba(0,0,0,.6), inset 0 0 0 1px rgba(255,255,255,.1); transform-style: preserve-3d; will-change: transform; }
  .w3tlt-card:focus-visible { outline: 2px solid #f1efe9; outline-offset: 6px; }
  .w3tlt-lines { position: absolute; inset: 0; opacity: .3; background: repeating-linear-gradient(115deg, rgba(255,255,255,.05) 0 2px, transparent 2px 9px); }
  .w3tlt-face { position: relative; display: flex; flex-direction: column; justify-content: space-between; height: 100%; }
  .w3tlt-top, .w3tlt-bottom { display: flex; justify-content: space-between; align-items: flex-end; }
  .w3tlt-top { align-items: flex-start; }
  .w3tlt-brand { font-size: 14px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; }
  .w3tlt-top svg { width: 32px; height: 24px; fill: none; stroke: var(--w3tlt-gold); stroke-width: 1.6; }
  .w3tlt-plan { display: block; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: #c9c5bc; }
  .w3tlt-bottom { margin-top: 4px; }
  .w3tlt-price { font-size: 24px; font-weight: 600; }
  .w3tlt-no { font-family: ui-monospace, monospace; font-size: 14px; letter-spacing: .1em; color: var(--w3tlt-gold); }
  .w3tlt-glare { position: absolute; inset: -50%; pointer-events: none; opacity: .25; background: radial-gradient(circle at 50% 50%, rgba(255,255,255,.55), rgba(255,255,255,0) 45%); }
  @media (prefers-reduced-motion: reduce) { .w3tlt-card { transform: rotateX(4deg) rotateY(-6deg) !important; will-change: auto; } .w3tlt-glare { transform: translate(-15%, -15%) !important; } }
</style>
<script>
  (function () {
    /* Change these: tilt in degrees at the card edge, and the brightest glare. */
    var MAX_TILT = 10, GLARE = 0.55;
    var root = document.querySelector(".w3tlt");
    if (!root || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
    var card = root.querySelector(".w3tlt-card"), glare = root.querySelector(".w3tlt-glare");
    var tx = 0, ty = 0, x = 0, y = 0, live = false, frame = 0, visible = true;
    function clamp(v) { return Math.max(-1, Math.min(1, v)); }
    if (matchMedia("(hover: hover) and (pointer: fine)").matches) {
      root.addEventListener("pointermove", function (e) {
        if (e.pointerType !== "mouse") return;
        var r = card.getBoundingClientRect();
        tx = clamp((e.clientX - r.left) / r.width * 2 - 1); ty = clamp((e.clientY - r.top) / r.height * 2 - 1); live = true;
      });
      root.addEventListener("pointerleave", function () { live = false; });
    }
    function tick(now) {
      /* idle demo: a slow figure-of-eight until a real mouse arrives */
      if (!live) { tx = Math.sin(now / 2100) * 0.8; ty = Math.sin(now / 1500 + 1) * 0.6; }
      x += (tx - x) * 0.08; y += (ty - y) * 0.08;
      card.style.transform = "rotateX(" + (-y * MAX_TILT).toFixed(2) + "deg) rotateY(" + (x * MAX_TILT).toFixed(2) + "deg)";
      glare.style.transform = "translate(" + (x * 30).toFixed(1) + "%," + (y * 30).toFixed(1) + "%)";
      glare.style.opacity = (GLARE * (0.35 + 0.65 * Math.min(1, Math.hypot(x, y)))).toFixed(3);
      frame = requestAnimationFrame(tick);
    }
    function play() { if (!frame && visible) frame = requestAnimationFrame(tick); }
    new IntersectionObserver(function (en) {
      visible = en[0].isIntersecting;
      if (visible) play(); else { cancelAnimationFrame(frame); frame = 0; }
    }).observe(root);
    play();
  })();
</script>

With reduced motion: The card rests at a fixed, gentle angle with a soft highlight in one corner and never follows the pointer.

Running cost: A frame loop writes two rotations, one translate and one opacity, and it stops while the section is off screen.

  • Set `MAX_TILT` for the angle at the card's edge and `GLARE` for how bright the highlight gets.
  • Change `--w3tlt-depth` (perspective) for a flatter or more dramatic tilt.

Performance notes

Transitions on transform and opacity are handled by the compositor, so even a page with dozens of hoverable cards stays smooth. Effects that seem to grow a shadow fade in a second, pre-drawn shadow layer instead of animating box-shadow, which would repaint the card every frame.

Magnetic effects measure the button once when the pointer enters, not on every move, and write a single transform per frame. When the pointer leaves, a short CSS transition returns the button to rest, so no script keeps running afterwards.

Questions

How does a magnetic button work?

On pointer move, the script takes the distance from the button's centre to the pointer, multiplies it by a small strength value and applies it as a translate. When the pointer leaves, the transform resets to zero with an easing transition, which reads as the button springing back.

Why should hover effects also use :focus-visible?

People who navigate with a keyboard never trigger :hover. Pairing each hover rule with :focus-visible gives them the same feedback, and :focus-visible avoids showing a focus style after mouse clicks in current browsers.

How do I stop hover styles sticking on touch screens?

Wrap them in @media (hover: hover) and (pointer: fine). Phones then skip the hover look, and you can give taps a brief :active state instead.

Which properties should a hover animation change?

Transform and opacity. Changing width, padding, margins or box-shadow on hover makes the browser redo layout or paint, which can make neighbouring content jump and adds work on every transition frame.

More collections: Custom Cursor Effects in CSS and JavaScript, Expanding Cards and Image Panels, Stacking Cards on Scroll. All animated buttons. Build your site free to have a full site built around them.

Product

Who It's For

Features

Resources

Company

View Sitemap