Tear off coupon: pull the stub to keep your discount code

Pull the gold stub down and it swings open, rips free along the perforation and leaves the code ready to copy. A tap tears it for you, so nobody has to play to get the offer.

A café runs a weekday lunch deal and puts the discount code in plain text on the menu page. It works, but nobody remembers it, and it looks like every other line on the page. A paper voucher feels different: you tear off the stub and it is yours. This coupon brings that small moment to the web. Pull the gold stub down and it swings open along the perforation, rips free and falls away, leaving the code ready to copy. A simple tap does the same thing, so nobody has to play to get the offer.

Pull the stub down to tear it off, or just tap it.

Weekday lunch voucher

20% off any bowl

Monday to Friday, 11:30 to 2:30. One per table.

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

How it works

  1. Draw the voucher. The coupon is two blocks side by side: the green body with the offer and a gold stub with a dashed left border. Two CSS masks cut half circle notches at each end of the perforation, the way real tickets are punched.
  2. Hinge the stub. The stub rotates around its bottom left corner. A custom property, --p, runs from 0 to 1, and the CSS turns it into a rotation of up to 18 degrees, so the gap opens from the top like paper giving way.
  3. Follow the pull. Pointer events track how far the finger or mouse has moved down and slightly right. The first few pixels are ignored so a tap stays a tap. Once the pull starts, both halves get a ragged clip-path edge so the line looks torn rather than cut.
  4. Tear or spring back. Past the full pull distance the stub rips free and drops out of view. Let go early and it springs back with a short hint. Let go past 70 percent and it finishes the tear for you.
  5. Hand over the code. A panel appears with the code, a copy button and a way to put the stub back. Focus moves to the copy button and a live region reads out the code.

The code

Three small files with no libraries: paste them into a page or hand them to whoever builds your site.

HTML
<div class="tc" data-lab="tear-coupon">
  <p class="tc-hint" id="tc-hint">Pull the stub down to tear it off, or just tap it.</p>
  <div class="tc-coupon">
    <div class="tc-body">
      <p class="tc-eyebrow">Weekday lunch voucher</p>
      <p class="tc-deal">20% off any bowl</p>
      <p class="tc-small">Monday to Friday, 11:30 to 2:30. One per table.</p>
    </div>
    <button class="tc-stub" type="button" aria-describedby="tc-hint">
      <span class="tc-keep">Keep this</span>
      <span class="tc-big" aria-hidden="true">20%</span>
      <span class="tc-pull">Tear to get your code</span>
    </button>
  </div>
  <div class="tc-kept" hidden>
    <p class="tc-code-line">Your code <span class="tc-code">BOWL20</span></p>
    <p class="tc-small">Show it at the counter or type it in at checkout.</p>
    <div class="tc-actions">
      <button class="tc-copy" type="button">Copy code</button>
      <button class="tc-reset" type="button">Put the stub back</button>
    </div>
  </div>
  <p class="tc-status" aria-live="polite"></p>
