Tear-off ticket call to action
A closing call to action shaped like a ticket: pull the stub down, the perforation rips hole by hole, the stub falls away spinning and your invite code is revealed with a stamp.
"use client";
import { useRef, useState, type CSSProperties, type PointerEvent } from "react";
import "./tear-ticket-cta.css";
/**
* TearTicketCta: a closing call to action shaped like a ticket you tear off.
* - Pull the stub down (or press the button): the paper bends, the perforation rips step by step
* along the dotted line, and past halfway the stub comes free and falls away, spinning.
* - What was printed under the stub (your code or next step) is revealed with a small stamp.
*/
export function TearTicketCta({
eyebrow = "Early access",
title,
text,
code,
theme = "dark",
}: {
eyebrow?: string;
title: string;
text: string;
/** What is revealed once the stub is torn off. */
code: string;
theme?: "light" | "dark";
}) {
const [pull, setPull] = useState(0);
const [torn, setTorn] = useState(false);
const start = useRef<number | null>(null);
const holes = 18;
const down = (e: PointerEvent<HTMLDivElement>) => {
if (torn) return;
start.current = e.clientY;
e.currentTarget.setPointerCapture(e.pointerId);
};
const move = (e: PointerEvent<HTMLDivElement>) => {
if (start.current === null) return;
const k = Math.max(0, Math.min(1, (e.clientY - start.current) / 160));
setPull(k);
if (k >= 1) {
start.current = null;
setTorn(true);
}
};
const up = () => {
if (start.current === null) return;
start.current = null;
if (pull > 0.55) setTorn(true);
else setPull(0);
};
const ripped = torn ? holes : Math.floor(pull * 1.6 * holes);
return (
<section
className="gu-tear"
data-theme={theme}
aria-labelledby="gu-tear-title"
>
<div
className="gu-tear__ticket"
data-torn={torn}
style={{ "--pull": pull } as CSSProperties}
>
<div className="gu-tear__main">
<p className="gu-tear__eyebrow">{eyebrow}</p>
<h2 id="gu-tear-title">{title}</h2>
<p className="gu-tear__text">{text}</p>
<div className="gu-tear__reveal" aria-live="polite">
{torn ? (
<>
<span className="gu-tear__stamp" aria-hidden="true">
Yours
</span>
<span className="gu-tear__label">Your invite code</span>
<strong className="gu-tear__code">{code}</strong>
</>
) : (
<span className="gu-tear__label">
Tear off the stub to get your invite code
</span>
)}
</div>
</div>
<div className="gu-tear__perf" aria-hidden="true">
{Array.from({ length: holes }, (_, i) => (
<i
key={i}
data-ripped={i < ripped}
style={{ "--i": i } as CSSProperties}
/>
))}
</div>
<div
className="gu-tear__stub"
onPointerDown={down}
onPointerMove={move}
onPointerUp={up}
onPointerCancel={up}
aria-hidden="true"
>
<span className="gu-tear__grip">Pull down to tear</span>
<span className="gu-tear__barcode">
{Array.from({ length: 34 }, (_, i) => (
<b
key={i}
style={{ "--w": ((i * 7) % 4) + 1 } as CSSProperties}
/>
))}
</span>
<span className="gu-tear__no">No. 004218</span>
</div>
</div>
{!torn && (
<button
type="button"
className="gu-tear__btn"
onClick={() => setTorn(true)}
>
Tear it off
</button>
)}
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Tear-off ticket call to action
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A closing call-to-action section shaped like a paper ticket. The cream top part holds the headline; an orange stub with a barcode hangs below a dotted perforation. Pulling the stub down bends it away, rips the perforation hole by hole, and past halfway (or at the full 160px) the stub tears free and falls off the page spinning. The ticket jolts, gets a ragged torn edge, and the invite code that was hidden is revealed with a rubber-stamp "Yours".
## Layout and look
- Section: #0e0e10 (light: #f3eee3) with an orange glow behind the ticket, centred, generous padding.
- Ticket max 520px with a big drop shadow. Top: paper #f3eee3 (light: #fffdf8), radius 22px top, padding 34px, two semicircle notches (14px) cut at the bottom corners with CSS masks. Eyebrow 14px bold orange, headline 32–52px weight 900, 17px text at 75%.
- A dashed box inside shows "Tear off the stub to get your invite code", later the code (30px weight 900, wide letter spacing).
- Perforation: 18 small holes (8px circles in the page colour) across the join.
- Stub: orange #ff5a1f, matching notches on top, "↓ Pull down to tear" (the arrow nudges), a ticket number, and a barcode of 34 ink bars of varying width.
- Under the ticket a 48px outline pill button "Tear it off".
## Behavior and motion
1. The ticket swings in on load (40px up, −6° rotation, spring).
2. Drag the stub: pull = clamp(dy / 160, 0, 1). The stub moves down pull × 26px, rotates pull × 7°, and tilts back with perspective(600px) rotateX(−pull × 28°). Holes rip left to right: the first floor(pull × 1.6 × 18) holes stretch into slots.
3. Release under 55%: springs back. Over 55% or reaching 100%: torn. The stub falls with an accelerating curve (sideways drift, rotating to 70°, off the bottom), the top part shakes once, gets a zig-zag torn bottom edge (clip-path) and the code fades in from wide blurred letters; the stamp slams in from 2.6× scale after 0.6s.
## Accessibility
- The stub is aria-hidden; the real control is the "Tear it off" button. The reveal area is aria-live so the code is announced.
- prefers-reduced-motion: no fall, no shake; the stub simply disappears and the code shows.
## Props
eyebrow, title, text, code (revealed text), theme.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### TearTicketCta.tsx
```tsx
"use client";
import { useRef, useState, type CSSProperties, type PointerEvent } from "react";
import "./tear-ticket-cta.css";
/**
* TearTicketCta: a closing call to action shaped like a ticket you tear off.
* - Pull the stub down (or press the button): the paper bends, the perforation rips step by step
* along the dotted line, and past halfway the stub comes free and falls away, spinning.
* - What was printed under the stub (your code or next step) is revealed with a small stamp.
*/
export function TearTicketCta({
eyebrow = "Early access",
title,
text,
code,
theme = "dark",
}: {
eyebrow?: string;
title: string;
text: string;
/** What is revealed once the stub is torn off. */
code: string;
theme?: "light" | "dark";
}) {
const [pull, setPull] = useState(0);
const [torn, setTorn] = useState(false);
const start = useRef<number | null>(null);
const holes = 18;
const down = (e: PointerEvent<HTMLDivElement>) => {
if (torn) return;
start.current = e.clientY;
e.currentTarget.setPointerCapture(e.pointerId);
};
const move = (e: PointerEvent<HTMLDivElement>) => {
if (start.current === null) return;
const k = Math.max(0, Math.min(1, (e.clientY - start.current) / 160));
setPull(k);
if (k >= 1) {
start.current = null;
setTorn(true);
}
};
const up = () => {
if (start.current === null) return;
start.current = null;
if (pull > 0.55) setTorn(true);
else setPull(0);
};
const ripped = torn ? holes : Math.floor(pull * 1.6 * holes);
return (
<section
className="gu-tear"
data-theme={theme}
aria-labelledby="gu-tear-title"
>
<div
className="gu-tear__ticket"
data-torn={torn}
style={{ "--pull": pull } as CSSProperties}
>
<div className="gu-tear__main">
<p className="gu-tear__eyebrow">{eyebrow}</p>
<h2 id="gu-tear-title">{title}</h2>
<p className="gu-tear__text">{text}</p>
<div className="gu-tear__reveal" aria-live="polite">
{torn ? (
<>
<span className="gu-tear__stamp" aria-hidden="true">
Yours
</span>
<span className="gu-tear__label">Your invite code</span>
<strong className="gu-tear__code">{code}</strong>
</>
) : (
<span className="gu-tear__label">
Tear off the stub to get your invite code
</span>
)}
</div>
</div>
<div className="gu-tear__perf" aria-hidden="true">
{Array.from({ length: holes }, (_, i) => (
<i
key={i}
data-ripped={i < ripped}
style={{ "--i": i } as CSSProperties}
/>
))}
</div>
<div
className="gu-tear__stub"
onPointerDown={down}
onPointerMove={move}
onPointerUp={up}
onPointerCancel={up}
aria-hidden="true"
>
<span className="gu-tear__grip">Pull down to tear</span>
<span className="gu-tear__barcode">
{Array.from({ length: 34 }, (_, i) => (
<b
key={i}
style={{ "--w": ((i * 7) % 4) + 1 } as CSSProperties}
/>
))}
</span>
<span className="gu-tear__no">No. 004218</span>
</div>
</div>
{!torn && (
<button
type="button"
className="gu-tear__btn"
onClick={() => setTorn(true)}
>
Tear it off
</button>
)}
</section>
);
}
```
### tear-ticket-cta.css
```css
.gu-tear {
--bg: #0e0e10;
--paper: #f3eee3;
--ink: #0e0e10;
--accent: #ff5a1f;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
display: grid;
justify-items: center;
gap: 22px;
padding: clamp(56px, 9vw, 120px) 20px;
background:
radial-gradient(60% 50% at 50% 30%, rgb(255 90 31 / 0.22), transparent 70%),
var(--bg);
font-family: ui-sans-serif, system-ui, sans-serif;
overflow: hidden;
}
.gu-tear[data-theme="light"] {
--bg: #f3eee3;
--paper: #fffdf8;
}
.gu-tear__ticket {
--pull: 0;
position: relative;
width: min(100%, 520px);
filter: drop-shadow(0 30px 40px rgb(0 0 0 / 0.4));
animation: gu-tear-in 1s var(--spring) backwards;
}
@keyframes gu-tear-in {
from {
opacity: 0;
translate: 0 40px;
rotate: -6deg;
}
}
.gu-tear__main {
position: relative;
padding: 34px 34px 28px;
border-radius: 22px 22px 0 0;
background: var(--paper);
color: var(--ink);
/* Notches cut into both sides where the perforation starts. */
-webkit-mask:
radial-gradient(circle 14px at 0 100%, #0000 98%, #000) left,
radial-gradient(circle 14px at 100% 100%, #0000 98%, #000) right;
-webkit-mask-size: 51% 100%;
-webkit-mask-repeat: no-repeat;
mask:
radial-gradient(circle 14px at 0 100%, #0000 98%, #000) left / 51% 100%
no-repeat,
radial-gradient(circle 14px at 100% 100%, #0000 98%, #000) right / 51% 100%
no-repeat;
}
.gu-tear__eyebrow {
margin: 0;
font-size: 14px;
font-weight: 700;
color: var(--accent);
}
.gu-tear__main h2 {
margin: 6px 0 0;
font-size: clamp(32px, 6vw, 52px);
font-weight: 900;
letter-spacing: -0.045em;
line-height: 0.98;
}
.gu-tear__text {
margin: 12px 0 0;
font-size: 17px;
line-height: 1.5;
opacity: 0.75;
}
.gu-tear__reveal {
position: relative;
display: grid;
gap: 2px;
margin-top: 22px;
padding: 16px 18px;
border-radius: 14px;
border: 1.5px dashed rgb(14 14 16 / 0.25);
}
.gu-tear__label {
font-size: 13px;
font-weight: 600;
opacity: 0.65;
}
.gu-tear__code {
font-size: 30px;
font-weight: 900;
letter-spacing: 0.08em;
animation: gu-tear-code 0.8s 0.2s var(--ease) backwards;
}
@keyframes gu-tear-code {
from {
opacity: 0;
letter-spacing: 0.5em;
filter: blur(6px);
}
}
.gu-tear__stamp {
position: absolute;
right: 14px;
top: 50%;
padding: 4px 12px;
border: 3px solid var(--accent);
border-radius: 8px;
color: var(--accent);
font-size: 20px;
font-weight: 900;
text-transform: uppercase;
letter-spacing: 0.08em;
rotate: -12deg;
translate: 0 -50%;
animation: gu-tear-stamp 0.5s 0.6s cubic-bezier(0.5, 0, 0.75, 0) backwards;
}
@keyframes gu-tear-stamp {
from {
scale: 2.6;
opacity: 0;
}
}
/* The perforation: little holes that rip open one by one. */
.gu-tear__perf {
position: relative;
display: flex;
justify-content: space-between;
height: 0;
padding: 0 22px;
z-index: 2;
}
.gu-tear__perf i {
width: 8px;
height: 8px;
margin-top: -4px;
border-radius: 50%;
background: var(--bg);
transition:
scale 0.25s var(--spring),
border-radius 0.25s;
}
.gu-tear__perf i[data-ripped="true"] {
scale: 1.7 1.1;
border-radius: 40%;
}
.gu-tear__stub {
position: relative;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 8px 16px;
padding: 22px 34px 26px;
border-radius: 0 0 22px 22px;
background: var(--accent);
color: var(--ink);
cursor: grab;
touch-action: none;
user-select: none;
transform-origin: 50% 0;
-webkit-mask:
radial-gradient(circle 14px at 0 0, #0000 98%, #000) left,
radial-gradient(circle 14px at 100% 0, #0000 98%, #000) right;
-webkit-mask-size: 51% 100%;
-webkit-mask-repeat: no-repeat;
mask:
radial-gradient(circle 14px at 0 0, #0000 98%, #000) left / 51% 100%
no-repeat,
radial-gradient(circle 14px at 100% 0, #0000 98%, #000) right / 51% 100%
no-repeat;
/* As you pull, the stub bends away from the tear, lifting more on the side that rips first. */
translate: 0 calc(var(--pull) * 26px);
rotate: calc(var(--pull) * 7deg);
transform: perspective(600px) rotateX(calc(var(--pull) * -28deg));
transition:
translate 0.5s var(--spring),
rotate 0.5s var(--spring),
transform 0.5s var(--spring);
}
.gu-tear__stub:active {
cursor: grabbing;
transition-duration: 0.08s;
}
.gu-tear__grip {
font-size: 15px;
font-weight: 800;
}
.gu-tear__grip::before {
content: "↓ ";
display: inline-block;
animation: gu-tear-nudge 1.6s ease-in-out infinite;
}
@keyframes gu-tear-nudge {
50% {
translate: 0 4px;
}
}
.gu-tear__no {
grid-column: 1;
font-size: 12px;
font-weight: 700;
opacity: 0.7;
}
.gu-tear__barcode {
grid-row: span 2;
display: flex;
align-items: stretch;
gap: 2px;
height: 44px;
}
.gu-tear__barcode b {
width: calc(var(--w) * 1.4px);
background: var(--ink);
}
.gu-tear__ticket[data-torn="true"] .gu-tear__stub {
animation: gu-tear-fall 1.3s cubic-bezier(0.5, 0, 0.75, 0) forwards;
pointer-events: none;
}
@keyframes gu-tear-fall {
0% {
translate: 0 30px;
rotate: 8deg;
}
20% {
translate: 30px 20px;
rotate: 14deg;
}
100% {
translate: 120px 120vh;
rotate: 70deg;
opacity: 0.6;
}
}
.gu-tear__ticket[data-torn="true"] .gu-tear__perf i {
opacity: 0;
transition: opacity 0.4s 0.2s;
}
.gu-tear__ticket[data-torn="true"] .gu-tear__main {
border-radius: 22px;
-webkit-mask: none;
mask: none;
animation: gu-tear-shake 0.5s var(--ease);
/* A torn, slightly ragged bottom edge. */
clip-path: polygon(
0 0,
100% 0,
100% 100%,
95% 99%,
90% 100%,
85% 99%,
80% 100%,
75% 99%,
70% 100%,
65% 99%,
60% 100%,
55% 99%,
50% 100%,
45% 99%,
40% 100%,
35% 99%,
30% 100%,
25% 99%,
20% 100%,
15% 99%,
10% 100%,
5% 99%,
0 100%
);
}
@keyframes gu-tear-shake {
30% {
translate: 0 -6px;
rotate: -1deg;
}
60% {
translate: 0 2px;
rotate: 0.5deg;
}
}
.gu-tear__btn {
min-height: 48px;
padding: 0 22px;
border: 1.5px solid rgb(243 238 227 / 0.5);
border-radius: 999px;
background: none;
color: #f3eee3;
font-family: inherit;
font-size: 15px;
font-weight: 700;
cursor: pointer;
transition:
background-color 0.3s,
color 0.3s;
}
.gu-tear[data-theme="light"] .gu-tear__btn {
color: #0e0e10;
border-color: rgb(14 14 16 / 0.4);
}
.gu-tear__btn:hover {
background: var(--accent);
border-color: var(--accent);
color: #0e0e10;
}
.gu-tear__btn:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 3px;
}
@media (prefers-reduced-motion: reduce) {
.gu-tear *,
.gu-tear *::before,
.gu-tear *::after {
animation-duration: 0.01ms !important;
animation-delay: 0ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
.gu-tear__ticket[data-torn="true"] .gu-tear__stub {
opacity: 0;
}
}
```
You might also want
Next piece: Trail that draws itselfBento features grid
Templates, intermediate
Changelog timeline
Templates, intermediate
How it works, sticky scenes
Templates, intermediate