Vine wrap card: leaves grow around the card people point at

Point at the workshop card and stems climb its sides, leaves unfurl and two small gold flowers open at the top. Move away and the vines pull back, leaving a normal card.

A florist, a garden centre or a café with a courtyard often has one card on the home page that matters more than the rest: this week's workshop, the seasonal menu, the plant sale. It sits in a grid with everything else and looks just as flat. A vine wrap card gives that one card a little life. When someone points at it, tabs into it or taps it on a phone, thin stems climb its edges, leaves unfurl along them and a couple of small gold flowers open at the top. Move away and the vines pull back.

Saturday workshop

Make a winter wreath

Two hours, fresh cedar and eucalyptus, tea included. Six seats per class, all materials on the table.

Saturdays 10:00 to 12:00 · $65 per seat

Point at the card, tab to the button, or tap the card on a phone.

Live demo. It runs on exactly the code further down this page.

How it works

  1. Measure the card. The script reads the card's width and height and lays an SVG layer over it, 14 pixels larger on every side, so the vines can sit right on the border.
  2. Plan the routes. Two routes start near the bottom corners, climb the sides, turn the top corners and meet in the middle. A third creeps along part of the bottom edge. Each route is walked in 4 pixel steps with a small sine wave added, which turns straight lines into a wandering stem.
  3. Grow the stem. Each stem is one SVG path. Its stroke-dasharray equals its length, and the script slides stroke-dashoffset from the full length to zero, so the line seems to draw itself from the root.
  4. Sprout leaves and flowers. Every 26 pixels a leaf is pinned to the stem, alternating sides. It stays at zero size until the growing tip passes it, then scales up over the next 24 pixels. Flowers work the same way, just later along the stem.
  5. Stop when still. The animation loop only runs while the vines are growing or shrinking. A ResizeObserver rebuilds the routes if the card changes size, for example when a phone rotates.

The code

Three small files, plain HTML, CSS and JavaScript, with no library and no images.

HTML
<div class="vw" data-lab="vine-wrap">
  <article class="vw-card">
    <svg class="vw-vines" aria-hidden="true" focusable="false"></svg>
    <p class="vw-eyebrow">Saturday workshop</p>
    <p class="vw-title">Make a winter wreath</p>
    <p class="vw-text">Two hours, fresh cedar and eucalyptus, tea included. Six seats per class, all materials on the table.</p>
    <p class="vw-meta">Saturdays 10:00 to 12:00 &middot; $65 per seat</p>
    <button class="vw-btn" type="button">Book a seat</button>
  </article>
  <p class="vw-hint">Point at the card, tab to the button, or tap the card on a phone.</p>
  <p class="vw-status" aria-live="polite"></p>