</div>
CSS
.tc {
  display: grid;
  justify-items: center;
  gap: 14px;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  font-family: system-ui, sans-serif;
  color: #101a14;
  text-align: center;
}
.tc p { margin: 0; }
.tc-hint { font-size: 15px; line-height: 1.4; color: #46534a; }
.tc-coupon {
  display: flex;
  width: 100%;
  min-height: 160px;
  filter: drop-shadow(0 6px 14px rgba(16, 26, 20, .16));
}
/* Half circle notches at both ends of the perforation, cut with masks. */
.tc-body {
  flex: 1;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 20px 18px 20px 22px;
  border-radius: 14px 0 0 14px;
  background: #133621;
  color: #f2f3ef;
  text-align: left;
  -webkit-mask: radial-gradient(circle 9px at 100% 0, #0000 97%, #000) top / 100% 51% no-repeat,
    radial-gradient(circle 9px at 100% 100%, #0000 97%, #000) bottom / 100% 51% no-repeat;
  mask: radial-gradient(circle 9px at 100% 0, #0000 97%, #000) top / 100% 51% no-repeat,
    radial-gradient(circle 9px at 100% 100%, #0000 97%, #000) bottom / 100% 51% no-repeat;
}
.tc-eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #f4d96c; }
.tc-deal { font-size: 24px; font-weight: 700; line-height: 1.15; }
.tc-body .tc-small { color: #c9cec4; }
.tc-small { font-size: 13px; line-height: 1.4; color: #46534a; }
.tc-stub {
  --p: 0;
  flex: 0 0 116px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  padding: 14px 10px;
  border: 0;
  border-left: 2px dashed #133621;
  border-radius: 0 14px 14px 0;
  background: #f4d96c;
  color: #133621;
  font: inherit;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  /* The stub hinges on its bottom left corner, so the gap opens from the top like real paper. */
  transform-origin: 0 100%;
  transform: rotate(calc(var(--p) * 18deg)) translateY(calc(var(--p) * 6px));
  -webkit-mask: radial-gradient(circle 9px at 0 0, #0000 97%, #000) top / 100% 51% no-repeat,
    radial-gradient(circle 9px at 0 100%, #0000 97%, #000) bottom / 100% 51% no-repeat;
  mask: radial-gradient(circle 9px at 0 0, #0000 97%, #000) top / 100% 51% no-repeat,
    radial-gradient(circle 9px at 0 100%, #0000 97%, #000) bottom / 100% 51% no-repeat;
}
.tc-stub:active { cursor: grabbing; }
.tc-stub:focus-visible { outline: 3px solid #133621; outline-offset: -6px; }
.tc-stub.is-easing { transition: transform .35s cubic-bezier(.3, 1.5, .5, 1); }
.tc-stub.is-ripping { transition: transform .4s ease-in; }
.tc-stub.is-torn { border-left-color: transparent; }
.tc-stub.is-gone {
  transition: transform .6s cubic-bezier(.5, 0, .9, .5), opacity .6s;
  transform: translate(40px, 180px) rotate(34deg);
  opacity: 0;
  pointer-events: none;
}
.tc-keep { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.tc-big { font-size: 30px; font-weight: 800; line-height: 1; }
.tc-pull { font-size: 12px; line-height: 1.3; }
.tc-kept {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border: 2px dashed #c9cec4;
  border-radius: 14px;
  background: #fff;
  animation: tc-in .4s ease-out;
}
.tc-kept[hidden] { display: none; }
.tc-code-line { font-size: 16px; font-weight: 600; }
.tc-code {
  display: inline-block;
  margin-left: 6px;
  padding: 3px 10px;
  border-radius: 6px;
  background: #f4d96c;
  color: #133621;
  font: 700 18px/1.3 ui-monospace, monospace;
  letter-spacing: .08em;
}
.tc-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tc-actions button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid #133621;
  border-radius: 999px;
  font: 600 14px/1 system-ui, sans-serif;
  cursor: pointer;
}
.tc-copy { background: #133621; color: #f4d96c; }
.tc-reset { background: #fff; color: #133621; }
.tc-actions button:focus-visible { outline: 3px solid #f4d96c; outline-offset: 2px; }
.tc-status { min-height: 1.4em; font-size: 14px; font-weight: 600; color: #133621; }
@keyframes tc-in { from { opacity: 0; transform: translateY(-8px); } }
@media (max-width: 420px) {
  .tc-deal { font-size: 20px; }
  .tc-stub { flex-basis: 96px; }
  .tc-big { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .tc-stub, .tc-stub.is-easing, .tc-stub.is-ripping { transform: none; transition: none; }
  .tc-stub.is-gone { transform: none; transition: opacity .2s; }
  .tc-kept { animation: none; }
}
JavaScript
(function () {
  var root = document.querySelector('[data-lab="tear-coupon"]');
  if (!root) return;
  var body = root.querySelector('.tc-body');
  var stub = root.querySelector('.tc-stub');
  var kept = root.querySelector('.tc-kept');
  var code = root.querySelector('.tc-code');
  var status = root.querySelector('.tc-status');
  var PULL = 110;           // pixels of pull needed to tear the stub off
  var calm = window.matchMedia('(prefers-reduced-motion: reduce)');
  var startX = 0, startY = 0, p = 0, dragging = false, moved = false, done = false;

  // A ragged edge for both halves, so the paper looks torn rather than cut.
  function jag(side) {
    var pts = [], i, y, a;
    for (i = 0; i <= 16; i++) {
      y = (i / 16 * 100).toFixed(1) + '%';
      a = (i % 2 ? 5 : 1) + (i * 7 % 3);
      pts.push(side === 'right' ? 'calc(100% - ' + a + 'px) ' + y : a + 'px ' + y);
    }
    return side === 'right'
      ? 'polygon(0 0, ' + pts.join(', ') + ', 0 100%)'
      : 'polygon(' + pts.join(', ') + ', 100% 100%, 100% 0)';
  }

  function setP(v) { p = Math.max(0, Math.min(1, v)); stub.style.setProperty('--p', p.toFixed(3)); }

  function startTear() {
    stub.classList.add('is-torn');
    body.style.clipPath = jag('right');
    stub.style.clipPath = jag('left');
  }

  function finish() {
    if (done) return;
    done = true;
    stub.classList.remove('is-ripping', 'is-easing');
    stub.classList.add('is-gone');
    kept.hidden = false;
    status.textContent = 'Torn off. Your code is ' + code.textContent + '.';
    // Hand focus to the copy button once the stub is gone, so keyboard users are not left behind.
    setTimeout(function () { kept.querySelector('.tc-copy').focus({ preventScroll: true }); }, calm.matches ? 0 : 450);
  }

  // A tap, Enter or Space tears it for you: dragging is the fun part, never the only way.
  function autoTear() {
    if (done) return;
    startTear();
    if (calm.matches) { finish(); return; }
    stub.classList.add('is-ripping');
    setP(1);
    setTimeout(finish, 380);
  }

  stub.addEventListener('pointerdown', function (e) {
    if (done) return;
    dragging = true; moved = false;
    startX = e.clientX; startY = e.clientY;
    stub.classList.remove('is-easing');
    stub.setPointerCapture(e.pointerId);
  });
  stub.addEventListener('pointermove', function (e) {
    if (!dragging) return;
    var dx = e.clientX - startX, dy = e.clientY - startY;
    if (!moved && Math.abs(dx) + Math.abs(dy) < 6) return;
    if (!moved) { moved = true; startTear(); }
    // Pulling down (and a little to the right) is what opens the tear.
    setP((dy * 0.85 + dx * 0.5) / PULL);
    if (p >= 1) { dragging = false; finish(); }
  });
  function release() {
    if (!dragging) return;
    dragging = false;
    if (!moved || done) return;
    if (p > 0.7) { autoTear(); return; }
    stub.classList.add('is-easing');
    setP(0);
    status.textContent = 'Almost. Pull a little further, or just tap the stub.';
  }
  stub.addEventListener('pointerup', release);
  stub.addEventListener('pointercancel', release);
  stub.addEventListener('click', function () { if (!moved) autoTear(); moved = false; });
  stub.addEventListener('contextmenu', function (e) { e.preventDefault(); });

  root.querySelector('.tc-copy').addEventListener('click', function () {
    var text = code.textContent;
    if (navigator.clipboard && navigator.clipboard.writeText) {
      navigator.clipboard.writeText(text).then(function () { status.textContent = 'Copied ' + text + '.'; },
        function () { status.textContent = 'Copy blocked here. The code is ' + text + '.'; });
    } else {
      status.textContent = 'The code is ' + text + '.';
    }
  });

  root.querySelector('.tc-reset').addEventListener('click', function () {
    done = false;
    kept.hidden = true;
    stub.className = 'tc-stub';
    stub.style.clipPath = body.style.clipPath = '';
    setP(0);
    status.textContent = 'The stub is back on.';
    stub.focus({ preventScroll: true });
  });
})();

When to use it, and when not to

It fits offers that you want people to notice and keep: a lunch deal on a menu page, a first visit discount for a salon, a loyalty reward in an email landing page, a promotion on a printed flyer's QR code page. The tear gives a single, clear moment where the code changes hands, which is easier to remember than a line of small print.

It is the wrong choice for codes people need quickly and often, such as a staff discount or a checkout field, where any extra step is friction. Do not hide prices or terms behind the tear either; the offer and its conditions should be readable before anyone touches it. Dragging can be hard for people with limited hand movement, which is why a tap, Enter or Space tears it automatically, and the reduced motion setting skips the swing and simply shows the code.

Make it yours

  • How far to pull: change PULL in the script. Around 90 to 140 pixels feels deliberate on both a phone and a laptop.
  • The offer and code: edit the text in .tc-body and the value inside .tc-code; the messages read the code from the page, so there is only one place to change it.
  • Look: the stub width is flex: 0 0 116px on .tc-stub, the swing is the 18deg in its transform, and the notch size is the 9px circle in both masks.

Frequently asked questions

Does it work on phones?

Yes. It uses pointer events and turns off touch scrolling on the stub only, so the page still scrolls normally everywhere else and a pull on the stub is never mistaken for a scroll.

Is the code hidden from search engines or screen readers?

The code sits in the page as normal HTML inside a hidden panel, so it is not a secret. Treat the tear as a nice moment, not a security measure, and use single use codes from your booking or shop system if that matters.

Can I show different codes to different visitors?

Yes. Fill .tc-code from your server or shop platform when the page loads. The script reads the code from the page at the moment of the tear, so nothing else needs to change.

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