Back to Blog

Dark Mode Web Design: A Practical Guide to Designing and Building It

TL;DRGood dark mode is a second, deliberately designed color scheme, not inverted colors. Use dark gray rather than pure black, off-white text, desaturated accents and lighter surfaces for elevation, and keep WCAG contrast at 4.5:1 for normal text. Follow prefers-color-scheme by default and add a toggle that remembers the choice. The eye-strain benefits are mixed, so offer it as an option.

A client asks for dark mode, and it sounds like a quick job: swap the background to black and the text to white. Then the logo vanishes, the photos glare, the buttons blend into the page, and the site flashes white on every load. Good dark mode is a second, deliberately designed color scheme, not an inverted one. This guide covers when it’s worth offering, the color and contrast rules that keep it readable, and the CSS and JavaScript to build it properly.

dark mode

What is dark mode web design?

Dark mode is a color scheme that uses dark backgrounds with light text and interface elements, offered alongside or instead of a standard light theme. On the web, it usually means a site that follows the visitor’s operating system setting and, ideally, lets them switch themes manually.

The idea isn’t new. Early computer terminals showed light text on dark screens, and code editors have long defaulted to dark themes. It went mainstream once operating systems added system-wide dark modes, starting with macOS Mojave in 2018 and followed by iOS 13 and Android 10 in 2019. Browsers then added the prefers-color-scheme media query, which lets a website detect that setting and respond to it.

Should your website offer dark mode?

Offer dark mode when your visitors spend long sessions with your site, use it at night or in dim rooms, or already expect it from the apps and operating systems they use. Many people now set their devices to dark, so a bright white site can feel jarring to them.

It tends to make most sense for:

  • Web apps, dashboards and SaaS tools people keep open for hours
  • Documentation, developer tools and long-form reading
  • Media, gaming and entertainment sites, where dark backgrounds suit images and video
  • Sites whose audience is mostly on mobile at night

It’s a lower priority for a small brochure site that people visit briefly, or for brands whose identity depends heavily on light colors. Dark mode doubles the color states you need to design and test, so treat it as a real feature with ongoing upkeep, not a toggle you add and forget.

Does dark mode reduce eye strain and improve readability?

The evidence is mixed. Dark mode can feel more comfortable in low light because the screen emits less overall light, but research on reading has generally found that dark text on a light background is read as well or better by most people with typical vision in normal lighting.

A few points are well established:

  • Lighting matters: in a dark room, a bright white page causes glare; in daylight, light themes are usually easier to read.
  • It varies by person: some people with light sensitivity or certain eye conditions find dark themes easier, while many people with astigmatism find light text on dark backgrounds looks blurry or “glows.”
  • Battery savings are real but limited: on OLED and AMOLED screens, dark pixels use less power, so dark themes can save battery, mostly at higher brightness. On LCD screens the backlight stays on, so savings are minimal.

What reliably reduces strain and improves readability on any web page isn’t the color scheme on its own. It’s sufficient text contrast, a comfortable font size, generous line spacing, sensible line length, and letting people choose the theme that suits their eyes and surroundings. That’s the strongest case for dark mode: as an option, not a replacement.

Developer working at a computer in a dimly lit room

What colors work best for dark mode?

Use a dark gray background instead of pure black, off-white text instead of pure white, and slightly desaturated versions of your brand colors. This keeps contrast high without the harsh glare and “vibrating” edges that pure extremes create.

Avoid pure black and pure white

White text on #000000 produces maximum contrast, which sounds ideal but tends to cause glare and halation, especially for people with astigmatism. A dark gray such as #121212 (the base surface Google’s Material Design recommends) or a dark tone of your brand color reads more comfortably. For body text, an off-white around #e0e0e0 to #ececec usually works better than #ffffff.

Desaturate accent colors

Fully saturated colors look much more intense on dark backgrounds and can strain the eyes. Use lighter, less saturated tints of your brand colors for links, buttons and highlights in dark mode, and reserve the strongest colors for small accents.

Don’t rely on inversion

Automatic inversion flips images, shadows and brand colors in ways nobody designed. Instead, define each color as a token (background, surface, text, muted text, border, accent) and give every token a deliberate light and dark value.

What contrast ratios does dark mode need?

Dark mode must meet the same WCAG contrast requirements as light mode: at least 4.5:1 for normal text and 3:1 for large text (roughly 24px regular or 18.66px bold and up). Buttons, form fields, focus indicators and meaningful icons need at least 3:1 against their surroundings.

Check every text and component color pair in both themes with a contrast checker or your browser’s developer tools. Common dark mode failures include gray placeholder text, muted secondary text, thin borders on inputs, and focus outlines that disappeared because they were tuned for a white page. Aim for high contrast without jumping straight to the maximum; very light gray on dark gray easily clears 4.5:1 and is easier on the eyes than pure white on black.

How do you show depth and elevation in dark mode?

Use lighter surfaces for elements that sit “higher,” because shadows barely show on dark backgrounds. A card, menu or modal should be a step lighter than the page behind it, and the higher it sits, the lighter it gets.

A simple scale might be a page background of #121212, cards around #1e1e1e, and menus and dialogs around #2a2a2a. Add subtle borders where surfaces sit next to each other with little contrast between them, and keep shadows for the light theme where they still read clearly.

How should images and logos work in dark mode?

