DEV Community

Cover image for Designing Accessible Dark Mode Interfaces: A Step-by-Step Guide for Modern Web Designers
henry messiah tmt
henry messiah tmt

Posted on

Designing Accessible Dark Mode Interfaces: A Step-by-Step Guide for Modern Web Designers

Introduction

Dark mode is everywhere, from mobile apps to developer tools and websites. It’s sleek, power-efficient, and easier on the eyes for many users.

But there’s a catch: most dark mode designs aren’t accessible. Poor contrast, harsh text, and invisible icons make them difficult to use for people with visual impairments, and tiring for everyone else.

In this guide, you’ll build your own accessible dark mode layout from scratch, learning best practices as you go. By the end, you’ll know how to design, test, and implement dark mode that’s both stylish and inclusive. You will be able to build interchangable theme as seen bellow:
ScreenRecording2025-10-28121345-ezgif.com-optimize

Prerequisites

Before you begin, ensure you meet a few basic requirements to follow this guide smoothly. These will help you understand each step and build your own accessible dark mode interface without issues.

You’ll need:

  • Basic web development knowledge: comfortable with HTML, CSS, and a bit of JavaScript.
  • A code editor: such as Visual Studio Code, Sublime Text, or Atom.
  • A modern browser: Chrome, Firefox, or Edge for previewing and testing your design.
  • Basic understanding of accessibility principles: like color contrast and readability.

Optional but helpful:

  • Familiarity with design tools such as Figma or Adobe XD (for visual testing).
  • Access to accessibility tools like Stark or WebAIM Contrast Checker.

If you’re missing any of these, take a moment to set them up first, so that we can flow together effortlessly.
Once these prerequisites are in place, you’re ready to start building your own inclusive dark mode layout from scratch.

Setting Up Your Project

With your tools ready, it’s time to create your workspace. In this step, you’ll build the structure that will hold your dark mode interface.

Let’s start by creating a simple HTML + CSS + JavaScript project that you’ll use throughout this tutorial.

Create Your Project Folder

On your computer, create a new folder called dark-mode-tutorial.

If you’re using Windows, right-click on your desktop → New → Folder → name it dark-mode-tutorial.

Alternatively, open your terminal or command prompt and run:

mkdir dark-mode-tutorial
cd dark-mode-tutorial
Enter fullscreen mode Exit fullscreen mode

Open the folder in your code editor (for example, Visual Studio Code).

In VS Code, go to File → Open Folder → dark-mode-tutorial. Or from your terminal, run:

code .
Enter fullscreen mode Exit fullscreen mode

This opens the current folder directly in VS Code. Now, you’re inside your project, the creative canvas where everything will unfold.

Create Three Files

Inside your dark-mode-tutorial folder, create these three files:

dark-mode-tutorial/
├── index.html
├── style.css
└── script.js
Enter fullscreen mode Exit fullscreen mode

You can do this by:
Right-clicking in VS Code’s file explorer → New File, or Running these commands in your terminal:

touch index.html style.css script.js
Enter fullscreen mode Exit fullscreen mode

This trio forms the backbone of your dark mode project: HTML for structure, CSS for design, and JavaScript for interactivity.

Before we style and script, let’s fill your HTML file with a clean, accessible layout.

Add the Starter HTML Code

Every great interface begins with solid structure. Let’s add your starter HTML code that is simple, semantic, and screen-reader friendly.

Now, open the index.html file in your editor.
To do that:
In VS Code, click index.html in the left panel. Paste in the following code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Accessible Dark Mode Demo</title>
  <link rel="stylesheet" href="style.css" />
</head>
<body>
  <header>
    <h1>Accessible Dark Mode Demo</h1>
    <button id="theme-toggle">Toggle Theme</button>
  </header>

  <main>
    <section>
      <h2>Welcome</h2>
      <p>This page demonstrates how to build an accessible dark mode interface.</p>
    </section>
  </main>

  <script src="script.js"></script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Save your file (Ctrl + S or Cmd + S).
Now that your basic structure is ready, let’s make it both beautiful and accessible.

Understanding Accessibility in Dark Mode

Now that your structure is set, let’s talk about why accessibility matters in dark mode.
Even the most elegant design fails if users can’t comfortably read or interact with it.

