Skip to the content

Tear-off

Any element gets a perforated line and a strip to tear off.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

    The box that carries data-tear-off has to hug the front: no padding, no border, nothing else inside but the two faces. The layout of the front has to agree with data-tear-off-strip: the script cuts where the setting says. And nothing close around the element may clip it with overflow: hidden, the strip leaves its box.
  3. Add custom JS

  4. Use it on your own elements

    Custom attributes
    Select the element on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-tear-off Marks an element with a strip to tear off: a box that hugs the element and holds nothing else. It takes no value: leave the value field empty. It carries the settings. Put it around any element of the page, as many as you like; each one tears on its own.
    data-tear-off-front On the element itself, whole, strip included: a coupon, a ticket, a card, a picture. It takes no value. It decides the size, and the script cuts it where the side and strip settings say. Without it nothing is mounted, and the console says so. [ Required ]
    data-tear-off-under On the face that shows where the strip was, after the front: a code, a price, a link. It takes no value. The stylesheet lays it behind the strip and it is out of reach until the strip is off. Without it the page behind the element shows where the strip was. [ Optional ]
    data-tear-off-label On the element, with a few words as its value: what a screen reader says for the button that tears the strip. Without it the button says Tear off the strip. [ Optional ]
    data-tear-off-back-label On the element, with a few words as its value: what a screen reader says for the same button once the strip is off. Without it the button says Put the strip back. [ Optional ]
    data-tear-off-state Written by the engine on the element: idle when whole, tearing while the line gives, part when a tear was left in part, loose when the strip is free in the hand, falling, torn, and returning on the way back. Never written by hand. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same element. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-tear-off-back-color auto Colour of the back of the paper, the side the strip shows as it turns over in its fall. Options: auto, the front's own background colour mixed with paper white, and paper white alone under a front with no background; or any CSS colour. Taken out of this block, --tear-off-back on the element takes over.
    data-tear-off-side right Which side of the element is the strip, which also turns the line. Options: right and left, an upright line and a strip beside it; top and bottom, a level line and a strip above or below it.
    data-tear-off-strip 30% Depth of the strip, from that side of the element to the line, any CSS unit or a percentage of the element.
    data-tear-off-hole clamp(3px, 0.32vw, 5px) Width of one hole of the line, any CSS unit.
    data-tear-off-gap clamp(9px, 0.9vw, 14px) Distance from the middle of one hole to the next, any CSS unit; the script and the stylesheet fit a whole number of them in the line.
    data-tear-off-ragged 0.5 Size of the teeth the torn edge keeps between two holes, 0 to 1.
    data-tear-off-seed 7 Which torn edge is drawn, a whole number.
    data-tear-off-from pull The end of the line that gives first. Options: pull, the end nearer to where the strip was taken; start, the top of an upright line or the left of a level one; end, the other. A key always tears from start unless end is set.
    data-tear-off-shadow 0.5 Strength of the shadow the torn length casts on the page, 0 to 1.
    data-tear-off-threshold 0.8 Share of the line torn past which letting go finishes the tear, 0 to 1.
    data-tear-off-release rest What letting go before that does. Options: rest, the torn length springs back against what still holds and stays a hair open; hold, it stays at the angle it was left at; back, the tear closes again, hole by hole.
    data-tear-off-put-back true Whether the key, on a strip already torn off, puts it back. Options: true, Enter or Space puts the strip back; false, a strip torn off is gone for good, and only putBack() from a script brings it back.

What it does

Tear-off is a cursor animation for Webflow and vanilla JavaScript, with no library. Also called tear off coupon effect, perforated ticket tear animation or tear away ticket stub.

Any element gets a perforated line and a strip to tear off. Take the strip and pull it away from the rest: the line gives bridge by bridge from the end you pull from, at the pace of the hand, the torn length bends off the page and casts a shadow, and both sides of the tear show the same ragged edge, small teeth between the half holes, drawn from a seed. Let go early and what has torn stays torn, the strip resting against what still holds. Pull past the last hole and the strip comes free, follows the hand, and falls away when released, turning over to show its back. What is left is the stub with its torn edge and a second face of your own where the strip was: a code, a price, a link that can be clicked. The holes are a mask on the page's own element and the tear is a clip-path on it: nothing is turned into a bitmap, so the text stays sharp on any screen, at any size, on an element turned on the page. Each strip is one Tab stop, Enter or Space tears it off and puts it back. Under reduced motion the strip is simply there or gone. Without the script the element is whole and the second face is a plain block after it. No library, no canvas, no picture.

Updated

Questions

Put data-tear-off on a box that hugs the coupon, data-tear-off-front on the coupon itself, strip included, and data-tear-off-under on the code that shows where the strip was. data-tear-off-side says which side is the strip, right by default, and data-tear-off-strip how deep it is, 30% by default. The code is out of reach until the strip is off, then it can be read, selected and clicked.

No. The holes are a CSS mask on the page's own element and the tear is a clip-path on it, so nothing is turned into a bitmap and the text stays sharp at any size. The ragged edge, small teeth between the half holes, is drawn from data-tear-off-seed, with data-tear-off-ragged for the size of the teeth.

What has torn stays torn, the strip resting against what still holds: that is data-tear-off-release="rest", the default, and back closes the tear again instead. Past threshold, 0.8 of the line by default, a release finishes the tear. Pulled past the last hole, the strip comes free, follows the hand and falls away, turning over to show its back.

Yes. Each strip is one Tab stop, a real button laid over it: Enter or Space tears it off and the same key puts it back. With data-tear-off-put-back="false" the button is disabled once the strip is gone and the focus moves to the face underneath, so what was found is read at once. From a script, tear() and putBack() do the same.

Without the script the element is whole, with no holes, and the face underneath is a plain block right after it, so the code or the link is still there to read and to click. Under prefers-reduced-motion there is no pull, no bend and no fall: a click on the strip, or the key, takes it off at once.