🎨CSS & Color

Dark Mode Switcher CSS

Transition logic and styles for dark mode support.

Explanation

Supporting dark mode is essential for modern web applications to reduce eye strain.

Examples

Class Pattern
Output
.dark { background: #000, color: #fff }

Code Examples

CSS
body {
  transition: background-color 0.3s, color 0.3s;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --text: #f8fafc;
  }
}

Try it Now

💡 Tips

  • Use prefers-color-scheme for automatic detection
  • Avoid pure black (#000) for large areas; use dark navy or charcoal
  • Desaturate colors slightly in dark mode

⚠️ Common Pitfalls

  • Hardcoding colors instead of using variables makes dark mode impossible