<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: aqib lala</title>
    <description>The latest articles on DEV Community by aqib lala (@aqib_lala_58b9b4e0c90ca6c).</description>
    <link>https://dev.to/aqib_lala_58b9b4e0c90ca6c</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3586625%2F75d076d6-a69c-4710-b62d-ebda8cd836d2.jpg</url>
      <title>DEV Community: aqib lala</title>
      <link>https://dev.to/aqib_lala_58b9b4e0c90ca6c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aqib_lala_58b9b4e0c90ca6c"/>
    <language>en</language>
    <item>
      <title>How to Add Dark Mode to Your Website Using Tailwind and JavaScript</title>
      <dc:creator>aqib lala</dc:creator>
      <pubDate>Fri, 31 Oct 2025 08:47:25 +0000</pubDate>
      <link>https://dev.to/aqib_lala_58b9b4e0c90ca6c/how-to-add-dark-mode-to-your-website-using-tailwind-and-javascript-275a</link>
      <guid>https://dev.to/aqib_lala_58b9b4e0c90ca6c/how-to-add-dark-mode-to-your-website-using-tailwind-and-javascript-275a</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Dark mode isn’t just a design trend anymore — it’s a must-have feature for any modern web app. With Tailwind CSS and a pinch of JavaScript, you can implement a smooth, persistent dark mode in just a few lines of code.&lt;br&gt;
Let’s dive in and give your website that sleek, night-friendly vibe 🌙&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;Before we begin, make sure you have:&lt;br&gt;
• A project set up with Tailwind CSS&lt;br&gt;
• Basic understanding of HTML and JavaScript&lt;br&gt;
• A browser and text editor (VS Code recommended)&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Enable Dark Mode in Tailwind Config
&lt;/h2&gt;

&lt;p&gt;Tailwind makes it incredibly easy to enable dark mode.&lt;br&gt;
Open your tailwind.config.js and add this line:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kcoebafupopl4mmo2o5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8kcoebafupopl4mmo2o5.png" alt=" " width="675" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This tells Tailwind to apply dark styles whenever a .dark class is present on your  or &lt;/p&gt; tag.
&lt;h2&gt;
  
  
  Step 2: Add Light &amp;amp; Dark Styles in Your HTML
&lt;/h2&gt;

&lt;p&gt;Now, create two versions of your background and text colors using Tailwind’s dark mode classes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzpumxgl6trplt9sypm9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzpumxgl6trplt9sypm9.png" alt=" " width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;dark: prefix automatically applies the dark version of each style when .dark is active on the body.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Add JavaScript for Toggle Functionality
&lt;/h2&gt;

&lt;p&gt;We’ll use a simple script to toggle the dark class and store the user’s preference in localStorage so it persists after reload.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1lcihdea8gd2wqfrisrt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1lcihdea8gd2wqfrisrt.png" alt=" " width="742" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s all it takes. The button now toggles dark mode — and your &lt;a href="https://apksell.net/" rel="noopener noreferrer"&gt;site&lt;/a&gt; remembers the user’s choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Smooth Transitions for a Premium Feel
&lt;/h2&gt;

&lt;p&gt;Add this to your body class or global CSS for a smooth color fade effect when toggling themes:&lt;br&gt;
.transition-colors {&lt;br&gt;
  transition: background-color 0.3s, color 0.3s;&lt;br&gt;
}&lt;br&gt;
Tailwind already includes utilities like transition-colors and duration-300, so you can easily control the timing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Optional — Sync with System Preferences
&lt;/h2&gt;

&lt;p&gt;Want your site to automatically detect the user’s OS theme?&lt;br&gt;
You can use the prefers-color-scheme media query:&lt;br&gt;
if (&lt;br&gt;
  localStorage.getItem('theme') === 'dark' ||&lt;br&gt;
  (!localStorage.getItem('theme') &amp;amp;&amp;amp;&lt;br&gt;
    window.matchMedia('(prefers-color-scheme: dark)').matches)&lt;br&gt;
) {&lt;br&gt;
  body.classList.add('dark');&lt;br&gt;
}&lt;br&gt;
This ensures your dark mode is smart and adapts instantly to &lt;a href="https://dev.tourl"&gt;user&lt;/a&gt; preferences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Touch
&lt;/h2&gt;

&lt;p&gt;With just a few lines of code, you’ve implemented a fully functional, persistent, and smooth dark mode powered by Tailwind CSS and JavaScript.&lt;br&gt;
Your users will love the elegant transition and modern look — and your codebase stays clean, thanks to Tailwind’s class-based styling.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>blockchain</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
