
You’ve spent hours perfecting your UI typography. The hierarchy is spot-on, the line heights are comfortable, and your brand's custom sans-serif font looks incredibly elegant. But the moment you toggle on your site's dark mode, something goes wrong.
Suddenly, your clean, sophisticated body copy looks bloated. The letters seem to bleed into each other, looking half a weight thicker than they did on the light background.
This isn't a bug in your browser or a mistake in your font file. It is a biological quirk of the human eye called the irradiation illusion. Here is why it happens, and how you can fix it using CSS.
The irradiation illusion was first documented by Galileo Galilei in the 17th century and later analyzed by Hermann von Helmholtz. It describes how the human eye perceives bright shapes on dark backgrounds as being larger than dark shapes of the identical size on light backgrounds.
When light enters your eye, it scatters slightly on your retina. When you look at white text on a black screen, the light from the letters spills over onto the surrounding dark pixels in your field of vision. This creates a subtle halo effect, making the white strokes appear thicker and bolder.
In typography, this optical blooming fills in the negative space of your letters (such as the loops in "e" or "a"), reducing legibility and causing eye strain over long periods of reading.
To ensure your text looks visually consistent across both light and dark themes, you have to design for the human eye, not just the code. Here are four practical techniques to neutralize the irradiation illusion.
The most direct way to counter the irradiation illusion is to reduce the weight of your font in dark mode. If you are using font-weight: 400 (Regular) for your light mode body text, you should target 300 (Light) or 350 in dark mode.
Using CSS Custom Properties makes this incredibly straightforward:
:root {
--font-weight-body: 400;
--text-color: #111111;
--bg-color: #ffffff;
}
@media (prefers-color-scheme: dark) {
:root {
--font-weight-body: 300; /* Drop the weight in dark mode */
--text-color: #f3f4f6;
--bg-color: #121212;
}
}
body {
font-weight: var(--font-weight-body);
color: var(--text-color);
background-color: var(--bg-color);
}
Simply changing your font weight from 400 to 300 can sometimes cause a subtle layout shift because the letter widths change, altering line wraps.
If you are using a variable font, look to see if it supports the Grade (GRAD) axis. Grade alters the visual weight of the glyphs without changing their physical width or tracking. This means your text becomes optically thinner without shifting a single pixel of your layout.
@media (prefers-color-scheme: dark) {
body {
/* Lower the grade slightly for dark mode */
font-variation-settings: "GRAD" -20;
}
}
The stronger the contrast between your text and background, the more severe the light bleed will be. Avoid pairing pure white text (#ffffff) with a pure black background (#000000).
Instead, soften your dark mode palette. Use a deep charcoal or navy for the background, and an off-white or light gray for the body text.
/* Highly readable, low-glare dark mode pairing */
body {
background-color: #121214; /* Deep charcoal */
color: #e4e4e7; /* Soft off-white */
}
Browsers render text differently depending on the operating system. On macOS, Safari and Chrome apply a subpixel antialiasing technique that can make dark mode text look excessively heavy. You can gently thin out the text rendering on macOS using non-standard CSS properties:
@media (prefers-color-scheme: dark) {
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
}
Note: Use this property sparingly and test across multiple displays, as it can occasionally make light fonts look too thin on non-retina screens.
When it comes to web design, mathematical consistency does not always equal visual harmony. If you use the exact same styles for both light and dark modes, your typography will suffer. By adjusting your font-weights, lowering your contrast, and utilizing variable fonts, you can ensure that your user interface remains sharp, legible, and beautiful in any light.
Photo by Matheus Bertelli on Pexels