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

~/css/tailwind-dark-mode-ui

6 Tailwind Dark Mode UI

5 Tailwind1 with JSPublished 2026-10-05Free · no sign-up

Six dark mode patterns in Tailwind: lighter surfaces for elevation, a dashboard panel with a clear text hierarchy, a card switched by a dark: toggle, form fields for dark pages, a card that follows the system theme and a code window.

01. Tailwind Dark Surfaces and Elevation

TailwindDark modeElevation

In dark interfaces, raised things get lighter rather than casting bigger shadows. Three slate steps from 950 to 700 show the page, a card and a menu on top, each one a little lighter than the layer below.

View code
<div class="w-full max-w-xs rounded-2xl bg-slate-950 p-4 ring-1 ring-white/10">
  <p class="text-xs font-semibold uppercase tracking-wider text-slate-400">Page · slate-950</p>
  <div class="mt-3 rounded-xl bg-slate-900 p-4 ring-1 ring-white/10">
    <p class="text-sm font-semibold text-slate-100">Card · slate-900</p>
    <div class="mt-3 rounded-lg bg-slate-800 p-3 shadow-lg ring-1 ring-white/10"><p class="text-sm text-slate-200">Menu · slate-800</p><p class="mt-2 rounded-md bg-slate-700 px-2 py-1 text-xs text-white">Hovered item · slate-700</p></div>
  </div>
</div>

02. Tailwind Dark Dashboard Panel

TailwindDark modeDashboard

A dark stats panel with a clear text hierarchy: white for numbers, slate-300 for labels and slate-400 for hints, all above 4.5:1. Accent colours are lighter shades such as emerald-400, which read better on dark than the 600s.

View code
<section class="w-full max-w-xs rounded-2xl bg-slate-900 p-5 ring-1 ring-white/10">
  <div class="flex items-center justify-between"><h3 class="text-sm font-semibold text-slate-300">Revenue</h3><span class="rounded-full bg-emerald-400/10 px-2 py-0.5 text-xs font-semibold text-emerald-400">↑ 8.2%</span></div>
  <p class="mt-2 text-3xl font-bold text-white">$12,480</p>
  <p class="mt-1 text-xs text-slate-400">Compared with the previous 30 days</p>
  <div aria-hidden="true" class="mt-4 flex h-16 items-end gap-1.5"><span class="h-[40%] flex-1 rounded-sm bg-slate-700"></span><span class="h-[55%] flex-1 rounded-sm bg-slate-700"></span><span class="h-[45%] flex-1 rounded-sm bg-slate-700"></span><span class="h-[70%] flex-1 rounded-sm bg-slate-600"></span><span class="h-full flex-1 rounded-sm bg-emerald-400"></span></div>
</section>

03. Tailwind Light and Dark Toggle with dark:

TailwindDark modeToggle

One card written once with dark: variants, switched by a button that adds the dark class to its wrapper. The Tailwind config sets darkMode to class, so the theme follows the toggle instead of the operating system.

View code
<div id="twdm3" class="w-full max-w-xs">
  <div class="rounded-2xl bg-white p-5 ring-1 ring-slate-200 transition-colors dark:bg-slate-900 dark:ring-white/10">
    <div class="flex items-center justify-between"><h3 class="font-bold text-slate-900 dark:text-white">Notifications</h3><button id="twdm3b" type="button" aria-pressed="false" class="rounded-full bg-slate-100 px-3 py-1 text-xs font-semibold text-slate-800 hover:bg-slate-200 focus-visible:outline focus-visible:outline-2 focus-visible:outline-indigo-600 dark:bg-slate-800 dark:text-slate-100 dark:hover:bg-slate-700">🌙 Dark mode</button></div>
    <p class="mt-2 text-sm text-slate-600 dark:text-slate-300">Order #1042 has shipped and arrives Thursday.</p>
    <a href="#track" class="mt-3 inline-block text-sm font-semibold text-indigo-700 hover:underline dark:text-indigo-300">Track parcel →</a>
  </div>
</div>
tailwind.config = { darkMode: 'class' };
var w = document.getElementById('twdm3'), b = document.getElementById('twdm3b');
b.onclick = function () { var on = w.classList.toggle('dark'); b.setAttribute('aria-pressed', on); };