Most photos can stay as they are, but logos, icons, illustrations and screenshots often need dark-specific versions. Anything with a transparent background and dark artwork can disappear against a dark page.

  • Logos and icons: provide a light version of the logo, or use SVGs that inherit currentColor so they follow the text color automatically.
  • Illustrations and diagrams: serve a dark variant, or place them on a light card so they keep their intended look.
  • Photos: very bright photos can glare in dark mode; a slight reduction in brightness (for example with a CSS filter) can help, but test it so images don’t look dull.
  • Screenshots: if you show your own product, offer dark screenshots in dark mode where possible.

The HTML <picture> element can swap images based on the theme:

<picture>
  <source srcset="logo-light.svg" media="(prefers-color-scheme: dark)">
  <img src="logo-dark.svg" alt="Company name">
</picture>

Note that this follows the system setting only. If your site also has a manual toggle, swap image sources or styles with the same theme attribute your CSS uses.

How do you build dark mode with prefers-color-scheme?

Define your colors as CSS custom properties, set light values by default, and override them inside a prefers-color-scheme: dark media query. Every component then uses the variables, so the whole site switches with the system setting.

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --surface: #f4f4f5;
  --text: #1a1a1a;
  --text-muted: #555555;
  --accent: #1d4ed8;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --surface: #1e1e1e;
    --text: #e6e6e6;
    --text-muted: #a3a3a3;
    --accent: #8ab4f8;
  }
}

:root[data-theme="dark"] {
  --bg: #121212;
  --surface: #1e1e1e;
  --text: #e6e6e6;
  --text-muted: #a3a3a3;
  --accent: #8ab4f8;
}

body {
  background: var(--bg);
  color: var(--text);
}

The color-scheme property tells the browser to render built-in elements such as scrollbars and form controls in the matching theme. The data-theme selectors let a manual choice override the system setting in either direction, which the toggle below relies on.

How do you add a dark mode toggle that remembers the choice?

Add a button that sets a data-theme attribute on the <html> element and saves the choice in localStorage, then reapply that choice before the page renders. Applying it early prevents the “flash” of the wrong theme on page load.

Put this small script in the <head>, before your stylesheet loads:

<script>
  try {
    var saved = localStorage.getItem('theme');
    if (saved) document.documentElement.dataset.theme = saved;
  } catch (e) {}
</script>

Then wire up the button anywhere in the page:

<button type="button" id="theme-toggle" aria-pressed="false">Dark mode</button>

<script>
  var root = document.documentElement;
  var btn = document.getElementById('theme-toggle');
  function isDark() {
    return root.dataset.theme
      ? root.dataset.theme === 'dark'
      : window.matchMedia('(prefers-color-scheme: dark)').matches;
  }
  btn.setAttribute('aria-pressed', isDark());
  btn.addEventListener('click', function () {
    var next = isDark() ? 'light' : 'dark';
    root.dataset.theme = next;
    btn.setAttribute('aria-pressed', next === 'dark');
    try { localStorage.setItem('theme', next); } catch (e) {}
  });
</script>

Visitors who never touch the button keep following their system setting. Once they choose, their choice wins on every page and visit. Many sites also offer a third “system” option that clears the saved value, which is a nice touch for people who switch their device theme by time of day. On WordPress, the head script belongs in the theme’s header so it runs before the page paints.

How do you test dark mode for accessibility?

Test both themes as if each were the only one: check contrast, keyboard focus, states and content on real devices. Dark mode bugs usually hide in components nobody looked at after the switch.

  1. Emulate the setting: Chrome, Edge and Firefox developer tools can emulate prefers-color-scheme, so you can flip themes without changing your system.
  2. Check contrast for every pair: body text, muted text, links, buttons, placeholders, borders and focus rings, against 4.5:1 and 3:1.
  3. Walk through every state: hover, focus, active, disabled, error and success messages, plus forms, tables, code blocks and embeds.
  4. Use the keyboard: tab through the page and make sure the focus indicator is clearly visible on dark surfaces.
  5. Review media: logos, icons, charts, maps and third-party widgets that may not support dark mode.
  6. Test on real screens: phones in a dark room and laptops in daylight show problems that emulation misses.
  7. Respect user settings: make sure the toggle is a real button with an accessible name and state, and that forced colors or high contrast modes still work.

If you want a second pair of eyes on a dark theme, our UI/UX design team can design the token system and both themes before development starts. To see how teams measure whether a change like this actually helps, read our take on measuring user experience.

Frequently asked questions

Is dark mode better for your eyes?

Not universally. It can be more comfortable in dim light, but most people with typical vision read dark text on a light background as well or better in normal lighting. Offering both themes is the safest choice.

What is the best background color for dark mode?

A dark gray rather than pure black, such as #121212 or a very dark tone of your brand color. Pair it with off-white text and check that the combination meets at least 4.5:1 contrast.

Does dark mode save battery?

On OLED and AMOLED screens, yes, because dark pixels draw less power, and the effect is larger at high brightness. On LCD screens, which use a constant backlight, the savings are minimal.

Should a website follow the system dark mode setting?

Yes, follow prefers-color-scheme by default so the site matches what visitors already chose, then add a toggle that lets them override it and remembers their choice.

Need dark mode designed and built properly for a client site, from color tokens to a flicker-free toggle? Get started with Hey Reliable.

Get started now

Start with a risk-free, no obligation proposal delivered to your inbox in one business day or less.

Get Started
  • 5-Star Rated Technical Partner
  • 100% White-Label - Sign our NDA
  • 90-Day Code Guarantee
Hey Reliable logo

Welcome to Hey Reliable

We’d love to hear from you. Please use the form below or email info@heyreliable.com.

"*" indicates required fields

This field is for validation purposes and should be left unchanged.
Secret Link