<?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[Bhavik Blogs]]></title><description><![CDATA[Bhavik Blogs]]></description><link>https://bhavik-blogs.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1639977560289/4mb-7FeOC.png</url><title>Bhavik Blogs</title><link>https://bhavik-blogs.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 14:12:35 GMT</lastBuildDate><atom:link href="https://bhavik-blogs.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to make dark and light modes on your website]]></title><description><![CDATA[Adding Dark and light mode to your website can make it look really pretty and engaging. And creating this effect is really easy
Let me show you how to create a color mode changing system as you see on this website see in just two steps

 Step 1

For ...]]></description><link>https://bhavik-blogs.hashnode.dev/how-to-make-dark-and-light-modes-on-your-website</link><guid isPermaLink="true">https://bhavik-blogs.hashnode.dev/how-to-make-dark-and-light-modes-on-your-website</guid><dc:creator><![CDATA[Bhavik Khawale]]></dc:creator><pubDate>Sat, 28 Aug 2021 14:42:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1639978704154/5pdWruAuF.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Adding Dark and light mode to your website can make it look really pretty and engaging. And creating this effect is really easy</p>
<p>Let me show you how to create a color mode changing system as you see on this website see in just two steps</p>
<blockquote>
<h1 id="heading-step-1"><strong> Step 1</strong></h1>
</blockquote>
<p>For the first step, we need to create some variables and replace them with all colors to be changed</p>
<p>your code would be looking like this now. With repeating color values</p>
<pre><code><span class="hljs-selector-class">.header</span>{
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#c9c9c9</span>;
}
<span class="hljs-selector-class">.footer</span>{
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#c9c9c9</span>;
}
<span class="hljs-selector-tag">h1</span>{
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#000</span>
}
<span class="hljs-selector-tag">p</span>{
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#000</span>
}
<span class="hljs-selector-tag">h3</span>{
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#000</span>
}
</code></pre><p>But now we have to replace with CSS variables</p>
<p>this is how it would look like</p>
<pre><code><span class="hljs-selector-pseudo">:root</span>{
    <span class="hljs-attribute">--backgroundColor</span>: <span class="hljs-number">#fff</span>;
    <span class="hljs-attribute">--textColor</span>: <span class="hljs-number">#000</span>;
}
<span class="hljs-selector-class">.header</span>{
    <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--backgroundColor);
}
<span class="hljs-selector-class">.footer</span>{
    <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--backgroundColor);
}
<span class="hljs-selector-tag">h1</span>{
    <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--textColor);
}
<span class="hljs-selector-tag">p</span>{
    <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--textColor);
}
<span class="hljs-selector-tag">h3</span>{
    <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--textColor);
}
</code></pre><blockquote>
<h1 id="heading-step-2"><strong> Step 2</strong></h1>
</blockquote>
<p>Now we have assigned variables to all the colors.
We have to change those variable values with JS</p>
<p>for making the colors change you can use event listeners. this is for dark mode</p>
<pre><code>document.getElementById(<span class="hljs-string">'darkButtion'</span>).addEventListener(<span class="hljs-string">'click'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">params</span>) </span>{
    const r <span class="hljs-operator">=</span> document.querySelector(<span class="hljs-string">':root'</span>);
    r.style.setProperty(<span class="hljs-string">'--backgroundColor'</span>, <span class="hljs-string">'rgb(25, 25, 25)'</span>);
    r.style.setProperty(<span class="hljs-string">'--textColor'</span>,       <span class="hljs-string">'#fff'</span>);
});
</code></pre><p>and for the light theme put the same values you put in the CSS file
something like this</p>
<pre><code>document.getElementById(<span class="hljs-string">'light'</span>).addEventListener(<span class="hljs-string">'click'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">params</span>) </span>{
    const r <span class="hljs-operator">=</span> document.querySelector(<span class="hljs-string">':root'</span>);
    r.style.setProperty(<span class="hljs-string">'--backgroundColor'</span>, <span class="hljs-string">'#fff'</span>);
    r.style.setProperty(<span class="hljs-string">'--textColor'</span>,       <span class="hljs-string">'#000'</span>);
});
</code></pre><div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/huKwupxdd_Y">https://youtu.be/huKwupxdd_Y</a></div>
]]></content:encoded></item></channel></rss>