Accessibility ensures inclusivity and dark mode introduces unique visual challenges that we must address.

Accessibility means designing for everyone, including users with low vision or color blindness. In dark mode, even small mistakes in color contrast can make text unreadable.

Apply a Comfortable Dark Background

Open your style.css file:
In VS Code, click on style.css in the left sidebar. Then paste in the following CSScode:

body {
  background-color: #121212; /* softer than pure black */
  color: #E0E0E0; /* light gray text */
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.6;
  padding: 2rem;
}
Enter fullscreen mode Exit fullscreen mode

Why not use pure black (#000000)?
Because white text on a pure black background causes glare, especially for users with astigmatism or light sensitivity (I am a pharmacist, you can believe me on this).
A dark gray background is easier on the eyes and improves readability.

Screenshot 2025-10-27 162903

Now that you’ve created a comfortable visual base, let’s refine your color palette for clarity and balance.

Choosing the Right Color Palette

Colors define how users perceive your interface, so good color contrast makes dark mode usable.

A good dark mode color palette is calm, readable, and adheres to WCAG 2.1 contrast standards (at least 4.5:1 for normal text).

Screenshot 2025-10-27 163158

Let us now bring the colors to life in our next step.

Add Color Variables

Now that we understand what a good dark mode color palette is, let’s define reusable color variables in your CSS for consistency.

Still in your style.css file, scroll to the top and add these color variables:

:root {
  --background-dark: #121212;
  --text-light: #E0E0E0;
  --accent-color: #BB86FC; /* soft purple */
}

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

button {
  background-color: var(--accent-color);
  color: #000;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
}
Enter fullscreen mode Exit fullscreen mode

Tip: Use tools like Contrast Checker by WebAIM
to test your color combinations.

## Typography and Readability
Typography is where accessibility meets design.
Readable type keeps users engaged and reduces visual fatigue, especially in dark mode.

Readable typography is essential in dark mode.
Text should be slightly larger, well-spaced, and never pure white.

Screenshot 2025-10-27 164449

Update Your style.css File
Scroll down and add these new styles:

h1, h2 {
  font-weight: 600;
  margin-bottom: 0.5em;
}

p {
  font-size: 1.1rem;
  color: #E0E0E0; /* not pure white */
}

main {
  max-width: 700px;
  margin: 2rem auto;
}
Enter fullscreen mode Exit fullscreen mode

Avoid ultra-thin fonts. They can fade or disappear against dark backgrounds. Stick to medium or bold weights for headings.

Now that your text is legible, it’s time to enhance your visual elements like icons and images.

Icons, Illustrations, and Imagery

Dark mode affects visuals too. Bright icons or images that look great in light mode may disappear in dark mode.

Screenshot 2025-10-27 165038

Add an Image

In your index.html, go to the section and add this line under the

tag:

<img src="light-logo.png" alt="Company logo" class="logo" />

Adjust the Image in CSS

Visuals add personality, but they can break dark mode if not optimized.
Icons may fade, and bright images can overpower the background.
To prevent this, balance brightness and contrast:
Open yourstyle.css again and add the following code:

.logo {
  filter: brightness(0.9) contrast(1.1);
  width: 50px;
}

For the best results, prepare two logo versions, one for light mode and one for dark mode, and switch them dynamically in JavaScript (we’ll cover that next).

Adding a Dark Mode Toggle (with JavaScript)

Let’s make your design interactive by allowing users to toggle between light and dark themes. We are empowering users to switch between light and dark modes with a simple button.

Add a Data Attribute

In your index.html, locate the <body> tag and modify it like this:

<body data-theme="light">

Add JavaScript to Toggle Themes

Now, open your script.js file (click on it in your editor) and paste this code:

const toggleBtn = document.getElementById("theme-toggle");
const body = document.body;

toggleBtn.addEventListener("click", () => {
  const currentTheme = body.getAttribute("data-theme");
  const newTheme = currentTheme === "dark" ? "light" : "dark";
  body.setAttribute("data-theme", newTheme);
});

Define Light and Dark Themes in CSS

Back in your style.css, scroll to the bottom and add:

[data-theme="light"] {
  --background-dark: #FFFFFF;
  --text-light: #111111;
  --accent-color: #6200EE;
}

[data-theme="dark"] {
  --background-dark: #121212;
  --text-light: #E0E0E0;
  --accent-color: #BB86FC;
}

Test it:

Save all files (Ctrl + S or Cmd + S).

Open index.html in your browser (double-click the file or run open index.html).

Click the Toggle Theme button, your dark mode should now switch dynamically like you see bellow.

ScreenRecording2025-10-28121345-ezgif.com-optimize

Testing Accessibility

Never assume your design is accessible, always test it. Accessibility testing ensures your dark mode works for everyone, including users with visual impairments or those viewing your site under different lighting conditions.

Start by opening your project in a browser. Locate your index.html file inside the dark-mode-tutorial folder and double-click it to open. You can also right-click and choose Open With → Chrome, Firefox, or Edge. Try toggling between light and dark themes using the “Toggle Theme” button.

As you switch modes, check if your text remains readable and whether icons, buttons, and accents are still visible. The goal is for both themes to look balanced, comfortable, and easy on the eyes.

Next, test your color contrast ratio using WebAIM’s Contrast Checker. Copy your text and background colors from your CSS file (for example, #121212 and #E0E0E0) and paste them into the tool. Aim for a ratio of 4.5:1 or higher for normal text and 3:1 for larger text.

Screenshot 2025-10-27 163158

If your contrast ratio falls below the standard, adjust the colors slightly. Lighten the text or darken the background until the ratio improves. This small tweak makes a big difference for users with low vision or color sensitivity.

You can also use accessibility tools for deeper testing. The Stark Plugin in Figma or Adobe XD simulates color blindness and checks contrast instantly. In Chrome, open DevTools → Lighthouse → Accessibility and click Analyze page load to get a detailed accessibility score. Firefox users can check the Accessibility Tab under Ctrl + Shift + I.

Finally, perform a manual test. Turn on your room lights and review your page, is everything still clear? Then dim the lights or use your device’s dark mode and check again. If your page feels comfortable in both conditions, you’ve achieved true accessibility balance.

Case Studies & Best Practices

Many popular platforms have already mastered dark mode accessibility. Studying their design choices helps you create your own high-quality, inclusive themes.

GitHub, for example, uses dark gray backgrounds (#0D1117) instead of pure black. Its text (#C9D1D9) maintains strong contrast and consistency, ensuring comfort during long coding sessions. The key takeaway: readability always comes before aesthetics.

Screenshot 2025-10-28 135632

Slack takes a different approach by offering multiple dark themes. Users can choose what feels best for their eyes, proving that customization enhances accessibility. Choice empowers users with diverse vision needs.

Notion uses layered contrasts and soft shadows to separate elements clearly. Its design demonstrates how visual hierarchy, not just color contrast improves readability in dark environments.

When designing your own dark mode, avoid common mistakes. Don’t use pure black backgrounds with bright white text; they create harsh glare and eye strain. Steer clear of overly saturated accent colors or gray-on-gray combinations with poor contrast.

Instead, use subtle elevation effects such as shadows or slightly lighter backgrounds to separate elements. This creates depth and readability without overwhelming the user’s eyes.

Next Steps

Take your design further by adding smooth CSStransitions when switching between light and dark modes. You can also detect user preferences automatically using the prefers-color-scheme media query.

If possible, test your design with users who have color vision deficiencies or rely on assistive technologies like screen readers. Their feedback will help you refine your design for real-world use.

Conclusion

You’ve successfully created and tested an accessible dark mode interface. You learned how to balance colors, ensure readability, and test for inclusivity. Now your design doesn’t just look modern, it works beautifully for everyone.

Designing an accessible dark mode interface isn’t just about trendy visuals, it’s about empathy and inclusion. A well-crafted dark theme supports users who are light-sensitive, work at night, or simply prefer darker interfaces, ensuring comfort and usability for everyone.

Useful Resources

Top comments (2)

Collapse
 
samuel_ndiomu_a0348a661c4 profile image
Samuel Ndiomu

Beautifully written

Collapse
 
adika_david_f4882f8904c91 profile image
ADIKA DAVID

Thank you so much for taking time to write articles such as this. You're good to go. Cheers Bro