Let’s create a Gift Box Unboxing Card using HTML, CSS, and JavaScript – a 3D gift box with a satin ribbon and a name tag that shakes when you tap it, lifts its lid, pops gold confetti and sends a greeting card flying out to reveal a personal message.
- HTML: Create the 3D box from separate faces (outer walls, inner walls, lid and a flat satin bow), the name tag, the greeting card with its front and back, the action buttons and a small form to make your own card.
- CSS: Style the box with real 3D transforms, a soft paper grain, a satin ribbon and a warm light inside. Add the shake, lid lift, card rise and flip animations, and keep the layout clean on any screen size.
- JavaScript: Control the unboxing step by step, move the card smoothly from inside the box to the front, run a confetti system with real paper physics, and read the names and message from the link so anyone can send their own gift.
This project teaches how to build an interactive 3D gift box unboxing card using HTML, CSS, and JavaScript by combining CSS 3D transforms, keyframe animations, a canvas confetti engine and personal links made with URL parameters.
HTML :
HTML: Creates the structure of the gift card, including the 3D box faces, the inner walls and floor light, the flat satin bow, the name tag, the greeting card, the two confetti canvases and the create your own form.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gift Box Unboxing Card</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..600;1,9..144,300..500&family=Inter:wght@400;500&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- confetti behind the box and card -->
<canvas id="confettiBack" aria-hidden="true"></canvas>
<main class="stage" id="stage">
<div class="intro">
<p class="eyebrow">A gift for</p>
<h1 class="intro-name" id="introName">Alexa</h1>
</div>
<div class="glow" aria-hidden="true"></div>
<!-- greeting card (front + back) -->
<div class="card" id="card" aria-label="Greeting card. Tap to flip">
<div class="card-inner">
<div class="card-face card-front">
<div class="seal" id="seal">S</div>
<p class="eyebrow">A note for</p>
<h2 class="card-to" id="cardTo">Alexa</h2>
<span class="rule" aria-hidden="true"></span>
<p class="card-hint">Tap to read</p>
</div>
<div class="card-face card-back">
<div class="letter" id="letter">
<p class="dear">Dear <span id="dearTo">Alexa</span>,</p>
<p class="msg" id="msg"></p>
<p class="sign">
<span class="sign-label">With love,</span>
<span class="sign-name" id="fromName">Stella</span>
</p>
</div>
<p class="letter-date" id="dateText"></p>
</div>
</div>
</div>
<!-- 3D gift box -->
<button class="gift-wrap" id="gift" aria-label="Open the gift">
<div class="floater">
<div class="shaker">
<div class="gift">
<div class="box">
<div class="face side front">
<div class="tag" aria-hidden="true">
<span class="tag-string"></span>
<span class="tag-card"><span class="tag-hole"></span><span id="tagTo">Alexa</span></span>
</div>
</div>
<div class="face side back"></div>
<div class="face side left"></div>
<div class="face side right"></div>
<div class="face bottom"></div>
<!-- inside of the box -->
<div class="face wall in-front"></div>
<div class="face wall in-back"></div>
<div class="face wall in-left"></div>
<div class="face wall in-right"></div>
<div class="face floor-light"></div>
</div>
<!-- the card while it is still inside the box -->
<div class="mini" id="mini" aria-hidden="true">
<div class="mini-card">
<div class="seal" id="miniSeal">S</div>
<p class="eyebrow">A note for</p>
<p class="card-to" id="miniTo">Alexa</p>
<span class="rule"></span>
</div>
</div>
<div class="lid">
<div class="face lside front"></div>
<div class="face lside back"></div>
<div class="face lside left"></div>
<div class="face lside right"></div>
<div class="face ltop"></div>
<div class="face lunder"></div>
<!-- flat satin bow -->
<div class="face bow" aria-hidden="true">
<svg viewBox="0 0 208 208">
<defs>
<linearGradient id="satin" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#b49a72" />
<stop offset="0.45" stop-color="#f3e8d2" />
<stop offset="0.6" stop-color="#d8c3a0" />
<stop offset="1" stop-color="#a88c63" />
</linearGradient>
<linearGradient id="satinDark" x1="0" y1="0" x2="1" y2="0">
<stop offset="0" stop-color="#8f7550" />
<stop offset="1" stop-color="#c2a77d" />
</linearGradient>
</defs>
<path d="M98 110 L66 168 L76 164 L80 176 L108 114 Z" fill="url(#satin)" />
<path d="M110 110 L142 168 L132 164 L128 176 L100 114 Z" fill="url(#satin)" />
<path d="M104 104 C84 72 40 66 34 94 C30 118 70 130 104 106 Z" fill="url(#satin)" />
<path d="M104 104 C124 72 168 66 174 94 C178 118 138 130 104 106 Z" fill="url(#satin)" />
<path d="M104 105 C90 90 62 86 52 98 C66 104 86 108 104 105 Z" fill="url(#satinDark)" opacity="0.75" />
<path d="M104 105 C118 90 146 86 156 98 C142 104 122 108 104 105 Z" fill="url(#satinDark)" opacity="0.75" />
<rect x="94" y="93" width="20" height="24" rx="6" fill="url(#satin)" stroke="#a88c63" stroke-opacity="0.5" />
</svg>
</div>
</div>
</div>
</div>
</div>
</button>
<div class="shadow" aria-hidden="true"></div>
<p class="hint"><span class="hint-dot" aria-hidden="true"></span>Tap the box to open</p>
<div class="actions">
<button class="btn secondary" id="replayBtn">
<svg viewBox="0 0 24 24"><path d="M4.5 12a7.5 7.5 0 1 0 2.2-5.3M4.5 4.5V8H8" /></svg>
Replay
</button>
<button class="btn primary" id="makeBtn">Create your own</button>
</div>
</main>
<!-- confetti in front of everything -->
<canvas id="confetti" aria-hidden="true"></canvas>
<!-- create your own card -->
<dialog class="maker" id="maker">
<form method="dialog">
<div class="maker-head">
<h3>Create a gift</h3>
<button type="button" class="close-btn" id="closeBtn" aria-label="Close">
<svg viewBox="0 0 24 24"><path d="M7 7l10 10M17 7L7 17" /></svg>
</button>
</div>
<p class="maker-sub">Write a short note, copy the link and send it to someone.</p>
<div class="field-row">
<label class="field">To
<input type="text" id="fTo" maxlength="22" placeholder="Their name" />
</label>
<label class="field">From
<input type="text" id="fFrom" maxlength="22" placeholder="Your name" />
</label>
</div>
<label class="field">Message
<textarea id="fMsg" maxlength="160" rows="4" placeholder="Write your message"></textarea>
<span class="count" id="count">0 / 160</span>
</label>
<div class="maker-actions">
<button type="button" class="btn secondary" id="previewBtn">Preview</button>
<button type="button" class="btn primary" id="copyBtn">Copy link</button>
</div>
<p class="status" id="status" role="status"></p>
</form>
</dialog>
<script src="script.js"></script>
</body>
</html>
CSS :
CSS: Styles the scene and builds the 3D box with transforms, then animates the shake, the lid lifting off, the card rising out of the box, the card flip and the message fading in word by word.
/* ================= Tokens ================= */
:root {
--bg: #efebe5;
--bg-deep: #e3ddd4;
--ink: #1c2230;
--ink-2: #4a5160;
--muted: #8a8478;
--line: rgba(28, 34, 48, 0.12);
--paper: #fbfaf7;
--box: #222a39;
--box-dark: #171d29;
--ribbon: #d8c3a0;
--ribbon-hi: #efe2c8;
--ribbon-lo: #b49a72;
--serif: "Fraunces", Georgia, serif;
--sans: "Inter", system-ui, -apple-system, sans-serif;
--scale: 1; /* set by script.js to fit the screen */
}
*,
*::before,
*::after {
box-sizing: border-box;
}
html,
body {
margin: 0;
height: 100%;
}
body {
overflow: hidden;
font-family: var(--sans);
color: var(--ink);
background:
radial-gradient(ellipse 70% 60% at 50% 45%, #f7f4ef 0%, var(--bg) 55%, var(--bg-deep) 100%);
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: transparent;
}
button {
font: inherit;
color: inherit;
}
#confetti,
#confettiBack {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 20;
}
#confettiBack {
z-index: 0;
}
.close-btn {
display: grid;
place-items: center;
width: 34px;
height: 34px;
padding: 0;
border: 0;
border-radius: 50%;
background: transparent;
cursor: pointer;
transition: background 0.2s;
}
.close-btn:hover {
background: rgba(28, 34, 48, 0.06);
}
.close-btn svg {
width: 18px;
height: 18px;
fill: none;
stroke: currentColor;
stroke-width: 1.6;
stroke-linecap: round;
}
:focus-visible {
outline: 2px solid var(--ink);
outline-offset: 3px;
}
/* ================= Stage ================= */
.stage {
position: absolute;
left: 50%;
top: 50%;
width: 420px;
height: 700px;
transform: translate(-50%, -50%) scale(var(--scale));
z-index: 1;
}
.eyebrow {
margin: 0;
font-size: 13px;
font-weight: 500;
color: var(--muted);
}
.intro {
position: absolute;
top: 120px;
left: 0;
right: 0;
text-align: center;
transition: opacity 0.5s ease, transform 0.6s ease;
}
.intro-name {
margin: 8px 0 0;
padding: 0 24px;
font-family: var(--serif);
font-weight: 400;
font-size: 52px;
line-height: 1.05;
letter-spacing: -0.02em;
overflow-wrap: anywhere;
}
.is-open .intro {
opacity: 0;
transform: translateY(-16px);
}
/* soft warm light that appears when the box opens */
.glow {
position: absolute;
left: 50%;
top: 370px;
width: 520px;
height: 520px;
margin: -260px 0 0 -260px;
border-radius: 50%;
background: radial-gradient(circle, rgba(255, 236, 200, 0.95) 0%, rgba(255, 226, 180, 0.45) 30%, rgba(255, 226, 180, 0) 62%);
opacity: 0;
transform: scale(0.3);
transition: transform 1.2s cubic-bezier(0.2, 0.9, 0.3, 1), opacity 0.8s ease, top 1s cubic-bezier(0.3, 1, 0.4, 1);
pointer-events: none;
}
.is-open .glow {
opacity: 1;
transform: scale(1);
}
.card-out .glow {
top: 260px;
}
/* ================= Gift box (3D) ================= */
.gift-wrap {
position: absolute;
left: 50%;
top: 330px;
width: 200px;
height: 200px;
margin-left: -100px;
padding: 0;
border: 0;
background: none;
cursor: pointer;
perspective: 1000px;
transform-origin: 50% 100%;
transition: transform 1s cubic-bezier(0.3, 1, 0.4, 1);
z-index: 4;
}
.gift-wrap:hover:not(:disabled) {
transform: translateY(-6px);
}
.gift-wrap:disabled {
cursor: default;
}
.gift-wrap:focus-visible {
outline: 1.5px solid var(--ink);
outline-offset: 18px;
border-radius: 14px;
}
.card-out .gift-wrap {
transform: translateY(62px) scale(0.56);
}
.floater,
.shaker,
.gift,
.box,
.lid {
transform-style: preserve-3d;
}
.floater {
width: 100%;
height: 100%;
animation: float 4s ease-in-out infinite;
}
.shaker {
width: 100%;
height: 100%;
animation: nudge 5s ease-in-out 2s infinite;
}
.is-shaking .shaker {
animation: shake 0.85s ease-in-out;
}
.is-open .shaker {
animation: none;
}
.gift {
--S: 196px; /* box width & depth */
--H: 150px; /* box height */
--L: 208px; /* lid width & depth */
--h: 36px; /* lid height */
--rib: 22px; /* ribbon width */
--grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0.045 0 0 0 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
position: relative;
width: 196px;
height: 200px;
margin-left: 2px;
transform: rotateX(-30deg) rotateY(-36deg);
}
.face {
position: absolute;
left: 0;
top: 0;
}
.face::after {
content: "";
position: absolute;
inset: 0;
background: var(--shade, transparent);
}
/* satin ribbon used on every side */
.side,
.lside {
--stripe: linear-gradient(90deg,
transparent calc(50% - var(--rib) / 2),
var(--ribbon-lo) calc(50% - var(--rib) / 2),
var(--ribbon-hi) calc(50% - 3px),
var(--ribbon) calc(50% + 4px),
var(--ribbon-lo) calc(50% + var(--rib) / 2),
transparent calc(50% + var(--rib) / 2));
}
/* --- box body --- */
.box {
position: absolute;
left: 0;
top: 50px;
width: var(--S);
height: var(--H);
}
.side {
width: var(--S);
height: var(--H);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
background:
var(--grain),
linear-gradient(180deg, rgba(255, 255, 255, 0.14) 0 1.5px, rgba(0, 0, 0, 0.35) 1.5px, transparent 12px),
var(--stripe),
linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.12)),
var(--box);
}
.box .front { transform: translateZ(calc(var(--S) / 2)); }
.box .back { transform: rotateY(180deg) translateZ(calc(var(--S) / 2)); --shade: rgba(0, 0, 0, 0.3); }
.box .left { transform: rotateY(-90deg) translateZ(calc(var(--S) / 2)); }
.box .right { transform: rotateY(90deg) translateZ(calc(var(--S) / 2)); --shade: rgba(0, 0, 0, 0.28); }
.bottom,
.floor-light {
width: var(--S);
height: var(--S);
top: calc((var(--H) - var(--S)) / 2);
}
.bottom {
background: var(--box-dark);
transform: rotateX(-90deg) translateZ(calc(var(--H) / 2));
}
/* inner walls: plain dark card stock, warmer near the floor where the light is */
.wall {
width: var(--S);
height: var(--H);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
background: linear-gradient(0deg, #3b3529 0%, #262b36 45%, #1b202b 100%);
}
.in-front { transform: translateZ(calc(var(--S) / 2 - 1px)) rotateY(180deg); }
.in-back { transform: translateZ(calc(var(--S) / -2 + 1px)); --shade: rgba(0, 0, 0, 0.1); }
.in-left { transform: rotateY(90deg) translateZ(calc(var(--S) / -2 + 1px)); }
.in-right { transform: rotateY(-90deg) translateZ(calc(var(--S) / -2 + 1px)); --shade: rgba(0, 0, 0, 0.18); }
.wall::before {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(0deg,
rgba(255, 226, 170, 0.95) 0%,
rgba(240, 200, 140, 0.7) 40%,
rgba(190, 150, 100, 0.3) 75%,
rgba(0, 0, 0, 0) 100%);
opacity: 0;
transition: opacity 0.6s ease 0.1s;
}
.is-open .wall::before {
opacity: 1;
}
/* warm light on the floor of the box */
.floor-light {
transform: rotateX(90deg) translateZ(calc(var(--H) / -2 + 1px));
background: radial-gradient(circle, #fff4dc 0%, #ecd09d 30%, #6b5a3f 62%, #2a2c33 100%);
opacity: 0;
transition: opacity 0.5s ease;
}
.is-open .floor-light {
opacity: 1;
}
/* --- card inside the box (3D) --- */
.mini {
position: absolute;
left: calc((var(--S) - 290px) / 2);
top: calc(125px - 195px);
width: 290px;
height: 390px;
/* undo the box rotation so the card faces the viewer */
transform: rotateY(36deg) rotateX(30deg) scale(0.36);
transition: transform 0.9s cubic-bezier(0.2, 0.85, 0.3, 1);
}
.card-rise .mini {
transform: translateY(-130px) rotateY(36deg) rotateX(30deg) scale(0.36);
}
.card-out .mini {
visibility: hidden;
}
/* --- lid --- */
.lid {
position: absolute;
left: calc((var(--S) - var(--L)) / 2);
top: calc(50px - var(--h) + 8px);
width: var(--L);
height: var(--h);
}
.lside {
width: var(--L);
height: var(--h);
background:
var(--grain),
linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 50%, rgba(0, 0, 0, 0.18)),
var(--stripe),
var(--box);
}
.lid .front { transform: translateZ(calc(var(--L) / 2)); }
.lid .back { transform: rotateY(180deg) translateZ(calc(var(--L) / 2)); --shade: rgba(0, 0, 0, 0.3); }
.lid .left { transform: rotateY(-90deg) translateZ(calc(var(--L) / 2)); }
.lid .right { transform: rotateY(90deg) translateZ(calc(var(--L) / 2)); --shade: rgba(0, 0, 0, 0.28); }
.ltop,
.lunder {
width: var(--L);
height: var(--L);
top: calc((var(--h) - var(--L)) / 2);
}
.ltop {
transform: rotateX(90deg) translateZ(calc(var(--h) / 2));
background:
var(--grain),
linear-gradient(90deg,
transparent calc(50% - var(--rib) / 2),
var(--ribbon-lo) calc(50% - var(--rib) / 2),
var(--ribbon-hi) calc(50% - 3px),
var(--ribbon) calc(50% + 4px),
var(--ribbon-lo) calc(50% + var(--rib) / 2),
transparent calc(50% + var(--rib) / 2)),
linear-gradient(0deg,
transparent calc(50% - var(--rib) / 2),
var(--ribbon-lo) calc(50% - var(--rib) / 2),
var(--ribbon-hi) calc(50% - 3px),
var(--ribbon) calc(50% + 4px),
var(--ribbon-lo) calc(50% + var(--rib) / 2),
transparent calc(50% + var(--rib) / 2)),
#2a3345;
--shade: linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent 60%);
}
.lunder {
transform: rotateX(-90deg) translateZ(calc(var(--h) / 2));
background: var(--box-dark);
}
.is-open .lid {
animation: lidOff 1.6s cubic-bezier(0.3, 0.55, 0.35, 1) forwards;
}
@keyframes lidOff {
0% { transform: none; }
22% { transform: translate3d(0, -64px, 0) rotateZ(-4deg) rotateX(6deg); }
40% { transform: translate3d(30px, -150px, -20px) rotateZ(6deg) rotateX(-10deg); }
/* hidden at the end so it never stays on screen on tall displays */
100% { transform: translate3d(320px, -1500px, -160px) rotateZ(38deg) rotateX(-55deg) rotateY(25deg); visibility: hidden; }
}
/* --- flat satin bow lying on the lid --- */
.bow {
width: var(--L);
height: var(--L);
top: calc((var(--h) - var(--L)) / 2);
transform: rotateX(90deg) translateZ(calc(var(--h) / 2 + 1px));
}
.bow svg {
width: 100%;
height: 100%;
filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.45));
}
/* --- gift tag hanging from the ribbon --- */
.tag {
position: absolute;
left: calc(50% + 11px);
top: 12px;
filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35));
}
.tag-string {
position: absolute;
left: 0;
top: 0;
width: 34px;
height: 1px;
background: var(--ribbon);
transform-origin: 0 0;
transform: rotate(52deg);
}
.tag-card {
position: absolute;
left: 15px;
top: 20px;
display: block;
width: max-content;
max-width: 96px;
height: 28px;
padding: 0 10px 0 19px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
background: linear-gradient(180deg, #f8f3ea, #ece3d3);
color: var(--ink);
font: italic 400 13px/28px var(--serif);
clip-path: polygon(9px 0, 100% 0, 100% 100%, 9px 100%, 0 50%);
transform: rotate(12deg);
transform-origin: 6px 50%;
}
.tag-hole {
position: absolute;
left: 7px;
top: 50%;
width: 5px;
height: 5px;
margin-top: -2.5px;
border-radius: 50%;
background: var(--box);
box-shadow: 0 0 0 1px var(--ribbon-lo);
}
/* --- floor shadow --- */
.shadow {
position: absolute;
left: 50%;
top: 520px;
width: 260px;
height: 40px;
margin-left: -130px;
border-radius: 50%;
background:
radial-gradient(ellipse 42% 32% at 50% 50%, rgba(28, 34, 48, 0.38), rgba(28, 34, 48, 0) 100%),
radial-gradient(ellipse, rgba(28, 34, 48, 0.2), rgba(28, 34, 48, 0) 70%);
animation: shadow 4s ease-in-out infinite;
transition: top 1s cubic-bezier(0.3, 1, 0.4, 1), opacity 0.8s;
}
.card-out .shadow {
top: 552px;
opacity: 0.7;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
@keyframes shadow {
0%, 100% { transform: scale(1); }
50% { transform: scale(0.9); }
}
@keyframes nudge {
0%, 84%, 100% { transform: rotate(0); }
88% { transform: rotate(-2.5deg); }
92% { transform: rotate(2.5deg); }
96% { transform: rotate(-1.5deg); }
}
@keyframes shake {
0% { transform: rotate(0); }
14% { transform: translateX(-4px) rotate(-5deg); }
28% { transform: translateX(4px) rotate(5deg); }
42% { transform: translateX(-4px) rotate(-5deg); }
56% { transform: translateX(4px) rotate(5deg); }
70% { transform: rotate(0) scale(1.03); }
85% { transform: translateY(5px) scale(1.06, 0.94); }
100% { transform: none; }
}
/* ================= Hint ================= */
.hint {
position: absolute;
top: 612px;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
margin: 0;
font-size: 14px;
color: var(--ink-2);
transition: opacity 0.4s;
}
.hint-dot {
position: relative;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--ink);
}
.hint-dot::after {
content: "";
position: absolute;
inset: -5px;
border-radius: 50%;
border: 1px solid var(--ink);
animation: ping 2s ease-out infinite;
}
@keyframes ping {
from { transform: scale(0.5); opacity: 0.7; }
to { transform: scale(1.6); opacity: 0; }
}
.is-open .hint {
opacity: 0;
}
/* ================= Card ================= */
.card {
position: absolute;
left: 50%;
top: 60px;
width: 290px;
height: 390px;
perspective: 1600px;
opacity: 0;
visibility: hidden;
transform: translate(-50%, 85px) scale(0.36);
transition: transform 1s cubic-bezier(0.25, 1, 0.35, 1);
z-index: 6;
cursor: pointer;
}
.card-out .card {
opacity: 1;
visibility: visible;
transform: translate(-50%, 0) scale(1);
}
.no-anim,
.no-anim * {
transition: none !important;
animation: none !important;
}
.card-inner {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 1.1s cubic-bezier(0.3, 1.2, 0.4, 1);
}
.card.flipped .card-inner {
transform: rotateY(180deg);
}
.card-face {
position: absolute;
inset: 0;
border-radius: 6px;
overflow: hidden;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
background: var(--paper);
box-shadow:
0 1px 0 rgba(255, 255, 255, 0.8) inset,
0 2px 4px rgba(28, 34, 48, 0.06),
0 24px 48px -16px rgba(28, 34, 48, 0.35);
}
/* front */
.mini-card {
position: absolute;
inset: 0;
border-radius: 6px;
background: var(--paper);
box-shadow: 0 -10px 30px rgba(255, 230, 180, 0.25);
}
.card-front,
.mini-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 32px;
text-align: center;
}
.card-front::before,
.mini-card::before {
content: "";
position: absolute;
inset: 12px;
border: 1px solid var(--line);
border-radius: 3px;
pointer-events: none;
}
.seal {
display: grid;
place-items: center;
width: 46px;
height: 46px;
margin-bottom: 28px;
border-radius: 50%;
background: radial-gradient(circle at 35% 30%, var(--ribbon-hi), var(--ribbon) 55%, var(--ribbon-lo));
color: var(--ink);
font-family: var(--serif);
font-style: italic;
font-size: 20px;
box-shadow: 0 0 0 4px var(--paper), 0 0 0 5px rgba(180, 154, 114, 0.5);
}
.card-to {
margin: 8px 0 0;
font-family: var(--serif);
font-weight: 400;
font-size: 42px;
line-height: 1.05;
letter-spacing: -0.02em;
color: var(--ink);
overflow-wrap: anywhere;
}
.rule {
width: 32px;
height: 1px;
margin: 24px 0 0;
background: var(--ribbon-lo);
}
.card-hint {
position: absolute;
bottom: 32px;
margin: 0;
font-size: 12px;
color: var(--muted);
}
/* back */
.card-back {
transform: rotateY(180deg);
display: flex;
flex-direction: column;
padding: 36px 30px 22px;
}
.letter {
flex: 1;
}
.letter p {
margin: 0;
}
.letter .dear {
margin-bottom: 14px;
font-family: var(--serif);
font-style: italic;
font-size: 22px;
}
.msg {
font-family: var(--serif);
font-weight: 300;
font-size: 17px;
line-height: 1.6;
color: var(--ink-2);
overflow-wrap: break-word;
}
.msg .w {
display: inline-block;
opacity: 0;
}
.write .msg .w {
animation: rise 0.5s ease forwards;
animation-delay: calc(var(--i) * 55ms + 500ms);
}
.letter .sign {
display: flex;
flex-direction: column;
margin-top: 22px;
opacity: 0;
}
.write .sign {
animation: rise 0.6s ease forwards;
animation-delay: var(--sign-delay, 2s);
}
.sign-label {
font-size: 12px;
color: var(--muted);
}
.sign-name {
margin-top: 2px;
font-family: var(--serif);
font-style: italic;
font-size: 22px;
color: var(--ink);
}
.letter-date {
margin: 0;
padding-top: 14px;
border-top: 1px solid var(--line);
font-size: 11px;
color: var(--muted);
}
@keyframes rise {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: none; }
}
/* ================= Buttons ================= */
.actions {
position: absolute;
top: 648px;
left: 0;
right: 0;
display: flex;
justify-content: center;
gap: 10px;
opacity: 0;
transform: translateY(10px);
pointer-events: none;
transition: opacity 0.5s, transform 0.5s;
z-index: 8;
}
.done .actions {
opacity: 1;
transform: none;
pointer-events: auto;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
height: 44px;
padding: 0 20px;
border-radius: 999px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.btn:active {
transform: scale(0.98);
}
.btn svg {
width: 17px;
height: 17px;
fill: none;
stroke: currentColor;
stroke-width: 1.7;
stroke-linecap: round;
stroke-linejoin: round;
}
.btn.primary {
border: 1px solid var(--ink);
background: var(--ink);
color: #fff;
}
.btn.primary:hover {
background: #2c3446;
}
.btn.secondary {
border: 1px solid rgba(28, 34, 48, 0.18);
background: rgba(255, 255, 255, 0.6);
color: var(--ink);
}
.btn.secondary:hover {
background: #fff;
border-color: rgba(28, 34, 48, 0.3);
}
/* ================= Dialog ================= */
.maker {
width: min(92vw, 420px);
padding: 0;
border: 1px solid var(--line);
border-radius: 16px;
background: #fff;
color: var(--ink);
box-shadow: 0 32px 64px -24px rgba(28, 34, 48, 0.4);
}
.maker[open] {
animation: pop 0.3s cubic-bezier(0.2, 1, 0.4, 1);
}
.maker::backdrop {
background: rgba(28, 34, 48, 0.35);
backdrop-filter: blur(3px);
}
@keyframes pop {
from { opacity: 0; transform: translateY(12px) scale(0.98); }
}
.maker form {
padding: 24px;
}
.maker-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.maker h3 {
margin: 0;
font-family: var(--serif);
font-weight: 400;
font-size: 26px;
letter-spacing: -0.01em;
}
.maker-sub {
margin: 6px 0 22px;
font-size: 14px;
line-height: 1.5;
color: var(--ink-2);
}
.field-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.field {
display: grid;
gap: 6px;
margin-bottom: 14px;
font-size: 13px;
font-weight: 500;
color: var(--ink);
}
.field input,
.field textarea {
width: 100%;
padding: 11px 12px;
border: 1px solid rgba(28, 34, 48, 0.16);
border-radius: 10px;
background: #fff;
color: var(--ink);
font: 400 15px var(--sans);
resize: none;
transition: border-color 0.2s, box-shadow 0.2s;
}
.field input::placeholder,
.field textarea::placeholder {
color: #a9a49b;
}
.field input:focus,
.field textarea:focus {
outline: none;
border-color: var(--ink);
box-shadow: 0 0 0 3px rgba(28, 34, 48, 0.08);
}
.count {
justify-self: end;
font-size: 12px;
font-weight: 400;
color: var(--muted);
}
.maker-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 4px;
}
.status {
min-height: 18px;
margin: 12px 0 0;
font-size: 13px;
text-align: center;
color: var(--ink-2);
}
/* ================= Reduced motion ================= */
@media (prefers-reduced-motion: reduce) {
.floater,
.shaker,
.shadow,
.hint-dot::after {
animation: none !important;
}
}
JavaScript:
JavaScript: Runs the unboxing sequence, hands the card from the box to the front without a jump, draws two layers of confetti with drag, flutter and gold foil shine, and builds a shareable link with the names and message.
// ================= Helpers =================
const $ = (sel) => document.querySelector(sel);
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const rand = (min, max) => min + Math.random() * (max - min);
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const stage = $("#stage");
const gift = $("#gift");
const card = $("#card");
const mini = $("#mini");
const letter = $("#letter");
const msgEl = $("#msg");
const maker = $("#maker");
// ================= Fit the stage to any screen =================
let scale = 1;
function fit() {
scale = Math.min(innerWidth / 440, innerHeight / 720, 1.3);
document.documentElement.style.setProperty("--scale", scale.toFixed(3));
}
// ================= Card content (read from the URL) =================
const DEFAULTS = {
to: "Alexa",
msg: "Wishing you a calm, bright season and a year full of good things. Thank you for being part of this one.",
from: "Stella",
};
const params = new URLSearchParams(location.search);
let data = {
to: params.get("to") || DEFAULTS.to,
msg: params.get("msg") || DEFAULTS.msg,
from: params.get("from") || DEFAULTS.from,
};
function render() {
for (const id of ["introName", "cardTo", "miniTo", "dearTo", "tagTo"]) {
$(`#${id}`).textContent = data.to;
}
$("#fromName").textContent = data.from;
const initial = data.from.trim().charAt(0).toUpperCase();
$("#seal").textContent = initial;
$("#miniSeal").textContent = initial;
$("#dateText").textContent = new Date().toLocaleDateString("en-US", { month: "long", year: "numeric" });
// split the message into words so they can fade in one by one
msgEl.textContent = "";
const words = data.msg.split(/\s+/).filter(Boolean);
words.forEach((word, i) => {
const span = document.createElement("span");
span.className = "w";
span.textContent = word;
span.style.setProperty("--i", i);
msgEl.append(span, " ");
});
letter.style.setProperty("--sign-delay", `${words.length * 55 + 800}ms`);
}
// ================= Confetti =================
function setupCanvas(canvas) {
const ctx = canvas.getContext("2d");
const resize = () => {
const dpr = Math.min(devicePixelRatio || 1, 2);
canvas.width = innerWidth * dpr;
canvas.height = innerHeight * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
};
resize();
addEventListener("resize", resize);
return ctx;
}
// two layers: [behind the box and card, in front of everything]
const layers = [setupCanvas($("#confettiBack")), setupCanvas($("#confetti"))];
const PAPER_COLORS = ["#d8c3a0", "#efe2c8", "#ffffff", "#ffffff", "#c9b089", "#1c2230"];
const STREAMER_COLORS = ["#d8c3a0", "#c9b089", "#e8dcc4"];
const FOIL_DARK = [150, 120, 78]; // gold foil in shadow
const FOIL_LIGHT = [255, 246, 222]; // gold foil catching the light
let pieces = [];
let running = false;
let lastTime = 0;
function makePiece(x, y, vx, vy, backChance, maxLife) {
const r = Math.random();
const type = r < 0.14 ? "streamer" : r < 0.5 ? "foil" : r < 0.6 ? "dot" : "paper";
const back = Math.random() < backChance;
const depth = back ? rand(0.6, 0.85) : rand(0.9, 1.15); // far pieces are smaller
return {
type,
layer: back ? 0 : 1,
depth,
x,
y,
vx,
vy,
w: rand(5, 9) * depth,
h: rand(9, 15) * depth,
len: rand(34, 60) * depth,
rot: rand(0, Math.PI * 2),
spin: rand(-0.12, 0.12),
tilt: rand(0, Math.PI * 2),
tiltSpeed: rand(0.08, 0.2),
wave: rand(0, Math.PI * 2),
seed: rand(0, 1000),
color: PAPER_COLORS[(Math.random() * PAPER_COLORS.length) | 0],
streamerColor: STREAMER_COLORS[(Math.random() * STREAMER_COLORS.length) | 0],
life: 0,
maxLife,
};
}
// a cone of confetti released in 5 quick waves, so it feels like a pop
function burst(x, y, count) {
const s = Math.max(scale, 0.7);
for (let wave = 0; wave < 5; wave++) {
setTimeout(() => {
for (let i = 0; i < count / 5; i++) {
const angle = -Math.PI / 2 + rand(-0.75, 0.75);
const speed = rand(11, 21) * s * (1 - wave * 0.06);
pieces.push(
makePiece(x + rand(-30, 30) * s, y, Math.cos(angle) * speed, Math.sin(angle) * speed, 0.45, rand(4200, 5600))
);
}
startConfetti();
}, wave * 45);
}
}
// a slow shower from above, mostly behind the card so the letter stays readable
function shower(count) {
for (let i = 0; i < count; i++) {
const x = rand(0, innerWidth);
const y = rand(-innerHeight * 0.5, -20);
pieces.push(makePiece(x, y, rand(-0.5, 0.5), rand(0.5, 2), 0.8, 9000));
}
startConfetti();
}
function startConfetti() {
if (running) return;
running = true;
lastTime = 0;
requestAnimationFrame(tick);
}
function tick(now) {
// time-based, so it moves the same on 60Hz, 120Hz and slow phones
const dt = lastTime ? Math.max(0, Math.min((now - lastTime) / 16.67, 4)) : 1;
lastTime = now;
layers.forEach((ctx) => ctx.clearRect(0, 0, innerWidth, innerHeight));
pieces = pieces.filter((p) => p.life < p.maxLife && p.y < innerHeight + 80);
for (const p of pieces) {
p.life += dt * 16.67;
// air drag + gravity, with a slow top speed like real paper
const drag = Math.pow(p.type === "streamer" ? 0.962 : 0.975, dt);
p.vx *= drag;
p.vy = p.vy * drag + 0.22 * dt;
const maxFall = (p.type === "dot" ? 3.4 : p.type === "streamer" ? 1.8 : 2.4) * p.depth;
p.vy = Math.min(p.vy, maxFall);
// side-to-side flutter once it starts falling
const sway = p.vy > 0 ? Math.sin(now * 0.003 + p.seed) * 0.9 * p.depth : 0;
p.x += (p.vx + sway) * dt;
p.y += p.vy * dt;
p.rot += p.spin * dt;
p.tilt += p.tiltSpeed * dt;
p.wave += 0.18 * dt;
drawPiece(layers[p.layer], p);
}
if (pieces.length) requestAnimationFrame(tick);
else running = false;
}
function drawPiece(ctx, p) {
const fadeIn = Math.min(1, p.life / 120);
const fadeOut = Math.min(1, (p.maxLife - p.life) / 700);
ctx.globalAlpha = Math.max(0, Math.min(fadeIn, fadeOut)) * (p.layer === 0 ? 0.85 : 1);
ctx.save();
ctx.translate(p.x, p.y);
ctx.rotate(p.rot);
if (p.type === "streamer") {
// curly ribbon that keeps wiggling
ctx.beginPath();
for (let i = 0; i <= 14; i++) {
const t = i / 14;
const px = (t - 0.5) * p.len;
const py = Math.sin(p.wave + t * 6) * 5 * p.depth;
i ? ctx.lineTo(px, py) : ctx.moveTo(px, py);
}
ctx.strokeStyle = p.streamerColor;
ctx.lineWidth = 2.4 * p.depth;
ctx.lineCap = "round";
ctx.stroke();
} else {
const flip = Math.cos(p.tilt); // the piece turning over
ctx.scale(1, flip);
if (p.type === "foil") {
// brighter when facing the light, darker when turned away
const shine = Math.pow(Math.abs(Math.sin(p.tilt + p.rot)), 3);
const [r, g, b] = FOIL_DARK.map((d, i) => Math.round(d + (FOIL_LIGHT[i] - d) * shine));
ctx.fillStyle = `rgb(${r}, ${g}, ${b})`;
ctx.fillRect(-p.w / 2, -p.h / 2, p.w, p.h * 0.8);
} else if (p.type === "dot") {
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(0, 0, p.w * 0.45, 0, Math.PI * 2);
ctx.fill();
} else {
ctx.fillStyle = p.color;
ctx.fillRect(-p.w / 2, -p.h / 2, p.w, p.h);
if (flip < 0) {
// back side of the paper is a little darker
ctx.fillStyle = "rgba(0, 0, 0, 0.12)";
ctx.fillRect(-p.w / 2, -p.h / 2, p.w, p.h);
}
}
}
ctx.restore();
}
// ================= Unboxing sequence =================
let opened = false;
// Put the front card exactly where the 3D card is, then let it glide to the centre
function handOffCard() {
const m = mini.getBoundingClientRect();
const st = stage.getBoundingClientRect();
// the front card's centre with no transform, in stage units
const homeX = 210;
const homeY = 60 + 390 / 2;
const dx = (m.left + m.width / 2 - st.left) / scale - homeX;
const dy = (m.top + m.height / 2 - st.top) / scale - homeY;
const size = m.width / scale / 290;
card.style.transition = "none";
card.style.transform = `translate(calc(-50% + ${dx}px), ${dy}px) scale(${size})`;
stage.classList.add("card-out");
void card.offsetWidth; // lock in the start position
card.style.transition = "";
card.style.transform = "";
}
async function openGift() {
if (opened) return;
opened = true;
gift.disabled = true;
// 1. shake
stage.classList.add("is-shaking");
await wait(850);
// 2. lid lifts off, the light comes on, confetti pops
stage.classList.remove("is-shaking");
stage.classList.add("is-open");
setTimeout(() => {
const r = gift.getBoundingClientRect();
burst(r.left + r.width / 2, r.top + r.height * 0.25, reduceMotion ? 30 : 130);
}, 180);
await wait(500);
// 3. card rises out of the box
stage.classList.add("card-rise");
await wait(950);
// 4. card glides to the front
handOffCard();
await wait(1100);
// 5. flip and reveal the message
card.classList.add("flipped");
letter.classList.add("write");
shower(reduceMotion ? 20 : 70);
await wait(1200);
stage.classList.add("done");
}
function reset() {
stage.classList.add("no-anim");
stage.classList.remove("is-shaking", "is-open", "card-rise", "card-out", "done");
card.classList.remove("flipped");
letter.classList.remove("write");
pieces = [];
void stage.offsetWidth; // apply instantly, without animating back
stage.classList.remove("no-anim");
opened = false;
gift.disabled = false;
gift.focus({ preventScroll: true });
}
gift.addEventListener("click", openGift);
card.addEventListener("click", () => {
if (stage.classList.contains("card-out")) card.classList.toggle("flipped");
});
$("#replayBtn").addEventListener("click", reset);
// ================= Create your own =================
const fTo = $("#fTo");
const fMsg = $("#fMsg");
const fFrom = $("#fFrom");
const count = $("#count");
const status = $("#status");
function updateCount() {
count.textContent = `${fMsg.value.length} / 160`;
}
function readForm() {
return {
to: fTo.value.trim() || DEFAULTS.to,
msg: fMsg.value.trim() || DEFAULTS.msg,
from: fFrom.value.trim() || DEFAULTS.from,
};
}
function buildLink(d) {
const url = new URL(location.href);
url.search = new URLSearchParams(d).toString();
return url.toString();
}
function applyForm() {
data = readForm();
const link = buildLink(data);
history.replaceState(null, "", link);
render();
return link;
}
$("#makeBtn").addEventListener("click", () => {
fTo.value = data.to === DEFAULTS.to ? "" : data.to;
fMsg.value = data.msg === DEFAULTS.msg ? "" : data.msg;
fFrom.value = data.from === DEFAULTS.from ? "" : data.from;
status.textContent = "";
updateCount();
maker.showModal();
fTo.focus();
});
fMsg.addEventListener("input", updateCount);
$("#closeBtn").addEventListener("click", () => maker.close());
maker.addEventListener("click", (e) => {
if (e.target === maker) maker.close(); // click on the backdrop
});
$("#previewBtn").addEventListener("click", () => {
applyForm();
maker.close();
reset();
});
$("#copyBtn").addEventListener("click", async () => {
const link = applyForm();
try {
await navigator.clipboard.writeText(link);
status.textContent = "Link copied. Send it to someone!";
} catch {
window.prompt("Copy this link:", link);
}
});
// ================= Start =================
addEventListener("resize", fit);
fit();
render();
This project demonstrates how HTML, CSS, and JavaScript can work together to turn a simple greeting into a small moment of surprise. CSS 3D transforms give the box real depth, the card rises out from inside the walls, the canvas confetti falls like real paper, and URL parameters let anyone send a personal gift card to a friend, like Stella sending one to Alexa.
If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!
