Shadow-based elevations are useful on light-mode designs, but they look extremely weird in dark-mode.
1
2
3
4
5
6
7
1
2
3
4
5
6
7
This happens because of a very simple reason.
- In the day, there is a single light source from the sun. Most light-mode designs are based on this single light source concept.
- At night, there is no single light source. Instead there are multiple different kinds of light sources. Dark-mode designs can use any of these light sources.
Light sources at night
There are 5 kinds of lights at night:
- Simple elevation
- Neon lights
- Neon lights behind a fixture (also halo lighting)
- Spotlights
- Backlit
Simple elevation
Simple elevation is a lightening of the background to simulate objects that are closer to you. This is often described in many framework libraries.
To do this, we can just add a background-color with a light opacity to each card.
<div class="bg-white/3">1</div><div class="bg-white/5">2</div><div class="bg-white/7">3</div><div class="bg-white/9">4</div><div class="bg-white/11">5</div><div class="bg-white/13">6</div><div class="bg-white/15">7</div>1
2
3
4
5
6
7
Neon lights
Neon lights give out light by themselves. When you look at these lights, you’ll see a glow that diffuses from the light. This can be done easily with text-shadows or drop-shadow.
When you do this, the x and y of the shadow must be 0 because the neon light is a light source. So we only use blur.
.selector { text-shadow: 0 0 0.5em var(--color-yellow-500);}Neon Light
You can do this in Tailwind, of course. But you’d have to write the entire CSS in their text-shadow-* utility which is not very nice…
<div class="text-shadow-[0_0_0.5em_var(--color-yellow-500)]">...</div>I’d argue it’s easier to write an inline style in this case, but that’s tedious too — and difficult to use:
<div style="text-shadow: 0 0 0.5em var(--color-yellow-500)">...</div>To make life a little bit simpler, I created a text-shadow utility. It comes along with functional utilities:
tsx-*:xof the text shadowtsy-*:yof the text shadowtsb-*: The shadow’sblurtsc-*: The shadow’s color, defaults tocurrentcolor
The text shadow declaration from above becomes easier now, because:
xandymust be0, so we can exclude them.- We’re going to use
currentcolorfor the shadow, so we can exclude it too.
Which means, we only need to define the blur.
<div class="text-yellow-500 text-shadow tsb-[0.5em]">Neon Light</div>If you dislike functional utilities, you can always just use the main utility and adjust the CSS variables directly.
.neon { @apply text-shadow; --text-shadow-blur: 0.5em;}Neon Light
Halo lighting
Neon lights don’t have to be placed front-and-center. They can be placed behind an object. And that creates a glow behind the object.
Here we can use the same elevation-* utilities to create a soft, rich glow.
<!-- works for elevation-1 to elevation-7 --><div class="elevation-4 sy-0 sb-[1px] sc-yellow-500">...</div>This uses the functional utilities we’ve discussed back in the shadow lesson. But if you dislike functional utilities, you can use the CSS variables directly too.
.halo { @apply elevation-4; --shadow-y: 0; --shadow-blur: 1px; --shadow-color: var(--color-yellow-500);}1
2
3
4
5
6
7
The thing about dark mode is that any light intensity can work because there is nothing to cover how bright a light source can be. So you can go crazy and magnify the source with blur, spread, or even opacity — within reason, of course.
Here’s an example where I bumped the elevation spread by just 0.25px per layer. Crazy results.
1
2
3
4
5
6
7
Halo lighting + elevation
You can combine halo lighting with elevation. In this case, it makes sense for:
- The lighting to be larger when it is closer to the background
- And the lighting to be smaller when it is farther away from the background
Halo lighting on text
Not all text needs to be neon lights themselves. They can also contain backlighting around or behind the text. We already discussed this effect in text-stroke a few lessons back.
<!-- Tailwind implementation --><div class="text-stroke spl-stroke-yellow-500 drop-shadow dsb-[0.5em] dsa-0.75"></div>/* CSS Implementation */.effect { @apply text-stroke; @apply drop-shadow; --stroke-color: var(--color-yellow-500); --drop-shadow-blur: 0.5em; --drop-shadow-alpha: 0.75;}Neon Light
If you’re up for making things a little bit nicer, you could even add other coloured shadows to this implementation as well. Here’s an example where I add orange text-shadow into the mix.
Neon Light
Spotlights
Spotlights can bring focus to some objects by lighting them up.
To create a spotlight effect, we can use linear or radial gradients depending on the angle of the spotlight.
- A radial gradient looks more real, but it is more complex to create.
- A linear gradient looks flatter, but it is easier to create.
<!-- Linear gradient --><div class="linear-gradient gradient-angle-180 from-purple-300/15 to-white/0 "> Linear Gradient</div>
<!-- Radial gradient --><div class="radial-gradient from-purple-300/16 to-white/0" style=" --gradient-position: 50% 0%; --gradient-shape: circle; "> Radial Gradient</div>They both look like the items are more interesting compared to plain elevation.
Single Colour
Linear Gradient
Radial Gradient
If you want to bring this up a notch, you can imagine that the rim of the item is a reflective material. So when light shines on this rim, you create a brighter gradient compared to the items within the card.
Single Colour
Radial Gradient
Radial Gradient
I’ll show you a simple way to achieve this effect in the next lesson.
Backlit
Backlit simply means that light is showing from behind. We are already used to this because the computer or even a TV creates light in the middle of a dark room.
This is why colors and shapes look all right even if we are using them plainly.
If you put a box with backdrop-filter above backlit elements, you get Glassmorphism — this basically means light is diffused on the box with a blur filter.
<div class="backdrop-blur-[16px]"></div>You have to be mindful about contrast when doing this!
Of course, we can take it up a notch with some gradients on the glass box as well. A possible effect can look like this:
You have to be mindful about contrast when doing this!
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson