SolutionsCase StudiesAI ToolsResourcesAboutContact
Get Your Free AI Automation Audit Book a Free 30-Minute Strategy Call
Playground~/frontend Open editor

~/css/dark-mode-ui

7 CSS Dark Mode UI

6 Pure CSS1 with JSPublished 2026-10-05Free · no sign-up

Seven components designed for dark screens rather than inverted from light ones: a button set with tinted primaries, cards that rise with lighter surfaces, dark form fields, an app sidebar, status alerts with desaturated colours, a modal and a chart card.

01. Button Set for Dark Interfaces

Dark UIButtons

Primary, secondary and ghost buttons tuned for a dark background: the primary uses a lighter tint of the brand colour with dark text, because saturated colours on near-black vibrate and white text on them often fails contrast.

View code
<div class="dku1"><button class="p">Publish</button><button class="s">Preview</button><button class="g">Cancel</button></div>
.dku1 { display: flex; flex-wrap: wrap; gap: 10px; font: 600 14px Inter, system-ui, sans-serif; }
.dku1 button { padding: 10px 18px; border-radius: 10px; font: inherit; cursor: pointer; }
.dku1 .p { border: 0; background: #a5b4fc; color: #1e1b4b; } .dku1 .p:hover { background: #c7d2fe; }
.dku1 .s { border: 1px solid #3f4663; background: #1b2033; color: #e2e8f0; } .dku1 .s:hover { background: #242a40; }
.dku1 .g { border: 0; background: none; color: #a1a9c3; } .dku1 .g:hover { color: #fff; }
.dku1 button:focus-visible { outline: 2px solid #c7d2fe; outline-offset: 2px; }

02. Elevated Card on Dark

Dark UICard

On dark backgrounds elevation is shown by lighter surfaces and a faint top border highlight, since shadows barely show. The card uses three greys for page, card and inset area, and text in two tones for hierarchy.

View code
<article class="dku2"><p class="k">Storage</p><p class="v">68.4 GB <span>of 100 GB</span></p><div class="bar" role="img" aria-label="68 percent used"><span style="width:68%"></span></div></article>
.dku2 { width: 260px; max-width: 100%; padding: 18px; box-sizing: border-box; border-radius: 16px; background: #161b28; box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 12px 24px -12px #000; font: 14px Inter, system-ui, sans-serif; }
.dku2 .k { margin: 0; color: #8b93a8; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.dku2 .v { margin: 4px 0 12px; color: #f3f4f6; font-size: 24px; font-weight: 800; } .dku2 .v span { color: #8b93a8; font-size: 14px; font-weight: 500; }
.dku2 .bar { height: 8px; border-radius: 4px; background: #0d111b; } .dku2 .bar span { display: block; height: 100%; border-radius: 4px; background: #5eead4; }

03. Dark Form Fields

Dark UIForm

Inputs on a dark surface that are darker than the surface, with a border light enough to find, placeholder text that still passes contrast and a bright focus ring. Native controls get color-scheme: dark so their own parts match.

View code
<form class="dku3"><label>Project name<input value="Atlas redesign"></label><label>Visibility<select><option>Team</option><option>Private</option></select></label><label>Due date<input type="date" value="2026-11-14"></label></form>
.dku3 { display: grid; gap: 12px; width: 280px; max-width: 100%; padding: 18px; box-sizing: border-box; border-radius: 16px; background: #161b28; color-scheme: dark; font: 14px Inter, system-ui, sans-serif; }
.dku3 label { display: grid; gap: 4px; color: #c3c9da; font-weight: 600; font-size: 13px; }
.dku3 input, .dku3 select { min-width: 0; padding: 9px 10px; border: 1px solid #353c55; border-radius: 8px; background: #0d111b; color: #f3f4f6; font: 14px Inter, system-ui, sans-serif; }
.dku3 input:focus, .dku3 select:focus { outline: none; border-color: #818cf8; box-shadow: 0 0 0 3px rgba(129,140,248,.35); }

04. Dark App Navigation

Dark UINavigation

A dark sidebar where the current item is shown with a subtle lighter background and a coloured icon, rather than a bright block that would dominate a dark screen. Inactive items are dimmer but still pass contrast.

View code
<nav class="dku4" aria-label="App"><a href="#home" aria-current="page"><span aria-hidden="true">◆</span>Overview</a><a href="#tasks"><span aria-hidden="true">✓</span>Tasks</a><a href="#files"><span aria-hidden="true">▤</span>Files</a><a href="#team"><span aria-hidden="true">☺</span>Team</a></nav>
.dku4 { display: grid; gap: 2px; width: 200px; padding: 8px; border-radius: 14px; background: #10141f; font: 14px Inter, system-ui, sans-serif; }
.dku4 a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #9aa2b9; text-decoration: none; }
.dku4 a:hover { background: #171c2a; color: #e5e7eb; }
.dku4 a[aria-current] { background: #1c2234; color: #f9fafb; } .dku4 a[aria-current] span { color: #a5b4fc; }
.dku4 a:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 1px; }

05. Desaturated Alerts for Dark Mode

Dark UIAlerts

Status colours from a light theme glare on dark backgrounds. These alerts use deep tinted backgrounds with light, desaturated text in the same hue, which keeps the meaning of green, amber and red without the glow.

View code
<div class="dku5"><p class="ok"><b>Deployed.</b> Version 4.2 is live.</p><p class="warn"><b>Heads up.</b> Certificate expires in 9 days.</p><p class="err"><b>Failed.</b> Build 812 has 2 errors.</p></div>
.dku5 { display: grid; gap: 8px; width: 300px; max-width: 100%; font: 14px Inter, system-ui, sans-serif; }
.dku5 p { margin: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid; }
.dku5 .ok { background: #0b2418; border-color: #14532d; color: #bbf7d0; }
.dku5 .warn { background: #2a1d07; border-color: #713f12; color: #fde68a; }
.dku5 .err { background: #2a0e10; border-color: #7f1d1d; color: #fecaca; }

06. Dark Modal Dialog

Dark UIDialog

A modal on a dark interface: the dialog is lighter than the page so it reads as raised, the backdrop darkens the page further, and the destructive button uses a softened red. It is a native dialog with focus handling built in.

View code
<div class="dku6"><button class="open">Remove member</button><dialog aria-labelledby="dku6h"><h3 id="dku6h">Remove Jonas?</h3><p>He will lose access to 4 projects.</p><div><button class="c">Cancel</button><button class="r">Remove</button></div></dialog></div>
.dku6 { font: 14px Inter, system-ui, sans-serif; }
.dku6 .open { padding: 9px 14px; border: 1px solid #3f4663; border-radius: 8px; background: #1b2033; color: #e2e8f0; font: 600 14px Inter, system-ui, sans-serif; cursor: pointer; }
.dku6 dialog { width: min(280px, 90vw); padding: 20px; border: 1px solid #2c3349; border-radius: 16px; background: #1b2132; color: #e5e7eb; }
.dku6 dialog::backdrop { background: rgba(3,6,14,.75); }
.dku6 h3 { margin: 0 0 6px; color: #fff; } .dku6 p { margin: 0 0 16px; color: #a1a9c3; }
.dku6 dialog div { display: flex; justify-content: flex-end; gap: 8px; }
.dku6 dialog button { padding: 8px 14px; border-radius: 8px; font: 600 14px Inter, system-ui, sans-serif; cursor: pointer; }
.dku6 .c { border: 1px solid #3f4663; background: transparent; color: #e5e7eb; } .dku6 .r { border: 0; background: #f87171; color: #2a0e10; }
.dku6 button:focus-visible { outline: 2px solid #c7d2fe; outline-offset: 2px; }
var d = document.querySelector('.dku6 dialog');
document.querySelector('.dku6 .open').onclick = function () { d.showModal(); };
d.querySelectorAll('button').forEach(function (b) { b.onclick = function () { d.close(); }; });

07. Dark Chart Card

Dark UIData

A chart card for dark dashboards: gridlines barely visible, bars in one bright accent with the latest bar highlighted, and labels in a muted grey. Each bar is a list item carrying its value as hidden text.

View code
<section class="dku7" aria-labelledby="dku7h"><h3 id="dku7h">Signups, last 6 weeks</h3><ul><li style="--v:40"><span class="sr">Week 1: 40</span></li><li style="--v:55"><span class="sr">Week 2: 55</span></li><li style="--v:48"><span class="sr">Week 3: 48</span></li><li style="--v:70"><span class="sr">Week 4: 70</span></li><li style="--v:66"><span class="sr">Week 5: 66</span></li><li style="--v:88"><span class="sr">Week 6: 88</span></li></ul></section>
.dku7 { width: 280px; max-width: 100%; padding: 16px; box-sizing: border-box; border-radius: 16px; background: #161b28; font: 14px Inter, system-ui, sans-serif; }
.dku7 h3 { margin: 0 0 12px; color: #e5e7eb; font-size: 14px; }
.dku7 ul { display: flex; align-items: flex-end; gap: 8px; height: 120px; margin: 0; padding: 0; list-style: none; background: repeating-linear-gradient(#232a3d 0 1px, transparent 1px 30px); }
.dku7 li { flex: 1; height: calc(var(--v) * 1%); border-radius: 4px 4px 0 0; background: #4c5578; }
.dku7 li:last-child { background: #a5b4fc; }
.dku7 .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

About these CSS Dark Mode UI

Lighter means higher

On dark backgrounds, shadows disappear, so raised surfaces get lighter backgrounds and a faint top highlight. Use three or four surface greys in steps.

Desaturate the brand

Fully saturated colours vibrate on near-black. Use lighter, softer tints of your brand and status colours, with dark text on filled buttons.

Avoid pure black and white

Very dark grey backgrounds and off-white text reduce glare and halation, while still passing contrast comfortably.

Let native parts match

Set color-scheme: dark so scrollbars, date pickers and select menus use their dark versions too.

Frequently asked questions

Is dark mode just inverted colours?

No. Inverting breaks hierarchy and colour meaning; dark UI needs its own palette.

How do I switch between light and dark?

See the dark mode variables and toggles collections for the theme system and controls.

What contrast should dark text use?

The same WCAG 4.5:1 for body text; check light text against each surface grey.