DEV Community

Cover image for TailwindCSS Dark Mode. Free UI/UX design course
Keep Coding
Keep Coding

Posted on

1

TailwindCSS Dark Mode. Free UI/UX design course

Dark mode

Psst!
Press shift + D to toggle dark/light mode on most websites.

For some time now, dark mode has ceased to be just a fashionable novelty, and has become a mandatory functionality of good design.

Thanks to Tailwind, the implementation of dark mode in our project is child's play.

Image description

All we have to do is, as with Hover or other states, use the appropriate modifier and then specify the condition.

The modifier for dark mode is keyword dark:

HTML
<div class="bg-white dark:bg-neutral-700">[...]</div>

So if we want our standard, light card with dark text to have a dark mode variant, we need to define the condition that when dark mode is turned on, the background of the card changes to dark (dark:bg-neutral-700) and the text of the card to light (dark:text-neutral-50).

HTML
<div class="block rounded-lg bg-white p-6 shadow-md dark:bg-neutral-700">
<h5
class="mb-2 text-xl font-medium leading-tight text-neutral-800 dark:text-neutral-50">
Light mode
</h5>
<p class="mb-4 text-base text-neutral-600 dark:text-neutral-200">
Dark mode reduces eye strain in low-light conditions, saves energy on
OLED screens, and offers a visually refreshing aesthetic.
</p>
</div>

System preferences

Dark mode in Tailwind supports (in most cases) the preferences of your operating system.

This means that Tailwind can detect whether you are using a dark or light theme on your computer and adapt to it.

Therefore, depending on whether you used dark mode or light mode on your computer, our site should be displayed in your preferred mode from the beginning.

That's just yet another cool feature of Tailwind CSS 😉

Dark mode in the Navbar

Take another look at the Navbar in our project.

All the components of TW Elements support dark mode by default. So if you press shift + D on this website, you will notice that also the Navbar below switches the mode.

Image description

HTML
<!-- Navbar -->
<nav
class="flex-no-wrap relative flex w-full items-center justify-between bg-white py-2 shadow-md shadow-black/5 dark:bg-neutral-600 dark:shadow-black/10 lg:flex-wrap lg:justify-start lg:py-4"
data-twe-navbar-ref>
[...]
</nav>
<!-- Navbar -->

Dark mode in the playground

Whenever you see a button like this at the end of a lesson, you can go to our online editor to see the source code of the lesson material and modify it directly in your browser.

DEMO AND SOURCE CODE FOR THIS LESSON

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

PulumiUP 2025 image

From Infra to Platforms: PulumiUP 2025 Panel

Don’t miss the expert panel at PulumiUP 2025 on May 6. Learn how teams are evolving from infrastructure engineering to platform engineering—faster, more secure, and at scale.

Save Your Spot

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay