<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mamad Mirza]]></title><description><![CDATA[Mamad Mirza]]></description><link>https://mamadmirza.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Nov 2026 11:00:46 GMT</lastBuildDate><atom:link href="https://mamadmirza.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Dark Mode in 12 Lines of CSS (No Library, No Framework)]]></title><description><![CDATA[Most dark-mode tutorials reach for a library or a theme provider. You don't need one. CSS variables already do the whole job: define your colours once…]]></description><link>https://mamadmirza.hashnode.dev/dark-mode-in-12-lines-of-css-no-library-no-framework</link><guid isPermaLink="true">https://mamadmirza.hashnode.dev/dark-mode-in-12-lines-of-css-no-library-no-framework</guid><category><![CDATA[CSS]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Mamad Mirza]]></dc:creator><pubDate>Wed, 04 Nov 2026 14:43:38 GMT</pubDate><content:encoded><![CDATA[<p>Most dark-mode tutorials reach for a library or a theme provider. You don't need one. CSS variables already do the whole job: define your colours once, swap the values when a toggle flips, and let every element follow.</p>
<p>Here is the complete theme from a working demo page I built:</p>
<pre><code class="language-css">:root{
  --bg:#ffffff;
  --text:#16202e;
  --card:#eef2f7;
  --accent:#c9a227;
}
body.dark{
  --bg:#0b1220;
  --text:#f5f0e1;
  --card:#16223a;
  --accent:#e7c34a;
}
</code></pre>
<p>That's the theme itself. Everything else on the page just uses the variables:</p>
<pre><code class="language-css">body{
  background:var(--bg);
  color:var(--text);
  transition:background .3s, color .3s;
}
.card{ background:var(--card); }
button{ background:var(--accent); }
</code></pre>
<h2>The toggle</h2>
<p>One button, one class on <code>&lt;body&gt;</code>, and <code>localStorage</code> so the visitor's choice survives the next visit:</p>
<pre><code class="language-js">const b = document.body;
if (localStorage.getItem('demo-theme') === 'dark') b.classList.add('dark');

document.getElementById('t').onclick = () =&gt; {
  b.classList.toggle('dark');
  localStorage.setItem('demo-theme', b.classList.contains('dark') ? 'dark' : 'light');
};
</code></pre>
<h2>Why this works so well</h2>
<ul>
<li><strong>One source of truth.</strong> Backgrounds, text, cards and buttons all read the same few variables, so the dark theme can't drift out of sync with the light one.</li>
<li><strong>No flash of the wrong theme</strong> is handled by applying the saved class before the page settles — the check runs immediately.</li>
<li><strong>Zero dependencies.</strong> Nothing to install, nothing to break on the next framework update. It works in a static HTML file, a WordPress theme, or inside any framework's stylesheet.</li>
</ul>
<p>Dark mode isn't just a trend — visitors stay longer on pages that are easy on their eyes at night. With variables, adding it is an afternoon's small change, not a project.</p>
<hr />
<p><em>I'm Mamad Mirza, a full-stack developer in the UK. I build a small working project every day — follow along here, or work with me on <a href="https://laborx.com/freelancers/users/id476418">LaborX</a>.</em></p>
]]></content:encoded></item></channel></rss>