Pure CSS 3D Smartphone Teardown (Zero JavaScript) – Full Code
Introduction
Click a button and a whole smartphone comes apart in 3D: the display, the aluminium frame, the logic board, the battery and the back glass, each with its own label. Click again and it snaps back together. The best part? There is not a single line of JavaScript. Everything here is pure HTML and CSS.
In this tutorial you’ll build it step by step, and learn some of the most useful CSS 3D tricks along the way.
Live demo
Click Teardown to try it:
Watch the video
What you’ll learn
- The hidden checkbox trick: handling clicks without JavaScript
perspectiveandtransform-style: preserve-3d- Exploding layers with
translateZ()and CSS custom properties - Making labels rotate back so they always face the viewer
- Drawing camera lenses, a circuit board and a battery with gradients only
1. The idea: a phone is a stack of layers
A real phone is a stack: back glass at the bottom, then the battery, the logic board, the frame and the display on top. We build the same thing in CSS: five divs stacked in 3D space. When the phone is closed, the layers sit almost on top of each other. When you click Teardown, each layer moves up or down along the Z axis.
2. The HTML
A hidden checkbox is our on/off switch. The <label> is connected to it with for="tear", so clicking the label ticks the checkbox. That label is our button. Each part carries a data-label that CSS turns into a visible label later.
<div class="stage">
<input type="checkbox" id="tear" class="toggle">
<label for="tear" class="btn">
<span class="off">Teardown</span>
<span class="on">Assemble</span>
</label>
<div class="phone">
<div class="part back" data-label="Back glass">
<div class="cam">
<i class="lens"></i>
<i class="lens"></i>
<i class="lens"></i>
<i class="flash"></i>
</div>
<div class="logo"></div>
</div>
<div class="part battery" data-label="Battery">
<div class="cell">
<b>4,500 mAh</b>
<small>Li-ion · 3.87 V</small>
</div>
</div>
<div class="part board" data-label="Logic board">
<i class="chip cpu">P1</i>
<i class="chip ram">8 GB</i>
<i class="chip modem">5G</i>
</div>
<div class="part frame" data-label="Aluminium frame"></div>
<div class="part screen" data-label="OLED display">
<div class="island"></div>
<div class="time">9:41</div>
<div class="date">Tuesday, 1 December</div>
<div class="apps">
<i style="--h: 200"></i>
<i style="--h: 140"></i>
<i style="--h: 20"></i>
<i style="--h: 280"></i>
<i style="--h: 330"></i>
<i style="--h: 50"></i>
<i style="--h: 170"></i>
<i style="--h: 240"></i>
</div>
</div>
</div>
</div>3. The stage and perspective
perspective: 2200px tells the browser how far away the viewer is. Without it, 3D transforms look flat. A smaller value means a stronger, more dramatic 3D effect.
/* ---------- the scene ---------- */
.stage {
position: relative;
display: grid;
place-items: center;
width: 960px;
height: 760px;
perspective: 2200px;
font-family: system-ui, sans-serif;
}
.stage::after {
content: "";
position: absolute;
bottom: 70px;
width: 300px;
height: 40px;
border-radius: 50%;
background: radial-gradient(#0008, #0000 70%);
}The checkbox is hidden with display: none, but the label still toggles it. The ~ combinator selects every later sibling, so .toggle:checked ~ .phone styles the phone only while the box is ticked. The same trick swaps the button text from “Teardown” to “Assemble”.
/* ---------- the button (a label for the hidden checkbox) ---------- */
.toggle { display: none; }
.btn {
position: absolute;
bottom: 0;
z-index: 5;
padding: 14px 36px;
border-radius: 99px;
font-size: 20px;
font-weight: 800;
color: #fff;
background: linear-gradient(90deg, #7c5cff, #22d3ee);
box-shadow: 0 10px 30px #7c5cff66;
cursor: pointer;
transition: transform .2s;
}
.btn:hover { transform: scale(1.06); }
.btn .on,
.toggle:checked ~ .btn .off { display: none; }
.toggle:checked ~ .btn .on { display: inline; }5. The phone in 3D and the explode
transform-style: preserve-3d keeps the children in 3D space, which is what lets the layers separate. Each part gets a tiny translateZ from --z when closed and a big one from --open when the checkbox is checked. --d gives each layer its own delay, so they open one after another.
/* ---------- the phone: a 3D stack of parts ---------- */
.phone {
position: relative;
width: 260px;
height: 540px;
transform-style: preserve-3d;
transition: transform 1.4s cubic-bezier(.6, 0, .2, 1);
animation: float 6s ease-in-out infinite;
}
@keyframes float {
50% { translate: 0 -14px; }
}
.toggle:checked ~ .phone {
transform: translateY(-20px) rotateX(58deg) rotateZ(-38deg) scale(.6);
}
.part {
position: absolute;
inset: 0;
border-radius: 44px;
transform-style: preserve-3d;
transform: translateZ(calc(var(--z) * 1px));
transition: transform 1.4s cubic-bezier(.6, 0, .2, 1);
transition-delay: var(--d);
}
.back { --z: 0; --open: -290; --d: .2s; }
.battery { --z: 2; --open: -145; --d: .1s; }
.board { --z: 4; --open: 0; --d: 0s; }
.frame { --z: 6; --open: 145; --d: .1s; }
.screen { --z: 8; --open: 290; --d: .2s; }
.toggle:checked ~ .phone .part {
transform: translateZ(calc(var(--open) * 1px));
}6. Labels that face the viewer
The label is a ::after element with content: attr(data-label). The phone is rotated with rotateX(58deg) rotateZ(-38deg), so the label applies the opposite rotation in reverse order, rotateZ(38deg) rotateX(-58deg). The two cancel out and the text faces you.
/* ---------- labels: turned back to face the viewer ---------- */
.part::after {
content: attr(data-label);
position: absolute;
left: calc(100% + 30px);
top: 50%;
padding: 6px 0 6px 96px;
white-space: nowrap;
font-size: 28px;
font-weight: 700;
color: #fff;
background: linear-gradient(#fff, #fff) 0 50% / 84px 2px no-repeat;
opacity: 0;
transform-origin: 0 50%;
transform: translateY(-50%) rotateZ(38deg) rotateX(-58deg);
transition: opacity .5s;
}
.toggle:checked ~ .phone .part::after {
opacity: 1;
transition-delay: calc(var(--d) + 1.2s);
}7. Back glass, camera and logo
Each lens is a single radial-gradient: a blue reflection, dark glass and a grey ring. The logo is a conic-gradient circle with a mask that cuts out the middle, turning it into a ring.
/* ---------- 1. back glass + camera ---------- */
.back {
background: linear-gradient(145deg, #2c2f3d, #14161e);
box-shadow: inset 0 0 0 2px #ffffff18, 0 30px 60px #000a;
}
.cam {
position: absolute;
top: 22px;
left: 22px;
display: grid;
grid-template-columns: 1fr 1fr;
place-items: center;
width: 112px;
height: 112px;
padding: 8px;
box-sizing: border-box;
border-radius: 30px;
background: #1c1f28;
box-shadow: inset 0 0 0 2px #ffffff1c, 0 8px 20px #0008;
}
.lens {
width: 40px;
height: 40px;
border-radius: 50%;
background: radial-gradient(circle at 35% 35%,
#6b7fc0 0 8%, #0a0c12 28% 62%, #2b2f3d 64%);
box-shadow: 0 0 0 3px #3b4050;
}
.flash {
width: 16px;
height: 16px;
border-radius: 50%;
background: radial-gradient(#fff7d6, #e3be5c);
}
.logo {
position: absolute;
top: 50%;
left: 50%;
width: 56px;
height: 56px;
translate: -50% -50%;
border-radius: 50%;
background: conic-gradient(#7c5cff, #22d3ee, #ff4fd8, #7c5cff);
mask: radial-gradient(circle, #0000 44%, #000 46%);
}8. Battery and logic board
The circuit board uses no images at all: two repeating-linear-gradients (vertical and horizontal lines) on top of a dark green gradient. The chips get a golden border from box-shadow.
/* ---------- 2. battery ---------- */
.battery {
display: grid;
place-items: center;
}
.cell {
position: relative;
display: grid;
place-content: center;
gap: 6px;
width: 196px;
height: 330px;
border-radius: 22px;
text-align: center;
color: #e8ecff;
background: linear-gradient(160deg, #3c4050, #1e212b);
box-shadow: inset 0 0 0 2px #ffffff22, 0 0 40px #22c55e40;
}
.cell b { font-size: 30px; }
.cell small { font-size: 14px; color: #8f96b3; }
.cell::before {
content: "";
position: absolute;
top: -12px;
left: 50%;
width: 70px;
height: 14px;
translate: -50% 0;
border-radius: 4px;
background: linear-gradient(#e7c66b, #b8912f);
}
/* ---------- 3. logic board ---------- */
.board {
inset: 14px;
border-radius: 34px;
background:
repeating-linear-gradient(90deg, #0000 0 22px, #2ee6a622 22px 24px),
repeating-linear-gradient(0deg, #0000 0 30px, #2ee6a61a 30px 32px),
linear-gradient(160deg, #0f3d2e, #072118);
box-shadow: inset 0 0 0 2px #2ee6a650;
}
.chip {
position: absolute;
display: grid;
place-items: center;
border-radius: 8px;
font: 800 20px system-ui;
color: #c9d1f0;
background: linear-gradient(145deg, #2b2e38, #121318);
box-shadow: 0 0 0 3px #c9a24a66, 0 6px 14px #000a;
}
.cpu { top: 110px; left: 60px; width: 110px; height: 110px; font-size: 28px; }
.ram { top: 250px; left: 66px; width: 98px; height: 54px; }
.modem { top: 330px; left: 116px; width: 70px; height: 70px; }9. Aluminium frame and the display
The frame is only inset box-shadows. The second side button is a box-shadow copy of the first one, 90px lower: one element, two buttons. The app icons all share one rule, hsl(var(--h) 90% 65%), and only --h changes per icon.
/* ---------- 4. aluminium frame + buttons ---------- */
.frame {
box-shadow:
inset 0 0 0 10px #a3acbf,
inset 0 0 0 11px #ffffff66,
0 0 0 1px #0007;
}
.frame::before {
content: "";
position: absolute;
top: 140px;
right: -5px;
width: 6px;
height: 70px;
border-radius: 3px;
background: #a3acbf;
box-shadow: 0 90px 0 #a3acbf;
}
/* ---------- 5. OLED display ---------- */
.screen {
inset: 10px;
border-radius: 36px;
text-align: center;
color: #fff;
background:
radial-gradient(120% 80% at 15% 0%, #7c5cff, #0000 60%),
radial-gradient(100% 70% at 100% 100%, #ff4fd8, #0000 60%),
linear-gradient(#151735, #070812);
box-shadow: 0 0 0 2px #000, 0 0 50px #7c5cff55;
}
.island {
width: 92px;
height: 28px;
margin: 14px auto 0;
border-radius: 20px;
background: #000;
}
.time {
margin-top: 54px;
font: 200 84px/1 system-ui;
letter-spacing: -2px;
}
.date {
margin-top: 6px;
font-size: 15px;
font-weight: 600;
opacity: .8;
}
.apps {
position: absolute;
left: 22px;
right: 22px;
bottom: 34px;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 16px;
}
.apps i {
aspect-ratio: 1;
border-radius: 14px;
background: linear-gradient(145deg,
hsl(var(--h) 90% 65%), hsl(calc(var(--h) + 40) 90% 45%));
box-shadow: 0 6px 14px #0006;
}Full source code
Copy both files into a folder, open index.html in your browser, and click Teardown.
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Smartphone Teardown</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="stage">
<input type="checkbox" id="tear" class="toggle">
<label for="tear" class="btn">
<span class="off">Teardown</span>
<span class="on">Assemble</span>
</label>
<div class="phone">
<div class="part back" data-label="Back glass">
<div class="cam">
<i class="lens"></i>
<i class="lens"></i>
<i class="lens"></i>
<i class="flash"></i>
</div>
<div class="logo"></div>
</div>
<div class="part battery" data-label="Battery">
<div class="cell">
<b>4,500 mAh</b>
<small>Li-ion · 3.87 V</small>
</div>
</div>
<div class="part board" data-label="Logic board">
<i class="chip cpu">P1</i>
<i class="chip ram">8 GB</i>
<i class="chip modem">5G</i>
</div>
<div class="part frame" data-label="Aluminium frame"></div>
<div class="part screen" data-label="OLED display">
<div class="island"></div>
<div class="time">9:41</div>
<div class="date">Tuesday, 1 December</div>
<div class="apps">
<i style="--h: 200"></i>
<i style="--h: 140"></i>
<i style="--h: 20"></i>
<i style="--h: 280"></i>
<i style="--h: 330"></i>
<i style="--h: 50"></i>
<i style="--h: 170"></i>
<i style="--h: 240"></i>
</div>
</div>
</div>
</div>
</body>
</html>style.css
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: radial-gradient(1200px 800px at 50% 40%, #12152a, #06070d);
}
/* ---------- the scene ---------- */
.stage {
position: relative;
display: grid;
place-items: center;
width: 960px;
height: 760px;
perspective: 2200px;
font-family: system-ui, sans-serif;
}
.stage::after {
content: "";
position: absolute;
bottom: 70px;
width: 300px;
height: 40px;
border-radius: 50%;
background: radial-gradient(#0008, #0000 70%);
}
/* ---------- the button (a label for the hidden checkbox) ---------- */
.toggle { display: none; }
.btn {
position: absolute;
bottom: 0;
z-index: 5;
padding: 14px 36px;
border-radius: 99px;
font-size: 20px;
font-weight: 800;
color: #fff;
background: linear-gradient(90deg, #7c5cff, #22d3ee);
box-shadow: 0 10px 30px #7c5cff66;
cursor: pointer;
transition: transform .2s;
}
.btn:hover { transform: scale(1.06); }
.btn .on,
.toggle:checked ~ .btn .off { display: none; }
.toggle:checked ~ .btn .on { display: inline; }
/* ---------- the phone: a 3D stack of parts ---------- */
.phone {
position: relative;
width: 260px;
height: 540px;
transform-style: preserve-3d;
transition: transform 1.4s cubic-bezier(.6, 0, .2, 1);
animation: float 6s ease-in-out infinite;
}
@keyframes float {
50% { translate: 0 -14px; }
}
.toggle:checked ~ .phone {
transform: translateY(-20px) rotateX(58deg) rotateZ(-38deg) scale(.6);
}
.part {
position: absolute;
inset: 0;
border-radius: 44px;
transform-style: preserve-3d;
transform: translateZ(calc(var(--z) * 1px));
transition: transform 1.4s cubic-bezier(.6, 0, .2, 1);
transition-delay: var(--d);
}
.back { --z: 0; --open: -290; --d: .2s; }
.battery { --z: 2; --open: -145; --d: .1s; }
.board { --z: 4; --open: 0; --d: 0s; }
.frame { --z: 6; --open: 145; --d: .1s; }
.screen { --z: 8; --open: 290; --d: .2s; }
.toggle:checked ~ .phone .part {
transform: translateZ(calc(var(--open) * 1px));
}
/* ---------- labels: turned back to face the viewer ---------- */
.part::after {
content: attr(data-label);
position: absolute;
left: calc(100% + 30px);
top: 50%;
padding: 6px 0 6px 96px;
white-space: nowrap;
font-size: 28px;
font-weight: 700;
color: #fff;
background: linear-gradient(#fff, #fff) 0 50% / 84px 2px no-repeat;
opacity: 0;
transform-origin: 0 50%;
transform: translateY(-50%) rotateZ(38deg) rotateX(-58deg);
transition: opacity .5s;
}
.toggle:checked ~ .phone .part::after {
opacity: 1;
transition-delay: calc(var(--d) + 1.2s);
}
/* ---------- 1. back glass + camera ---------- */
.back {
background: linear-gradient(145deg, #2c2f3d, #14161e);
box-shadow: inset 0 0 0 2px #ffffff18, 0 30px 60px #000a;
}
.cam {
position: absolute;
top: 22px;
left: 22px;
display: grid;
grid-template-columns: 1fr 1fr;
place-items: center;
width: 112px;
height: 112px;
padding: 8px;
box-sizing: border-box;
border-radius: 30px;
background: #1c1f28;
box-shadow: inset 0 0 0 2px #ffffff1c, 0 8px 20px #0008;
}
.lens {
width: 40px;
height: 40px;
border-radius: 50%;
background: radial-gradient(circle at 35% 35%,
#6b7fc0 0 8%, #0a0c12 28% 62%, #2b2f3d 64%);
box-shadow: 0 0 0 3px #3b4050;
}
.flash {
width: 16px;
height: 16px;
border-radius: 50%;
background: radial-gradient(#fff7d6, #e3be5c);
}
.logo {
position: absolute;
top: 50%;
left: 50%;
width: 56px;
height: 56px;
translate: -50% -50%;
border-radius: 50%;
background: conic-gradient(#7c5cff, #22d3ee, #ff4fd8, #7c5cff);
mask: radial-gradient(circle, #0000 44%, #000 46%);
}
/* ---------- 2. battery ---------- */
.battery {
display: grid;
place-items: center;
}
.cell {
position: relative;
display: grid;
place-content: center;
gap: 6px;
width: 196px;
height: 330px;
border-radius: 22px;
text-align: center;
color: #e8ecff;
background: linear-gradient(160deg, #3c4050, #1e212b);
box-shadow: inset 0 0 0 2px #ffffff22, 0 0 40px #22c55e40;
}
.cell b { font-size: 30px; }
.cell small { font-size: 14px; color: #8f96b3; }
.cell::before {
content: "";
position: absolute;
top: -12px;
left: 50%;
width: 70px;
height: 14px;
translate: -50% 0;
border-radius: 4px;
background: linear-gradient(#e7c66b, #b8912f);
}
/* ---------- 3. logic board ---------- */
.board {
inset: 14px;
border-radius: 34px;
background:
repeating-linear-gradient(90deg, #0000 0 22px, #2ee6a622 22px 24px),
repeating-linear-gradient(0deg, #0000 0 30px, #2ee6a61a 30px 32px),
linear-gradient(160deg, #0f3d2e, #072118);
box-shadow: inset 0 0 0 2px #2ee6a650;
}
.chip {
position: absolute;
display: grid;
place-items: center;
border-radius: 8px;
font: 800 20px system-ui;
color: #c9d1f0;
background: linear-gradient(145deg, #2b2e38, #121318);
box-shadow: 0 0 0 3px #c9a24a66, 0 6px 14px #000a;
}
.cpu { top: 110px; left: 60px; width: 110px; height: 110px; font-size: 28px; }
.ram { top: 250px; left: 66px; width: 98px; height: 54px; }
.modem { top: 330px; left: 116px; width: 70px; height: 70px; }
/* ---------- 4. aluminium frame + buttons ---------- */
.frame {
box-shadow:
inset 0 0 0 10px #a3acbf,
inset 0 0 0 11px #ffffff66,
0 0 0 1px #0007;
}
.frame::before {
content: "";
position: absolute;
top: 140px;
right: -5px;
width: 6px;
height: 70px;
border-radius: 3px;
background: #a3acbf;
box-shadow: 0 90px 0 #a3acbf;
}
/* ---------- 5. OLED display ---------- */
.screen {
inset: 10px;
border-radius: 36px;
text-align: center;
color: #fff;
background:
radial-gradient(120% 80% at 15% 0%, #7c5cff, #0000 60%),
radial-gradient(100% 70% at 100% 100%, #ff4fd8, #0000 60%),
linear-gradient(#151735, #070812);
box-shadow: 0 0 0 2px #000, 0 0 50px #7c5cff55;
}
.island {
width: 92px;
height: 28px;
margin: 14px auto 0;
border-radius: 20px;
background: #000;
}
.time {
margin-top: 54px;
font: 200 84px/1 system-ui;
letter-spacing: -2px;
}
.date {
margin-top: 6px;
font-size: 15px;
font-weight: 600;
opacity: .8;
}
.apps {
position: absolute;
left: 22px;
right: 22px;
bottom: 34px;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 16px;
}
.apps i {
aspect-ratio: 1;
border-radius: 14px;
background: linear-gradient(145deg,
hsl(var(--h) 90% 65%), hsl(calc(var(--h) + 40) 90% 45%));
box-shadow: 0 6px 14px #0006;
}FAQ
Can you build interactive things without JavaScript?
Yes, for many UI states. A hidden checkbox plus :checked and the ~ combinator can toggle menus, modals, tabs and, as you saw here, 3D animations.
Why don't my layers separate in 3D?
Check that the parent has transform-style: preserve-3d. Without it, the browser flattens the children into one plane.
Does this work in all browsers?
Yes, in all modern browsers (Chrome, Edge, Firefox and Safari).
Conclusion
You just built a 3D smartphone that comes apart with one click, using only HTML and CSS. The key ideas: a hidden checkbox as the switch, preserve-3d to keep layers in 3D space, translateZ to move them apart, and a reverse rotation so the labels always face the viewer. Try changing the layers, colours or angles and make it your own!
Liked this project?
Subscribe to @web_dev_with_pritom for a new unique CSS project every week.

