Gift Box Reveal
Click to shake a gift box that bursts open with confetti, revealing a surprise prize
Embed this component
Paste this snippet into any site — the design renders in a sandboxed iframe served from /embed/gift-box-button.
<iframe src="/embed/gift-box-button" sandbox="allow-scripts" loading="lazy" title="Gift Box Reveal" style="border:0;width:100%;height:480px;overflow:hidden"></iframe>Implementation code
Copy the HTML and CSS for Gift Box Reveal, or grab a framework-specific implementation. The HTML and CSS variants are self-contained; framework variants assume that framework's project setup.
HTML
<button class="btn-gift" id="giftBtn" onclick="triggerGift()">
<span class="text">Reveal</span>
<span class="box-icon">🎁</span>
<span class="prize">💎 100 Coins!</span>
</button>
<script>
function triggerGift() {
const btn = document.getElementById('giftBtn');
if(btn.classList.contains('is-shaking')) return;
btn.classList.add('is-shaking');
setTimeout(() => { btn.classList.remove('is-shaking'); btn.classList.add('is-revealed'); createConfetti(btn); }, 1200);
setTimeout(() => { btn.classList.remove('is-revealed'); btn.querySelectorAll('.confetti').forEach(c => c.remove()); }, 5000);
}
function createConfetti(btn) {
const colors = ['#facc15','#3b82f6','#10b981','#f87171'];
for(let i = 0; i < 12; i++) {
const conf = document.createElement('div');
conf.classList.add('confetti');
conf.style.background = colors[Math.floor(Math.random() * colors.length)];
conf.style.setProperty('--tx', `${(Math.random() - 0.5) * 200}px`);
conf.style.setProperty('--ty', `${(Math.random() - 0.5) * 200}px`);
btn.appendChild(conf);
}
}
</script>CSS
.btn-gift { width: 160px; height: 50px; border-radius: 12px; border: none; background: #db2777; color: white; font-size: 16px; font-weight: 700; cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center; overflow: visible; transition: all 0.5s ease; box-shadow: 0 4px 15px rgba(219,39,119,0.4); font-family: system-ui, sans-serif; }
.btn-gift .box-icon { margin-left: 8px; font-size: 20px; transition: 0.3s; }
.btn-gift .prize { position: absolute; opacity: 0; font-size: 24px; transform: translateY(20px); transition: 0.5s; }
.btn-gift.is-shaking { animation: box-shake 0.4s infinite; }
.btn-gift.is-revealed { background: #9333ea; width: 180px; }
.btn-gift.is-revealed .box-icon, .btn-gift.is-revealed .text { opacity: 0; }
.btn-gift.is-revealed .prize { opacity: 1; transform: translateY(0); }
.confetti { position: absolute; width: 8px; height: 8px; border-radius: 2px; opacity: 0; }
.is-revealed .confetti { animation: pop-out 0.8s forwards ease-out; }
@keyframes box-shake { 0%,100% { transform: rotate(0deg); } 25% { transform: rotate(-5deg) scale(1.05); } 75% { transform: rotate(5deg) scale(1.05); } }
@keyframes pop-out { 0% { transform: translate(0,0) scale(1); opacity: 1; } 100% { transform: translate(var(--tx),var(--ty)) scale(0); opacity: 0; } }Tailwind CSS
<button class="w-[160px] h-[50px] rounded-xl border-none bg-pink-600 text-white text-base font-bold cursor-pointer relative flex items-center justify-center overflow-visible transition-all duration-500 shadow-[0_4px_15px_rgba(219,39,119,0.4)] [&.is-shaking]:animate-[box-shake_0.4s_infinite] [&.is-revealed]:bg-purple-600 [&.is-revealed]:w-[180px]" id="tw-gift">
<span class="text">Reveal</span>
<span class="box-icon ml-2 text-xl">🎁</span>
<span class="prize absolute text-2xl">💎 100 Coins!</span>
</button>React
import React from 'react';
import { motion } from 'framer-motion';
function GiftBoxButton() {
const [state, setState] = React.useState('idle');
const handleClick = () => {
if (state !== 'idle') return;
setState('shaking');
setTimeout(() => setState('revealed'), 1200);
setTimeout(() => setState('idle'), 5000);
};
const shake = state === 'shaking';
const rev = state === 'revealed';
const colors = ['#facc15', '#3b82f6', '#10b981', '#f87171'];
return (
<motion.button onClick={handleClick}
style={{ width: rev ? 180 : 160, height: 50, borderRadius: 12, border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', position: 'relative', fontSize: 16, fontWeight: 700, color: '#fff', background: rev ? '#9333ea' : '#db2777', boxShadow: rev ? '0 4px 15px rgba(147,51,234,0.4)' : '0 4px 15px rgba(219,39,119,0.4)', overflow: 'visible', transition: 'all 0.5s ease', fontFamily: 'system-ui, sans-serif' }}
animate={shake ? { rotate: [0, -5, 5, -5, 5, 0], scale: [1, 1.05, 1.05, 1], transition: { duration: 0.4, repeat: Infinity } } : {}}
whileTap={state === 'idle' ? { scale: 0.95 } : {}} disabled={state !== 'idle'}>
<motion.span style={{ position: 'absolute' }} animate={{ opacity: rev ? 0 : 1 }}>Reveal</motion.span>
<motion.span style={{ fontSize: 20, marginLeft: 8 }} animate={{ opacity: rev ? 0 : 1 }}>🎁</motion.span>
<motion.span style={{ position: 'absolute', fontSize: 24 }} animate={rev ? { opacity: 1, y: 0 } : { opacity: 0, y: 20 }}>💎 100 Coins!</motion.span>
{rev && [...Array(12)].map((_, i) => (
<motion.div key={i} style={{ position: 'absolute', width: 8, height: 8, borderRadius: 2, background: colors[i % 4] }}
initial={{ x: 0, y: 0, scale: 1, opacity: 1 }}
animate={{ x: (Math.random() - 0.5) * 200, y: (Math.random() - 0.5) * 200, scale: 0, opacity: 0 }}
transition={{ duration: 0.8, ease: 'easeOut' }} />
))}
</motion.button>
);
}Vue
<template>
<button class="btn-gift" :class="{ 'is-shaking': state==='shaking', 'is-revealed': state==='revealed' }" @click="handleClick" :disabled="state!=='idle'" ref="giftBtn">
<span class="text">Reveal</span>
<span class="box-icon">🎁</span>
<span class="prize">💎 100 Coins!</span>
</button>
</template>
<script setup>
import { ref } from 'vue';
const state = ref('idle');
function handleClick() {
if (state.value !== 'idle') return;
state.value = 'shaking';
setTimeout(() => state.value = 'revealed', 1200);
setTimeout(() => state.value = 'idle', 5000);
}
</script>
<style scoped>
.btn-gift { width: 160px; height: 50px; border-radius: 12px; border: none; background: #db2777; color: white; font-size: 16px; font-weight: 700; cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center; overflow: visible; transition: all 0.5s ease; box-shadow: 0 4px 15px rgba(219,39,119,0.4); }
.btn-gift .box-icon { margin-left: 8px; font-size: 20px; transition: 0.3s; }
.btn-gift .prize { position: absolute; opacity: 0; font-size: 24px; transform: translateY(20px); transition: 0.5s; }
.btn-gift.is-shaking { animation: box-shake 0.4s infinite; }
.btn-gift.is-revealed { background: #9333ea; width: 180px; }
.btn-gift.is-revealed .box-icon, .btn-gift.is-revealed .text { opacity: 0; }
.btn-gift.is-revealed .prize { opacity: 1; transform: translateY(0); }
.confetti { position: absolute; width: 8px; height: 8px; border-radius: 2px; opacity: 0; }
.is-revealed .confetti { animation: pop-out 0.8s forwards ease-out; }
@keyframes box-shake { 0%,100% { transform: rotate(0deg); } 25% { transform: rotate(-5deg) scale(1.05); } 75% { transform: rotate(5deg) scale(1.05); } }
@keyframes pop-out { 0% { transform: translate(0,0) scale(1); opacity: 1; } 100% { transform: translate(var(--tx),var(--ty)) scale(0); opacity: 0; } }
</style>Svelte
<script>
let state = 'idle';
function handleClick() {
if (state !== 'idle') return;
state = 'shaking';
setTimeout(() => state = 'revealed', 1200);
setTimeout(() => state = 'idle', 5000);
}
</script>
<button class="btn-gift" class:is-shaking={state==='shaking'} class:is-revealed={state==='revealed'} on:click={handleClick} disabled={state!=='idle'}>
<span class="text">Reveal</span>
<span class="box-icon">🎁</span>
<span class="prize">💎 100 Coins!</span>
</button>
<style>
.btn-gift { width: 160px; height: 50px; border-radius: 12px; border: none; background: #db2777; color: white; font-size: 16px; font-weight: 700; cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center; overflow: visible; transition: all 0.5s ease; box-shadow: 0 4px 15px rgba(219,39,119,0.4); }
.btn-gift .box-icon { margin-left: 8px; font-size: 20px; transition: 0.3s; }
.btn-gift .prize { position: absolute; opacity: 0; font-size: 24px; transform: translateY(20px); transition: 0.5s; }
.btn-gift.is-shaking { animation: box-shake 0.4s infinite; }
.btn-gift.is-revealed { background: #9333ea; width: 180px; }
.btn-gift.is-revealed .box-icon, .btn-gift.is-revealed .text { opacity: 0; }
.btn-gift.is-revealed .prize { opacity: 1; transform: translateY(0); }
.confetti { position: absolute; width: 8px; height: 8px; border-radius: 2px; opacity: 0; }
.is-revealed .confetti { animation: pop-out 0.8s forwards ease-out; }
@keyframes box-shake { 0%,100% { transform: rotate(0deg); } 25% { transform: rotate(-5deg) scale(1.05); } 75% { transform: rotate(5deg) scale(1.05); } }
@keyframes pop-out { 0% { transform: translate(0,0) scale(1); opacity: 1; } 100% { transform: translate(var(--tx),var(--ty)) scale(0); opacity: 0; } }
</style>Angular
import { Component } from '@angular/core';
@Component({
selector: 'app-gift-box-button',
template: `<button class="btn-gift" #giftBtn [class.is-shaking]="state==='shaking'" [class.is-revealed]="state==='revealed'" (click)="handleClick(giftBtn)" [disabled]="state!=='idle'">
<span class="text">Reveal</span>
<span class="box-icon">🎁</span>
<span class="prize">💎 100 Coins!</span>
</button>`,
styles: [`.btn-gift { width: 160px; height: 50px; border-radius: 12px; border: none; background: #db2777; color: white; font-size: 16px; font-weight: 700; cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center; overflow: visible; transition: all 0.5s ease; box-shadow: 0 4px 15px rgba(219,39,119,0.4); }
.btn-gift .box-icon { margin-left: 8px; font-size: 20px; transition: 0.3s; }
.btn-gift .prize { position: absolute; opacity: 0; font-size: 24px; transform: translateY(20px); transition: 0.5s; }
.btn-gift.is-shaking { animation: box-shake 0.4s infinite; }
.btn-gift.is-revealed { background: #9333ea; width: 180px; }
.btn-gift.is-revealed .box-icon, .btn-gift.is-revealed .text { opacity: 0; }
.btn-gift.is-revealed .prize { opacity: 1; transform: translateY(0); }
@keyframes box-shake { 0%,100% { transform: rotate(0deg); } 25% { transform: rotate(-5deg) scale(1.05); } 75% { transform: rotate(5deg) scale(1.05); } }`]
})
export class GiftBoxButtonComponent { state = 'idle'; handleClick(btn) { if (this.state !== 'idle') return; this.state = 'shaking'; setTimeout(() => this.state = 'revealed', 1200); setTimeout(() => this.state = 'idle', 5000); } }LWC — HTML template
<template><button class="btn-gift" onclick={handleClick} disabled={disabled}>
<span class="text">Reveal</span>
<span class="box-icon">🎁</span>
<span class="prize">💎 100 Coins!</span>
</button></template>LWC — JavaScript
import { LightningElement } from 'lwc';
export default class GiftBoxButton extends LightningElement {
state = 'idle';
get disabled() { return this.state !== 'idle'; }
handleClick() {
if (this.state !== 'idle') return;
this.state = 'shaking';
const btn = this.template.querySelector('button');
btn.classList.add('is-shaking');
setTimeout(() => { btn.classList.remove('is-shaking'); btn.classList.add('is-revealed'); this.state = 'revealed'; this.createConfetti(btn); }, 1200);
setTimeout(() => { btn.classList.remove('is-revealed'); btn.querySelectorAll('.confetti').forEach(c => c.remove()); this.state = 'idle'; }, 5000);
}
createConfetti(btn) {
const colors = ['#facc15','#3b82f6','#10b981','#f87171'];
for(let i = 0; i < 12; i++) {
const conf = document.createElement('div');
conf.classList.add('confetti');
conf.style.background = colors[Math.floor(Math.random() * colors.length)];
conf.style.setProperty('--tx', `${(Math.random() - 0.5) * 200}px`);
conf.style.setProperty('--ty', `${(Math.random() - 0.5) * 200}px`);
btn.appendChild(conf);
}
}
}LWC — CSS
.btn-gift { width: 160px; height: 50px; border-radius: 12px; border: none; background: #db2777; color: white; font-size: 16px; font-weight: 700; cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center; overflow: visible; transition: all 0.5s ease; box-shadow: 0 4px 15px rgba(219,39,119,0.4); }
.btn-gift .box-icon { margin-left: 8px; font-size: 20px; transition: 0.3s; }
.btn-gift .prize { position: absolute; opacity: 0; font-size: 24px; transform: translateY(20px); transition: 0.5s; }
.btn-gift.is-shaking { animation: box-shake 0.4s infinite; }
.btn-gift.is-revealed { background: #9333ea; width: 180px; }
.btn-gift.is-revealed .box-icon, .btn-gift.is-revealed .text { opacity: 0; }
.btn-gift.is-revealed .prize { opacity: 1; transform: translateY(0); }
.confetti { position: absolute; width: 8px; height: 8px; border-radius: 2px; opacity: 0; }
.is-revealed .confetti { animation: pop-out 0.8s forwards ease-out; }
@keyframes box-shake { 0%,100% { transform: rotate(0deg); } 25% { transform: rotate(-5deg) scale(1.05); } 75% { transform: rotate(5deg) scale(1.05); } }
@keyframes pop-out { 0% { transform: translate(0,0) scale(1); opacity: 1; } 100% { transform: translate(var(--tx),var(--ty)) scale(0); opacity: 0; } }LWC — Configuration
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets><target>lightning__AppPage</target><target>lightning__RecordPage</target><target>lightning__HomePage</target></targets>
</LightningComponentBundle>Where Gift Box Reveal fits
- Surprise
- Reward
- Unlock
- Celebration
- Giveaway
Interaction states & animations
- Shake
- Pop Out
- Confetti Burst
- Reveal
Topics
- #gift
- #box
- #reveal
- #confetti
- #surprise
- #prize
- #celebration
Accessibility notes
Confetti burst is purely decorative. Ensure the revealed prize text is accessible via screen readers.
Browser support
- All modern browsers