</div>
CSS
.vw {
  display: grid;
  justify-items: center;
  gap: 14px;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 26px 22px 0;
  box-sizing: border-box;
  font-family: system-ui, sans-serif;
  color: #101a14;
}
.vw p { margin: 0 !important; }
.vw-card {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  padding: 26px 24px 24px;
  border: 1px solid #c9cec4;
  border-radius: 16px;
  background: #fff;
  text-align: left;
  box-shadow: 0 8px 22px rgba(16, 26, 20, .08);
}
/* The vines sit in an SVG layer slightly larger than the card, so they can wrap its edge. */
.vw .vw-vines {
  position: absolute;
  max-width: none;
  max-height: none;
  top: -14px;
  left: -14px;
  width: calc(100% + 28px);
  height: calc(100% + 28px);
  overflow: visible;
  pointer-events: none;
}
.vw-stem { fill: none; stroke: #2f6b45; stroke-width: 2.4; stroke-linecap: round; }
.vw-leaf { fill: #3f8a57; }
.vw-leaf.vw-dark { fill: #133621; }
.vw-petal { fill: #f4d96c; }
.vw-heart { fill: #133621; }
.vw-eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: #46534a; }
.vw .vw-title { margin: 6px 0 8px !important; font: 700 24px/1.2 system-ui, sans-serif; color: #133621; }
.vw-text { font-size: 15px; line-height: 1.5; }
.vw .vw-meta { margin-top: 10px !important; font-size: 14px; font-weight: 600; color: #46534a; }
.vw-btn {
  position: relative;
  margin-top: 16px;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  background: #133621;
  color: #f4d96c;
  font: 600 15px/1 system-ui, sans-serif;
  cursor: pointer;
}
.vw-btn:focus-visible { outline: 3px solid #f4d96c; outline-offset: 3px; }
.vw-hint { font-size: 14px; line-height: 1.4; color: #46534a; text-align: center; }
.vw-status { min-height: 1.4em; font-size: 15px; font-weight: 600; color: #133621; text-align: center; }
@media (prefers-reduced-motion: reduce) {
  .vw-card { box-shadow: none; }
}
JavaScript
(function () {
  var root = document.querySelector('[data-lab="vine-wrap"]');
  if (!root) return;
  var card = root.querySelector('.vw-card');
  var svg = root.querySelector('.vw-vines');
  var btn = root.querySelector('.vw-btn');
  var status = root.querySelector('.vw-status');
  var NS = 'http://www.w3.org/2000/svg';
  var PAD = 14;             // how far the vine layer reaches past the card edge
  var GROW_MS = 1400;       // time for the vines to grow fully
  var SHRINK_MS = 700;      // time for them to pull back
  var LEAF_GAP = 26;        // pixels of stem between leaves
  var still = window.matchMedia && matchMedia('(prefers-reduced-motion: reduce)').matches;
  var vines = [], cur = 0, target = 0, last = 0, raf = 0;
  var hover = false, focus = false, pinned = false;

  function el(name, attrs, parent) {
    var n = document.createElementNS(NS, name);
    for (var k in attrs) n.setAttribute(k, attrs[k]);
    parent.appendChild(n);
    return n;
  }

  // Walk a route of corner points, adding a gentle wave, and keep every sample.
  function sample(route, phase) {
    var pts = [], s = 0;
    for (var i = 0; i < route.length - 1; i++) {
      var a = route[i], b = route[i + 1];
      var dx = b[0] - a[0], dy = b[1] - a[1], len = Math.sqrt(dx * dx + dy * dy);
      for (var d = 0; d < len; d += 4) {
        var w = Math.sin((s + d) / 22 + phase) * 4;
        pts.push({ s: s + d, x: a[0] + dx * d / len - dy / len * w, y: a[1] + dy * d / len + dx / len * w, ang: Math.atan2(dy, dx) });
      }
      s += len;
    }
    return { pts: pts, len: s };
  }

  function build() {
    while (svg.firstChild) svg.removeChild(svg.firstChild);
    var W = card.offsetWidth + PAD * 2, H = card.offsetHeight + PAD * 2;
    var x0 = PAD, y0 = PAD, x1 = W - PAD, y1 = H - PAD, r = 14, mid = W / 2;
    svg.setAttribute('viewBox', '0 0 ' + W + ' ' + H);
    // Two vines climb the sides and meet at the top; a third creeps along the bottom.
    var routes = [
      [[x0, y1 - 8], [x0, y0 + r], [x0 + 4, y0 + 4], [x0 + r, y0], [mid - 8, y0]],
      [[x1, y1 - 8], [x1, y0 + r], [x1 - 4, y0 + 4], [x1 - r, y0], [mid + 8, y0]],
      [[x0 + 8, y1], [x0 + (x1 - x0) * 0.42, y1]]
    ];
    vines = routes.map(function (route, n) {
      var v = sample(route, n * 2);
      var d = v.pts.map(function (p, i) { return (i ? 'L' : 'M') + p.x.toFixed(1) + ' ' + p.y.toFixed(1); }).join('');
      v.stem = el('path', { d: d, 'class': 'vw-stem', 'stroke-dasharray': v.len }, svg);
      v.bits = [];
      v.pts.forEach(function (p, i) {
        var step = Math.round(LEAF_GAP / 4);
        if (i < 4 || i % step) return;
        var side = (i / step) % 2 ? 1 : -1;
        var leaf = el('path', { d: 'M0 0C4 -6 12 -7 16 0C12 7 4 6 0 0Z', 'class': 'vw-leaf' + (side > 0 ? '' : ' vw-dark') }, svg);
        v.bits.push({ node: leaf, p: p, rot: p.ang * 180 / Math.PI + side * 55, at: p.s, size: 0.8 + (i % 3) * 0.12 });
      });
      // A small gold flower near the middle and the tip of each climbing vine.
      [0.5, 0.94].forEach(function (f) {
        if (n === 2 && f > 0.6) return;
        var p = v.pts[Math.floor((v.pts.length - 1) * f)];
        var g = el('g', {}, svg);
        for (var k = 0; k < 5; k++) {
          var a = k * Math.PI * 2 / 5;
          el('circle', { cx: (Math.cos(a) * 4).toFixed(2), cy: (Math.sin(a) * 4).toFixed(2), r: 3.4, 'class': 'vw-petal' }, g);
        }
        el('circle', { cx: 0, cy: 0, r: 2.2, 'class': 'vw-heart' }, g);
        v.bits.push({ node: g, p: p, rot: 0, at: p.s + 10, size: 1.1 });
      });
      return v;
    });
    draw();
  }

  // Each part appears once the stem has grown past it.
  function draw() {
    var e = cur * cur * (3 - 2 * cur);
    vines.forEach(function (v) {
      var reach = v.len * e;
      v.stem.setAttribute('stroke-dashoffset', (v.len - reach).toFixed(1));
      v.bits.forEach(function (b) {
        var k = Math.max(0, Math.min(1, (reach - b.at) / 24)) * b.size;
        b.node.setAttribute('transform', 'translate(' + b.p.x.toFixed(1) + ' ' + b.p.y.toFixed(1) + ') rotate(' + b.rot.toFixed(0) + ') scale(' + k.toFixed(3) + ')');
      });
    });
  }

  // The loop only runs while the vines are moving.
  function tick(t) {
    var dt = Math.min(50, t - last);
    last = t;
    var step = dt / (target > cur ? GROW_MS : SHRINK_MS);
    cur = target > cur ? Math.min(target, cur + step) : Math.max(target, cur - step);
    draw();
    raf = cur !== target ? requestAnimationFrame(tick) : 0;
  }

  function update() {
    target = hover || focus || pinned ? 1 : 0;
    if (still) { cur = target; draw(); return; }
    if (!raf && cur !== target) { last = performance.now(); raf = requestAnimationFrame(tick); }
  }

  card.addEventListener('pointerenter', function (e) { if (e.pointerType !== 'touch') { hover = true; update(); } });
  card.addEventListener('pointerleave', function (e) { if (e.pointerType !== 'touch') { hover = false; update(); } });
  card.addEventListener('focusin', function () { focus = true; update(); });
  card.addEventListener('focusout', function () { focus = false; update(); });
  // On a phone a tap on the card toggles the vines; a tap anywhere else lets them go.
  card.addEventListener('pointerup', function (e) {
    if (e.pointerType === 'touch' && e.target !== btn) { pinned = !pinned; update(); }
  });
  document.addEventListener('pointerdown', function (e) {
    if (pinned && !card.contains(e.target)) { pinned = false; update(); }
  });
  btn.addEventListener('click', function () {
    pinned = true;
    update();
    status.textContent = 'Seat request noted. This is a demo, so nothing was booked.';
  });

  if (window.ResizeObserver) new ResizeObserver(build).observe(card);
  else window.addEventListener('resize', build);
  build();
})();

When to use it, and when not to

It fits businesses where growing things are the product or the mood: florists, nurseries, garden designers, tea rooms, a farm stand, a yoga studio with a lot of plants in its photos. It works best on a single card you want people to notice, such as a class sign up, a seasonal offer or a gift card panel. One card per page is plenty. If every card on the page sprouts leaves, none of them stands out and the page starts to feel busy.

It is a poor fit for anything serious or urgent, like a pharmacy notice, a payment step or a cancellation policy, where decoration gets in the way. It also does nothing for people who never hover, so the card has to work perfectly well without the vines. Here the vines are pure decoration: the SVG is aria-hidden, ignores the pointer so it never blocks a click, and the heading, text and button are ordinary HTML that screen readers and search engines read normally. If a visitor has asked their device to reduce motion, the vines appear and disappear at once instead of growing.

Make it yours

  • Speed: change GROW_MS and SHRINK_MS. Keep the shrink faster than the grow so the card settles quickly when people move on.
  • Density: raise LEAF_GAP for a sparse, tidy vine or lower it to around 18 for a lush one. The flower positions are the two numbers in the [0.5, 0.94] list.
  • Colours: the stem, the two leaf shades and the petals are set in .vw-stem, .vw-leaf, .vw-dark and .vw-petal in the CSS. Swap the gold petals for pink or white to match your own flowers.

Frequently asked questions

Does it slow the page down?

Very little. It draws a few dozen small SVG shapes once, and the animation runs only for the second or so while the vines move, then stops completely.

Can the vines cover my text or button?

No. They sit on the border of the card, and the SVG layer has pointer-events: none, so clicks always reach the button underneath. Keep about 20 pixels of padding inside the card so leaves never touch the text.

Can I use it on more than one card?

Yes, but give each copy its own data-lab value or change the script to loop over every card. On a busy page, one wrapped card is usually the right amount.

What should your website do?

Describe a feature you wish your site had. If it is useful to other owners too, we build it here as a free Lab post with a live demo and code.

We never publish your name, email or website. Privacy

More from the Website Lab

All experiments
Effects

Scratch card reveal with canvas

Drag to scratch off a foil and reveal a hidden message, built with one canvas. Works on touch screens, with a keyboard friendly reveal button.

3 min read