Back to Blog
TutorialDecember 20, 202412 min read

Complete Guide to Dark Mode in Tailwind CSS

Implement a perfect dark mode in your Tailwind CSS project. Learn class-based vs media-query approaches and color strategies.

dark modetailwindtheming

Why Dark Mode?

  • Reduces eye strain in low-light environments
  • Saves battery on OLED/AMOLED displays
  • User preference - many users prefer dark interfaces

Setup Methods

Method 1: Class-Based (Recommended)

// tailwind.config.js
module.exports = {
  darkMode: 'class',
}
<html class="dark">
  <body class="bg-white dark:bg-gray-900">
    Content
  </body>
</html>

Method 2: Media Query

module.exports = {
  darkMode: 'media',
}

Recommended Dark Mode Palette

ElementLight ModeDark Mode
Backgroundbg-whitebg-gray-900
Surfacebg-gray-50bg-gray-800
Primary texttext-gray-900text-white
Secondary texttext-gray-600text-gray-400

Color Adjustments

In dark mode, colors should be one step lighter:

<button class="bg-blue-600 dark:bg-blue-500 text-white">
  Submit
</button>

Explore our Dark Mode Colors tool for perfect combinations.

Written by

TWColors Team

Try Our Tools

Put what you learned into practice with our free Tailwind CSS tools.

Explore 50+ Tools