04. Tailwind Dark Form Fields

TailwindDark modeForm

Inputs for dark pages: a slightly lighter field than the surface, a visible border, a readable placeholder and a bright focus ring. color-scheme: dark is set so native parts like the date picker turn dark too.

View code
<form class="grid w-full max-w-xs gap-3 rounded-2xl bg-slate-900 p-5 ring-1 ring-white/10 [color-scheme:dark]">
  <label class="grid gap-1 text-sm font-medium text-slate-200">Project name<input type="text" placeholder="Spring launch" class="rounded-lg border border-slate-600 bg-slate-800 px-3 py-2 text-white placeholder:text-slate-400 focus:border-sky-400 focus:outline-none focus:ring-2 focus:ring-sky-400/40"></label>
  <label class="grid gap-1 text-sm font-medium text-slate-200">Start date<input type="date" class="rounded-lg border border-slate-600 bg-slate-800 px-3 py-2 text-white focus:border-sky-400 focus:outline-none focus:ring-2 focus:ring-sky-400/40"></label>
  <button type="button" class="rounded-lg bg-sky-400 py-2 text-sm font-bold text-slate-950 hover:bg-sky-300 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-300">Create</button>
</form>

05. Tailwind Card that Follows the System Theme

TailwindDark modeprefers-color-scheme

With Tailwind's default media strategy, dark: utilities follow the visitor's operating system setting through prefers-color-scheme. Switch your system to dark mode and this card changes with no script.

View code
<article class="w-full max-w-xs rounded-2xl bg-white p-5 shadow-sm ring-1 ring-slate-200 dark:bg-slate-900 dark:ring-white/10">
  <p class="text-xs font-bold uppercase tracking-wider text-indigo-700 dark:text-indigo-300">Follows your system</p>
  <h3 class="mt-1 font-bold text-slate-900 dark:text-white">Weekly summary</h3>
  <p class="mt-1 text-sm text-slate-600 dark:text-slate-300">Switch your device to dark mode and this card switches too.</p>
</article>

06. Tailwind Dark Code Window

TailwindDark modeCode

A dark code window with traffic-light dots, a file name and colour-coded lines. The syntax colours are the 300 shades of the palette, which keep at least 4.5:1 against the near-black background.

View code
<figure class="w-full max-w-xs overflow-hidden rounded-xl bg-[#0d1117] shadow-xl ring-1 ring-black/20">
  <figcaption class="flex items-center gap-1.5 border-b border-white/10 px-3 py-2"><span aria-hidden="true" class="size-2.5 rounded-full bg-red-400"></span><span aria-hidden="true" class="size-2.5 rounded-full bg-amber-300"></span><span aria-hidden="true" class="size-2.5 rounded-full bg-emerald-400"></span><span class="ml-2 font-mono text-xs text-slate-400">theme.js</span></figcaption>
  <pre class="overflow-x-auto p-3 font-mono text-xs leading-6 text-slate-200"><code><span class="text-violet-300">const</span> theme <span class="text-sky-300">=</span> {
  mode: <span class="text-emerald-300">'dark'</span>,
  accent: <span class="text-emerald-300">'#38bdf8'</span>,
};</code></pre>
</figure>

About these Tailwind Dark Mode UI

Media or class

By default, dark: follows the system through prefers-color-scheme. Set darkMode: 'class' in the config to switch with a class on a parent instead, for a manual toggle.

Elevation by lightness

In dark themes, raised layers get lighter: slate-950 for the page, 900 for cards, 800 for menus. Shadows barely show on dark.

Lighter accents

Use the 300 or 400 shades for links and accents on dark backgrounds; the 600s that work on white are too dark.

Native controls too

[color-scheme:dark] turns date pickers, scrollbars and other built-in parts dark to match.

Frequently asked questions

Should I remember the visitor's choice?

Yes. Save the toggle in localStorage and apply the class before the page paints to avoid a flash.

Is pure black a good background?

Very dark grey or slate is easier on the eyes and lets elevation show.

Is there a CSS version?

Yes, see the CSS dark mode UI collection.