A café posts a different morning deal every day, and most visitors scroll straight past the line of text that announces it. This experiment wraps the deal in a small pixel crate that floats on the page. Each tap cracks it a little more and knocks off a few chips, and on the fourth tap it bursts open to show the offer. It turns a sentence people skip into a tiny moment they choose to play with, while a plain link lets anyone skip straight to the deal.
Today's deal is inside. Tap the crate four times to crack it open.
Crate deal, today only
Free cinnamon knot with any coffee
Before 11am. Show this screen at the counter.
How it works
- Draw the block. Three square faces (top, front and right side) are turned in 3D with CSS so they meet as one cube. Each face is an 8 by 8 grid of small squares, coloured by a little formula so the green middle looks speckled and the edge reads as a gold rim. No images and no 3D library.
- Plan the cracks. When the crate is packed, the script takes a short random walk from near the centre of each face. That walk is the crack, so it looks a little different every time.
- Tap to crack. Each tap turns more squares along the walk dark, squashes the cube for a split second and throws a handful of coloured chips that fall and fade away.
- Break it open. On the last tap the cube is hidden, a bigger burst of chips flies out and the deal card pops in. A live region reads the offer aloud, and focus moves to the button that packs the crate again.
- Stay calm when asked. With reduced motion turned on, the float, squash, chips and pop are all switched off. The cracks still show, because they are still pictures, not movement.
The code
Three short files and no libraries; the cube is only HTML and CSS transforms.
<div class="pc" data-lab="crate">
<p class="pc-hint" id="pc-hint">Today's deal is inside. Tap the crate four times to crack it open.</p>
<div class="pc-stage">
<button class="pc-block" type="button" aria-describedby="pc-hint" aria-label="Crack the crate open, 4 taps left">
<span class="pc-float" aria-hidden="true">
<span class="pc-cube">
<span class="pc-face pc-top"></span>
<span class="pc-face pc-front"></span>
<span class="pc-face pc-side"></span>
</span>
</span>
</button>
<div class="pc-prize" hidden>
<p class="pc-tag">Crate deal, today only</p>
<p class="pc-deal">Free cinnamon knot with any coffee</p>
<p class="pc-small">Before 11am. Show this screen at the counter.</p>
<button class="pc-reset" type="button">Pack the crate again</button>
</div>
</div>
<button class="pc-skip" type="button">Skip the taps and show the deal</button>
<p class="pc-status" aria-live="polite"></p>
</div>.pc {
position: relative;
display: grid;
justify-items: center;
gap: 10px;
width: 100%;
max-width: 520px;
margin: 0 auto;
font-family: system-ui, sans-serif;
color: #101a14;
text-align: center;
}
.pc-hint { margin: 0; font-size: 15px; line-height: 1.4; color: #46534a; }
.pc-stage {
position: relative;
display: grid;
place-items: center;
width: 100%;
height: 230px;
}
.pc-block {
display: grid;
place-items: center;
width: 190px;
height: 200px;
padding: 0;
border: 0;
border-radius: 14px;
background: none;
cursor: pointer;
perspective: 700px;
-webkit-tap-highlight-color: transparent;
}
.pc-block[hidden] { display: none; }
.pc-block:focus-visible, .pc-skip:focus-visible, .pc-reset:focus-visible { outline: 2px solid #133621; outline-offset: 3px; }
/* A gentle float while idle; paused when off screen or once opened. */
.pc-float { display: block; animation: pc-bob 3s ease-in-out infinite; }
.pc.is-off .pc-float { animation-play-state: paused; }
@keyframes pc-bob { 50% { transform: translateY(-7px); } }
/* The block: three faces of a cube, turned so we see the top, front and right side. */
.pc-cube {
position: relative;
display: block;
width: 104px;
height: 104px;
transform-style: preserve-3d;
transform: rotateX(-26deg) rotateY(-38deg);
}
.pc-cube.is-hit { animation: pc-hit .18s ease-out; }
@keyframes pc-hit { 40% { transform: rotateX(-26deg) rotateY(-38deg) scale(.9); } }
.pc-face {
position: absolute;
inset: 0;
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: repeat(8, 1fr);
}
.pc-front { transform: translateZ(52px); }
.pc-side { transform: rotateY(90deg) translateZ(52px); filter: brightness(.72); }
.pc-top { transform: rotateX(90deg) translateZ(52px); filter: brightness(1.25); }
.pc-px { background: #1b4a2e; transition: background-color .12s; }
.pc-px.pc-a { background: #133621; }
.pc-px.pc-b { background: #2f6b45; }
.pc-px.pc-rim { background: #d9b84a; }
.pc-px.pc-rim.pc-a { background: #f4d96c; }
.pc-px.pc-crack { background: #101a14; }
/* Chips that fly off with each tap. */
.pc-chip {
position: absolute;
left: 50%;
top: 50%;
width: 12px;
height: 12px;
margin: -6px 0 0 -6px;
pointer-events: none;
}
.pc-prize {
width: min(320px, 100%);
padding: 18px 18px 14px;
border: 2px solid #f4d96c;
border-radius: 14px;
background: #133621;
color: #f2f3ef;
box-shadow: 0 10px 26px rgba(16, 26, 20, .22);
}
.pc-prize[hidden] { display: none; }
.pc-prize.is-in { animation: pc-pop .45s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes pc-pop { from { transform: scale(.4); opacity: 0; } }
.pc-tag { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #f4d96c; }
.pc-deal { margin: 0 0 6px; font-size: 21px; font-weight: 700; line-height: 1.25; }
.pc-small { margin: 0 0 10px; font-size: 14px; color: #c9cec4; }
.pc-reset, .pc-skip {
padding: 6px 8px;
border: 0;
background: none;
font: 500 14px system-ui, sans-serif;
text-decoration: underline;
cursor: pointer;
}
.pc-reset { color: #f4d96c; }
.pc-skip { color: #133621; }
.pc-skip[hidden] { display: none; }
.pc-status { min-height: 1.4em; margin: 0; font-size: 15px; font-weight: 600; color: #133621; }
@media (prefers-reduced-motion: reduce) {
.pc-float, .pc-cube.is-hit, .pc-prize.is-in { animation: none; }
.pc-px { transition: none; }
}(function () {
var root = document.querySelector('[data-lab="crate"]');
if (!root) return;
var TAPS = 4; // taps needed to break the crate
var CHIPS = 6; // chips per tap; the final break throws four times as many
var COLORS = ['#133621', '#2f6b45', '#f4d96c', '#101a14'];
var block = root.querySelector('.pc-block');
var cube = root.querySelector('.pc-cube');
var stage = root.querySelector('.pc-stage');
var prize = root.querySelector('.pc-prize');
var skip = root.querySelector('.pc-skip');
var status = root.querySelector('.pc-status');
var calm = window.matchMedia && matchMedia('(prefers-reduced-motion: reduce)').matches;
var faces = [];
var hits = 0;
// Paint each face as an 8 by 8 grid of "pixels": a gold rim and a speckled green middle.
function paint(face) {
var cells = [];
for (var i = 0; i < 64; i++) {
var x = i % 8, y = Math.floor(i / 8);
var px = document.createElement('span');
var shade = (x * 7 + y * 13 + x * y) % 5;
px.className = 'pc-px' + (shade === 0 ? ' pc-a' : shade === 3 ? ' pc-b' : '') +
(x === 0 || y === 0 || x === 7 || y === 7 ? ' pc-rim' : '');
face.appendChild(px);
cells.push(px);
}
return cells;
}
// A crack is a short random walk from near the middle; each tap reveals more of it.
function crackPath() {
var x = 3 + Math.round(Math.random()), y = 3 + Math.round(Math.random()), path = [];
for (var i = 0; i < 18; i++) {
path.push(y * 8 + x);
if (Math.random() < 0.5) x += Math.random() < 0.5 ? -1 : 1;
else y += Math.random() < 0.5 ? -1 : 1;
x = Math.max(1, Math.min(6, x));
y = Math.max(1, Math.min(6, y));
}
return path;
}
root.querySelectorAll('.pc-face').forEach(function (f) {
faces.push({ cells: paint(f), path: [] });
});
function setCracks() {
var show = Math.ceil(18 * hits / (TAPS - 1));
faces.forEach(function (f) {
f.cells.forEach(function (c) { c.classList.remove('pc-crack'); });
for (var i = 0; i < Math.min(show, f.path.length); i++) f.cells[f.path[i]].classList.add('pc-crack');
});
}
// Small squares burst out from the centre and fall, then remove themselves.
function burst(n, reach) {
if (calm || !Element.prototype.animate) return;
for (var i = 0; i < n; i++) {
var chip = document.createElement('span');
chip.className = 'pc-chip';
chip.setAttribute('aria-hidden', 'true');
chip.style.background = COLORS[i % COLORS.length];
stage.appendChild(chip);
var a = Math.random() * Math.PI * 2, d = reach * (0.5 + Math.random() * 0.6);
var dx = Math.cos(a) * d, dy = Math.sin(a) * d * 0.7;
chip.animate([
{ transform: 'translate(0,0) rotate(0deg) scale(1)', opacity: 1 },
{ transform: 'translate(' + dx + 'px,' + (dy + 70) + 'px) rotate(' + (Math.random() * 360) + 'deg) scale(.5)', opacity: 0 }
], { duration: 650 + Math.random() * 300, easing: 'cubic-bezier(.2,.7,.5,1)' }).onfinish = (function (c) {
return function () { c.remove(); };
})(chip);
}
}
function open() {
block.hidden = true;
skip.hidden = true;
prize.hidden = false;
prize.classList.add('is-in');
burst(CHIPS * 4, 170);
// Read the deal from the HTML so the text only lives in one place.
status.textContent = 'Cracked open: ' + prize.querySelector('.pc-deal').textContent.toLowerCase() + '.';
prize.querySelector('.pc-reset').focus({ preventScroll: true });
}
block.addEventListener('click', function () {
hits++;
if (hits >= TAPS) { open(); return; }
setCracks();
cube.classList.remove('is-hit');
void cube.offsetWidth; // restart the squash animation
cube.classList.add('is-hit');
burst(CHIPS, 90);
var left = TAPS - hits;
block.setAttribute('aria-label', 'Crack the crate open, ' + left + (left === 1 ? ' tap' : ' taps') + ' left');
status.textContent = left === 1 ? 'One more tap.' : left + ' taps to go.';
});
skip.addEventListener('click', open);
function reset() {
hits = 0;
faces.forEach(function (f) { f.path = crackPath(); });
setCracks();
prize.hidden = true;
prize.classList.remove('is-in');
block.hidden = false;
skip.hidden = false;
block.setAttribute('aria-label', 'Crack the crate open, ' + TAPS + ' taps left');
status.textContent = '';
}
prize.querySelector('.pc-reset').addEventListener('click', function () { reset(); block.focus(); });
reset();
// Stop the idle float while the demo is off screen.
if ('IntersectionObserver' in window) {
new IntersectionObserver(function (e) {
root.classList.toggle('is-off', !e[0].isIntersecting);
}).observe(root);
}
})();When to use it, and when not to
It suits small, playful rewards where the reveal is the fun part: a deal of the day at a café or bakery, a mystery discount at a gift shop, a weekly surprise for a kids' activity centre, a "today's special" at a food truck. Hiding something behind four taps gives people a reason to stop for a second, and the moment of breaking it open makes the offer feel like a find rather than an advert.
It is a bad fit for anything people need to read: prices, opening hours, delivery terms, allergy information or booking details should never sit inside a crate. It also wears thin if you use it more than once on a page, or for every promotion. Save it for one spot where a bit of play matches your brand, and keep the deal itself honest; a crate that opens to fine print feels like a trick.
On accessibility, the crate is a real button with a label that counts down the taps, so it works with a keyboard (Enter or Space) as well as a mouse or a finger. The skip link means no one has to play to see the offer, which matters for people who use switch controls or simply do not want a game. The decorative squares and chips are hidden from screen readers.
Make it yours
- Number of taps: change
TAPSat the top of the script. Three or four feels like a small game; more than five starts to feel like work. - Colours: the face squares use
.pc-px,.pc-a,.pc-band.pc-rimin the CSS, and the chips take their colours from theCOLORSlist in the script. A brown and cream mix gives a wooden box; red and white suits a gift. - Size of the burst:
CHIPSsets how many squares fly off each tap, and the second number inburst(CHIPS * 4, 170)sets how far the final burst reaches.
Frequently asked questions
Can I change the deal every day without touching the code?
Yes. The offer is ordinary HTML inside .pc-prize, so you can edit the text in your page builder or fill it in from your CMS. The script only shows and hides it, and reads the announcement for screen readers straight from that text.
Does it work on phones?
Yes. The crate is a 190 pixel wide button, easy to tap with a thumb, and the 3D turn is plain CSS that every current mobile browser supports. The chips are removed from the page as soon as they land.
Will it slow my page down?
No. The block is 192 tiny squares drawn once, the only animation that runs on its own is a gentle float that pauses when the crate scrolls out of view, and nothing else moves until someone taps.