How to Add Dark Mode to a Small Website Properly
A reader emailed me in October with what he thought was a bug report about his own site. He had spent a Saturday adding a dark theme to a three page portfolio, shipped it that night, and then watched a number fall. Not traffic.

A reader emailed me in October with what he thought was a bug report about his own site. He had spent a Saturday adding a dark theme to a three page portfolio, shipped it that night, and then watched a number fall. Not traffic. Average time on page dropped from about a minute forty to forty seconds, and the only thing he had changed was the colors.
I opened the site on my phone in a dark room, which is where dark mode actually gets used, and the trouble was visible in under a second. He had set the page background to pure black and the body text to pure white, then left every other value exactly as it was. His accent blue, picked months earlier for a white page, now sat at a contrast ratio of roughly 2.6 against black, so every link read as a typo rather than a link. His project screenshots were PNG files with white backgrounds, and each one glowed in the middle of the page like someone had turned a flashlight on. A validator would have found nothing wrong. It simply hurt to read.
Pure black and pure white are the real problem
The default instinct is to flip the two extremes: background goes to #000000, text goes to #ffffff. That gives you a contrast ratio of 21 to 1, the highest the scale allows, and it reads worse than almost any other pairing you could have chosen.
White type on black bleeds. The bright glyphs spread slightly into the dark background on most screens, the effect gets stronger for anyone with astigmatism, and the result is text that looks fuzzy at the edges and is tiring after two paragraphs. People who read a lot at night notice it immediately and leave without being able to say why.
What works is pulling both ends toward the middle. A surface around #11131a and body text around #e6e8ee land at about 13 to 1, which clears every accessibility threshold with room to spare and stops the halo. The other advantage of a near black is that you can then show depth: a card sitting on #11131a can use #1a1d26 and look raised. On pure black there is nowhere to go except grey, which is why so many dark themes look like a flat sheet with lines drawn on it.
You probably do not need a toggle yet
Nearly every tutorial starts with a switch in the header, a click handler, and a saved choice in local storage. I would skip all of it for the first version, and that is the one piece of standard advice I argue with most often.
The browser already knows. Every phone and laptop sold in the last six years has an appearance setting, and the CSS media query for a preferred color scheme reads it for free. One block of CSS, no JavaScript, nothing to persist, nothing to go wrong. Someone who wanted dark gets dark, and the roughly two thirds of visitors who never touched that setting keep the light site you designed on purpose.
A toggle is also where small sites break. To avoid a flash of the wrong theme on load you need a tiny blocking script in the head that reads storage before the first paint. Get that wrong and visitors see a white flash before each dark page, which is worse than no dark mode at all. I have debugged that flash on four sites and it was never a ten minute fix.
One line worth adding either way is the color scheme declaration on your root element, set to light dark. That tells the browser to style the scrollbars, the form controls, and the text selection to match. Without it you get a dark page with a bright white scrollbar glued to the side of it, which is the giveaway that nobody checked the result on a desktop.
Six values, not two
Most of the dark themes I am sent treat the problem as two colors. It is closer to six, and once they are written down the rest of the work is mechanical. Borrow this as a starting point and adjust the hues to your own palette rather than copying mine.
| Role | Light | Dark | Why it changes |
|---|---|---|---|
| Page surface | #ffffff | #11131a | Near black, not black, to stop text bleed |
| Raised surface | #f4f6fb | #1a1d26 | Cards and tables need to sit above the page |
| Body text | #101524 | #e6e8ee | Around 90 per cent white reads calmer than 100 |
| Muted text | #5a6378 | #9aa3b8 | Dates and captions, still above 4.5 to 1 |
| Border | #e3e8f2 | #2a2f3d | A light border disappears entirely on dark |
| Accent | #1d4ed8 | #7aa2f7 | Saturated brand blues fail contrast on dark |
That last row is the one people resist. A deep brand blue that looks right on white usually comes in under 3 to 1 against a dark surface, and link text at that ratio is both inaccessible and practically invisible. You are not changing your brand colour, you are picking a lighter tint of it for one context. Keep the dark original for buttons with white text on them, where it still works.
If your colours were never written down as a short list in the first place, that is the job to do before any of this. I wrote about building that list in choosing a palette for a website, and a six row table like the one above is what makes a second theme a half hour of work instead of a weekend.
The parts that quietly break
The CSS is the easy half. What catches people is the content that was authored on the assumption of a white page.
Screenshots and diagrams saved as PNG or JPG carry their own white background, and on a dark page each one becomes a glowing rectangle. There is no CSS fix for a baked in background. Either re export the images with transparency and give them a small padded light surface of their own, so they read as deliberate objects on the page, or keep two versions and swap them with a picture element. Logos are the same story. A black wordmark on a transparent background vanishes completely. If you have the logo as SVG you can make its fill follow the current text colour and the problem solves itself for both themes.
Shadows go next. Every box shadow you own is a semi transparent black, which does nothing against a near black surface, so cards that looked separated now float with no edge. On dark you lean on borders and on that raised surface value instead. Then the odds and ends: the yellow autofill wash browsers paint into saved form fields, embedded maps and video players that arrive with their own white chrome, code blocks with a light syntax theme, and the theme colour meta tag that controls the browser bar on a phone.
Ten minutes of checking before you ship
Switch your operating system appearance to dark and walk your own site in that state, not just the homepage. The pages that break are the ones with real content: an article with a table and two screenshots, the contact form showing validation errors, the search page with nothing found.
Then do the boring measurement. Open the accessibility panel in your browser developer tools, click the body text, and read the computed contrast ratio. Do it again for muted text, for link text inside a paragraph, and for the label on your main button. Four numbers. Anything under 4.5 to 1 for normal text gets a lighter value, and you fix it in the token table rather than in the component, which is the whole point of writing the tokens down.
The last check is the one people skip: read a full article end to end in dark mode at night, on a phone, with the room lights off. That is the condition the theme exists for, and the only test that catches a surface a shade too bright or body type a shade too thin. If the typography feels wrong rather than the colour, the fix is in the layout, and the measurements I use are in designing a blog post layout people read. The rest sits in the web design section.
FAQ
Does dark mode actually save battery?
On an OLED screen, yes, measurably. Tests have put the saving at roughly 15 to 30 per cent of display power at moderate brightness. On an LCD the backlight stays on regardless and the saving is close to zero. A side benefit, not a reason to build it.
Should I invert my logo for the dark theme?
Invert the mark only if it is a single colour. A black wordmark becomes a white wordmark and looks correct. A logo with a specific brand colour in it should keep that colour and get a lighter tint only if contrast fails. What you should not do is apply a CSS filter that inverts the image, because it turns your blue into orange and your photos into negatives.
Will adding dark mode help my search rankings?
Not directly. There is no ranking signal for colour schemes. The indirect path is real but modest: a page people stay on and come back to tends to do better over time, and a theme that is painful at night loses those visitors. Treat it as a reason to keep readers, not as an SEO task.
How much CSS does this take on a small site?
If your colours are already variables, the dark block is the six values above inside one media query, so around fifteen lines. If every colour is hard coded across your stylesheet, the real work is pulling those hex codes out into variables first. On a small site that took me about an hour and made every later change faster.
More in Web Design
Web Design
How to Design a Blog Post Layout People Actually Read
A reader wrote to me in September with a problem that sounded like an SEO problem and was not one.
Web Design
How to Design a Hero Section That Does Not Slow the Page
A joiner I helped last year had a homepage that looked excellent in the designer's mockup.
Web Design
How to Design a Call to Action Button People Actually Click
Your page gets visitors, they scroll, and then they leave without booking, buying or signing up.