Skip to main content
Images and Design 5 min read · 962 words

Dark Mode Design: Best Practices for Colors, Contrast and Images

Learn how to design and build a dark mode that looks great and stays readable, including color choices, contrast, images and the CSS techniques to implement it.

N

By Naeem

Published

Images and Design

Dark mode has gone from a niche option to something many visitors expect. Some people prefer it for comfort in dim rooms, others because it can save battery on certain screens, and others simply like the look. But a good dark mode is not just a color inversion. Simply flipping white to black creates harsh contrast, washed-out colors and unreadable details. This guide covers the principles and the practical steps for designing and implementing a dark theme that people enjoy using.

Why Offer Dark Mode?

  • Comfort: bright white pages can feel glaring in low light.
  • Preference and accessibility: some users with light sensitivity find dark themes easier to read, although others find light text on dark backgrounds harder, especially with certain vision conditions. That is why offering a choice matters.
  • Battery life: on OLED screens, dark pixels use less power, so dark themes can reduce energy use.
  • Modern feel: many users associate dark interfaces with focused, premium experiences.

Principle 1: Avoid Pure Black and Pure White

A pure black background (#000000) with pure white text (#FFFFFF) creates very high contrast, which can cause eye strain and a "halo" effect around text for some readers. Instead, use a very dark gray or a dark tinted shade for the background, such as a deep navy or charcoal, and a soft off-white for body text. Many designs use backgrounds in the range of #0f172a to #1a1a1a and text colors around #e5e7eb or #f1f5f9.

Principle 2: Create Depth With Lightness, Not Shadows

In light themes, shadows suggest elevation. In dark themes, shadows are hardly visible, so designers show elevation by making higher surfaces slightly lighter. A card sitting above the page background should be a little lighter than the background, and a modal above the card a little lighter again. This gives a clear sense of layers without heavy borders.

Principle 3: Adjust Your Colors

Saturated, bright colors that look great on white can vibrate and look harsh on dark backgrounds. For dark mode:

  • Slightly desaturate and lighten brand colors and accent colors.
  • Do not reuse exactly the same hex values from the light theme without testing them.
  • Avoid large areas of highly saturated color.
  • Keep status colors (success, warning, error) recognizable but gentle.

Principle 4: Check Contrast Carefully

Dark mode does not exempt you from accessibility rules. Body text needs a contrast ratio of at least 4.5 to 1 against its background, and large text at least 3 to 1. Watch out for secondary text, placeholders, disabled states and borders, which often become too faint on dark backgrounds. At the same time, avoid making everything maximum brightness, since uniformly bright text reduces hierarchy. Use slightly dimmer shades for secondary content, while keeping them readable.

Principle 5: Handle Images and Graphics

  • Photographs usually work fine, but very bright images can look blinding against a dark page. You can slightly reduce brightness with a CSS filter when dark mode is active.
  • Logos and icons with dark artwork may disappear. Provide a light variant, or use SVG with currentColor.
  • Transparent PNGs that were designed for a white background may show ugly white edges or dark text that cannot be read.
  • Charts and diagrams need their own dark palette, including gridlines and labels.
  • Embedded content, such as maps and videos, may stay bright. Plan the surrounding layout so that it does not look jarring.

How to Implement It With CSS

The modern approach uses CSS custom properties, also called variables. Define your colors once, then redefine them for dark mode.

:root {
  --bg: #ffffff;
  --text: #1f2937;
  --card: #f3f4f6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --text: #e5e7eb;
    --card: #1e293b;
  }
}

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

The prefers-color-scheme media query follows the visitor's operating system setting. You can also add color-scheme: light dark to the root, which tells the browser to adapt built-in controls such as scrollbars and form fields.

Add a Manual Toggle

System preference is a good default, but many users want to switch manually. A common pattern is to add a data attribute or class to the html element, for example data-theme="dark", define the dark variables for that attribute, and save the choice in localStorage. To avoid a flash of the wrong theme when a page loads, run a tiny inline script in the head that applies the saved or system preference before the page is painted.

If you use Tailwind CSS, enabling the class strategy for dark mode lets you write utilities such as dark:bg-slate-900 and toggle a dark class on the root element.

Testing Your Dark Mode

  1. Test every page and component, including forms, tables, alerts, code blocks and modals.
  2. Check contrast with an accessibility tool.
  3. View it on different screens and brightness levels, ideally in a dark room too.
  4. Check the transition between modes for flickers.
  5. Test print styles, since people rarely want to print a dark background.

Common Mistakes

  • Inverting colors automatically and calling it done.
  • Forgetting form inputs, which stay bright white.
  • Low-contrast borders and dividers that disappear.
  • Using pure black with pure white text.
  • Neglecting emails, embedded widgets and third-party components that ignore your theme.
  • Hard-coding colors throughout the CSS, which makes theming painful. Use variables from the start.

Plan Your Palette

You can experiment with light and dark variations of your brand colors, check how they relate and copy the CSS with our free Color Palette and CSS Gradient Generator, which works in your browser.

Final Thoughts

A good dark mode is a thoughtful second design, not an afterthought. Use soft darks instead of pure black, express depth with lighter surfaces, adjust your colors and images, keep contrast accessible, build with CSS variables and let users choose. Do that, and you will give your visitors a comfortable experience in any lighting.

Try It Free · 100% In-Browser

Color Palette & CSS Gradient Generator

Extract dominant color palettes from any uploaded image, build harmonious schemes, check WCAG contrast, and craft CSS gradients.

Launch Tool →
N

Written by

Naeem

Naeem writes practical, no-fluff guides on developer workflows, web performance, privacy-first utilities, digital finance math, and focused productivity.

Keep exploring practical tutorials by Naeem.

All Guides →