CSS Dark Mode Elevation
Elevation for dark themes, where higher surfaces get lighter instead of relying on shadows alone.
1
2
3
4
HTML
<div class="dm-surface dm-level-1">1</div>
<div class="dm-surface dm-level-2">2</div>
<div class="dm-surface dm-level-3">3</div>
<div class="dm-surface dm-level-4">4</div>
CSS
/* Page background: #121212 */
.dm-surface {
display: grid;
place-items: center;
width: 48px;
height: 48px;
border-radius: 12px;
color: #e0e0e0;
font: 600 14px system-ui, sans-serif;
}
.dm-level-1 {
background: #1e1e1e;
box-shadow: 0 1px 2px #00000066;
}
.dm-level-2 {
background: #242424;
box-shadow: 0 2px 6px #00000080;
}
.dm-level-3 {
background: #2c2c2c;
box-shadow: 0 6px 14px #00000099;
}
.dm-level-4 {
background: #383838;
box-shadow: 0 12px 28px #000000b3;
}
About this CSS Dark Mode Elevation
This CSS Dark Mode Elevation is 30 lines of pure CSS (0.5 KB) with no JavaScript and no dependencies. It uses box shadows and CSS Grid. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#121212#e0e0e0#1e1e1e#00000066#242424#00000080#2c2c2c#00000099#383838#000000b3
How to use this dark mode elevation
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.dm-surfaceclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.