<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Flowbite - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Flowbite - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 26 Aug 2026 20:17:54 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/flowbite/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Dark Mode Switcher With Tailwind CSS and Flowbite ]]>
                </title>
                <description>
                    <![CDATA[ By Zoltán Szőgyényi Dark mode is starting to become a requirement rather that a nice-to-have feature like it was back in the day. It gives users the option to choose a theme that's comfortable for them, whether they're working during the day or at ni... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-dark-mode-switcher-with-tailwind-css-and-flowbite/</link>
                <guid isPermaLink="false">66d461c9a326133d12440aa6</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Flowbite ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tailwind ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 09 Dec 2021 16:11:44 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-2021-11-30-at-13.16.28-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Zoltán Szőgyényi</p>
<p>Dark mode is starting to become a requirement rather that a nice-to-have feature like it was back in the day. It gives users the option to choose a theme that's comfortable for them, whether they're working during the day or at night.</p>
<p>If you haven't already heard, Tailwind CSS is one of the fastest growing CSS frameworks today due to its utility-first approach.</p>
<p>But even though Tailwind has a pretty good dark mode integration guide, there's no clear explanation on how to build a switch element to toggle it. On top of that, Tailwind doesn't include any actual components that support dark mode.</p>
<p>That's where Flowbite comes in. Flowbite is a library that provides components and interactive elements on top of Tailwind CSS. And as of version 1.2, it supports dark mode.</p>
<p>So that's what I want to show you today – how to build a <a target="_blank" href="https://flowbite.com/docs/customize/dark-mode/">Tailwind CSS dark mode switch</a> element, and how to work with Flowbite components.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/2021-11-29-16.04.49-1.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Flowbite - Tailwind CSS dark mode switcher</em></p>
<p>Before diving into the tutorial, make sure you have a Tailwind CSS project already set up. You should also <a target="_blank" href="https://flowbite.com/docs/getting-started/quickstart/">install Flowbite as a plugin</a> so you can use its components in dark mode.</p>
<h2 id="heading-getting-started">Getting Started</h2>
<p>If you already have a Tailwind CSS project set up then you can skip to the part where you should install Flowbite as a plugin. If not, then follow the instructions here on how to install Tailwind CSS first.</p>
<h3 id="heading-how-to-install-tailwind-css">How to Install Tailwind CSS</h3>
<p>The most popular way of using Tailwind CSS is by installing it as a PostCSS plugin. For that, we need to install three different packages using NPM:</p>
<pre><code class="lang-shell">npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
</code></pre>
<p>After that you should create a file called <code>postcss.config.js</code> and add the following code inside of it:</p>
<pre><code class="lang-js"><span class="hljs-comment">// postcss.config.js</span>
<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">plugins</span>: {
    <span class="hljs-attr">tailwindcss</span>: {},
    <span class="hljs-attr">autoprefixer</span>: {},
  }
}
</code></pre>
<p>Now open your terminal and execute the following command:</p>
<pre><code class="lang-shell">npx tailwindcss init
</code></pre>
<p>This will create an empty <code>tailwind.config.js</code> file which we will use later on to include Flowbite as a plugin.</p>
<p>Next up you should create a new CSS file which you can call <code>styles.css</code> and add the following code inside of it:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* ./your-css-folder/styles.css */</span>
<span class="hljs-keyword">@tailwind</span> base;
<span class="hljs-keyword">@tailwind</span> components;
<span class="hljs-keyword">@tailwind</span> utilities;
</code></pre>
<p>After compiling the code using PostCSS, the injected directives (base, components, utilities) will be available as styles in the final CSS file.</p>
<p>Lastly, all you need to do is compile the CSS using Tailwind CLI by running the following command:</p>
<pre><code class="lang-shell">npx tailwindcss -o tailwind.css
</code></pre>
<p>A newly created <code>tailwind.css</code> file will be available in your project and you should include that inside your HTML templates to have access to the styles.</p>
<p>Now you have a working Tailwind CSS configuration locally on your computer. If you want to find more about this process, take a look at the <a target="_blank" href="https://tailwindcss.com/docs/installation">installation guide from Tailwind CSS</a>.</p>
<h3 id="heading-how-to-install-flowbite">How to Install Flowbite</h3>
<p>We need to install Flowbite to have access to the full features of the components and dark version support. Luckily the setup process is very straightforward since it's a Tailwind CSS plugin.</p>
<p>Let's start by first installing it via NPM:</p>
<pre><code class="lang-bash">npm i flowbite
</code></pre>
<p>Then require it as a plugin inside the <code>tailwind.config.js</code> file:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">module</span>.exports = {

    <span class="hljs-attr">plugins</span>: [
        <span class="hljs-built_in">require</span>(<span class="hljs-string">'flowbite/plugin'</span>)
    ]

}
</code></pre>
<p>Lastly, make sure that you also include the JavaScript file somewhere before the closure of the <code>&lt;body&gt;</code> tag:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"../path/to/flowbite/dist/flowbite.bundle.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<h3 id="heading-how-to-enable-dark-mode-in-tailwind-css">How to Enable Dark Mode in Tailwind CSS</h3>
<p>The first thing to understand is how dark mode works in Tailwind CSS. There are two ways you can set it up:</p>
<ul>
<li>using the <code>media</code> option</li>
<li>using the <code>class</code> option</li>
</ul>
<p>The main difference is that the <code>media</code> option will only take your browser's color scheme preference into account, which is actually set by the OS.</p>
<p>The <code>class</code> option will only look for a <code>.dark</code> class applied to the main <code>&lt;html&gt;</code> tag. This is what most websites use because, with this method, users can manually set their preference.</p>
<p>We'll stick with the <code>class</code> option, as it gives users greater control over their theming preferences.</p>
<p>Let's start off by adding the following to the <code>tailwind.config.js</code> file:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">darkMode</span>: <span class="hljs-string">'class'</span>,
  <span class="hljs-comment">// ...</span>
}
</code></pre>
<p>This configures Tailwind to use the <code>class</code> option for dark mode.</p>
<p>Next, add a script to the <code>&lt;head&gt;</code> element of the page. This checks for a previous user preference in <code>localStorage</code>, and uses the browser's color scheme as a backup:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-comment">// It's best to inline this in `head` to avoid FOUC (flash of unstyled content) when changing pages or themes</span>
  <span class="hljs-keyword">if</span> (
    <span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">'color-theme'</span>) === <span class="hljs-string">'dark'</span> ||
    (!(<span class="hljs-string">'color-theme'</span> <span class="hljs-keyword">in</span> <span class="hljs-built_in">localStorage</span>) &amp;&amp;
      <span class="hljs-built_in">window</span>.matchMedia(<span class="hljs-string">'(prefers-color-scheme: dark)'</span>).matches)
  ) {
    <span class="hljs-built_in">document</span>.documentElement.classList.add(<span class="hljs-string">'dark'</span>);
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-built_in">document</span>.documentElement.classList.remove(<span class="hljs-string">'dark'</span>);
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>The reason we add this script to the <code>&lt;head&gt;</code> tag and not before the closing <code>&lt;body&gt;</code> tag is because we want to avoid a flicking effect when setting the page to dark or light mode.</p>
<h2 id="heading-how-to-build-the-dark-mode-switch">How to Build the Dark Mode Switch</h2>
<p>Now that Tailwind is configured, we need to build the element users will interact with to change the theme from dark to light mode.</p>
<p>To do this, we'll stick with a basic <code>&lt;button&gt;</code> element from <a target="_blank" href="https://flowbite.com/docs/components/buttons/">Flowbite's component library</a>, and use two interchangeable icons.</p>
<p>Add the following HTML code to your page. I recommend adding the element somewhere on the top right side of the navigation bar, as it's the natural place users look when they want to change the color scheme:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>
  <span class="hljs-attr">id</span>=<span class="hljs-string">"theme-toggle"</span>
  <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span>
  <span class="hljs-attr">class</span>=<span class="hljs-string">"text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg text-sm p-2.5"</span>
&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
    <span class="hljs-attr">id</span>=<span class="hljs-string">"theme-toggle-dark-icon"</span>
    <span class="hljs-attr">class</span>=<span class="hljs-string">"w-5 h-5 hidden"</span>
    <span class="hljs-attr">fill</span>=<span class="hljs-string">"currentColor"</span>
    <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 20 20"</span>
    <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>
  &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span>
      <span class="hljs-attr">d</span>=<span class="hljs-string">"M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"</span>
    &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
    <span class="hljs-attr">id</span>=<span class="hljs-string">"theme-toggle-light-icon"</span>
    <span class="hljs-attr">class</span>=<span class="hljs-string">"w-5 h-5 hidden"</span>
    <span class="hljs-attr">fill</span>=<span class="hljs-string">"currentColor"</span>
    <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 20 20"</span>
    <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>
  &gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">path</span>
      <span class="hljs-attr">d</span>=<span class="hljs-string">"M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z"</span>
      <span class="hljs-attr">fill-rule</span>=<span class="hljs-string">"evenodd"</span>
      <span class="hljs-attr">clip-rule</span>=<span class="hljs-string">"evenodd"</span>
    &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>The two SVG objects are icons, and only one of them is shown based on the active theme. And there are three ids for the three objects:</p>
<ul>
<li><code>#theme-toggle</code> for the main dark mode switch element</li>
<li><code>#theme-toggle-dark-icon</code> for the moon icon that will be shown when the active theme is light</li>
<li><code>#theme-toggle-light-icon</code> for the sun icon that will be shown when the active theme is dark</li>
</ul>
<h2 id="heading-how-to-handle-the-dark-mode-switch-with-javascript">How to Handle the Dark Mode Switch with JavaScript</h2>
<p>The last thing we need to do is to handle the click events of the dark mode switch element and update the <code>localStorage</code> and the icons inside the element.</p>
<p>Add the following code in your main JavaScript file:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> themeToggleDarkIcon = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'theme-toggle-dark-icon'</span>);
<span class="hljs-keyword">var</span> themeToggleLightIcon = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'theme-toggle-light-icon'</span>);

<span class="hljs-comment">// Change the icons inside the button based on previous settings</span>
<span class="hljs-keyword">if</span> (<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">'color-theme'</span>) === <span class="hljs-string">'dark'</span> || (!(<span class="hljs-string">'color-theme'</span> <span class="hljs-keyword">in</span> <span class="hljs-built_in">localStorage</span>) &amp;&amp; <span class="hljs-built_in">window</span>.matchMedia(<span class="hljs-string">'(prefers-color-scheme: dark)'</span>).matches)) {
    themeToggleLightIcon.classList.remove(<span class="hljs-string">'hidden'</span>);
} <span class="hljs-keyword">else</span> {
    themeToggleDarkIcon.classList.remove(<span class="hljs-string">'hidden'</span>);
}

<span class="hljs-keyword">var</span> themeToggleBtn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'theme-toggle'</span>);

themeToggleBtn.addEventListener(<span class="hljs-string">'click'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{

    <span class="hljs-comment">// toggle icons inside button</span>
    themeToggleDarkIcon.classList.toggle(<span class="hljs-string">'hidden'</span>);
    themeToggleLightIcon.classList.toggle(<span class="hljs-string">'hidden'</span>);

    <span class="hljs-comment">// if set via local storage previously</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">'color-theme'</span>)) {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">localStorage</span>.getItem(<span class="hljs-string">'color-theme'</span>) === <span class="hljs-string">'light'</span>) {
            <span class="hljs-built_in">document</span>.documentElement.classList.add(<span class="hljs-string">'dark'</span>);
            <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">'color-theme'</span>, <span class="hljs-string">'dark'</span>);
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-built_in">document</span>.documentElement.classList.remove(<span class="hljs-string">'dark'</span>);
            <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">'color-theme'</span>, <span class="hljs-string">'light'</span>);
        }

    <span class="hljs-comment">// if NOT set via local storage previously</span>
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">document</span>.documentElement.classList.contains(<span class="hljs-string">'dark'</span>)) {
            <span class="hljs-built_in">document</span>.documentElement.classList.remove(<span class="hljs-string">'dark'</span>);
            <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">'color-theme'</span>, <span class="hljs-string">'light'</span>);
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-built_in">document</span>.documentElement.classList.add(<span class="hljs-string">'dark'</span>);
            <span class="hljs-built_in">localStorage</span>.setItem(<span class="hljs-string">'color-theme'</span>, <span class="hljs-string">'dark'</span>);
        }
    }

});
</code></pre>
<p>The first part of the code will change the icon that is being shown based on previous preference, either via the <code>localStorage</code> or the color scheme from the browser.</p>
<p>The second part of the code handles the click events on the switch element itself and sets the <code>localStorage</code> based on which theme has been selected.</p>
<h3 id="heading-how-to-use-the-dark-mode-switch-in-the-navigation-bar">How to Use the Dark Mode Switch in the Navigation Bar</h3>
<p>We're still not done yet as we need to find a place to position the dark mode switcher – and what a better place to do that other than the navigation bar.</p>
<p>Luckily, Flowbite comes with a lot of great <a target="_blank" href="https://flowbite.com/docs/components/navbar/">navbar components</a> that we can select from and position the dark mode switch button inside of it.</p>
<p>Let's take the navbar example with the button and change it with our own dark mode switcher:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bg-white border-gray-200 px- bg-white border-gray-200 px-2 sm:px-4 py-2.5 rounded dark:bg-gray-800"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container mx-auto flex flex-wrap items-center justify-between"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"h-10 mr-3"</span> <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 52 72"</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">"none"</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">d</span>=<span class="hljs-string">"M1.87695 53H28.7791C41.5357 53 51.877 42.7025 51.877 30H24.9748C12.2182 30 1.87695 40.2975 1.87695 53Z"</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">"#76A9FA"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">d</span>=<span class="hljs-string">"M0.000409561 32.1646L0.000409561 66.4111C12.8618 66.4111 23.2881 55.9849 23.2881 43.1235L23.2881 8.87689C10.9966 8.98066 1.39567 19.5573 0.000409561 32.1646Z"</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">"#A4CAFE"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">d</span>=<span class="hljs-string">"M50.877 5H23.9748C11.2182 5 0.876953 15.2975 0.876953 28H27.7791C40.5357 28 50.877 17.7025 50.877 5Z"</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">"#1C64F2"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"self-center text-lg font-semibold whitespace-nowrap dark:text-white"</span>&gt;</span>FlowBite<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex md:order-2"</span>&gt;</span>

      <span class="hljs-comment">&lt;!-- Dark mode switcher --&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
      <span class="hljs-attr">id</span>=<span class="hljs-string">"theme-toggle"</span>
      <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span>
      <span class="hljs-attr">class</span>=<span class="hljs-string">"text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg text-sm p-2.5"</span>
    &gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
        <span class="hljs-attr">id</span>=<span class="hljs-string">"theme-toggle-dark-icon"</span>
        <span class="hljs-attr">class</span>=<span class="hljs-string">"w-5 h-5 hidden"</span>
        <span class="hljs-attr">fill</span>=<span class="hljs-string">"currentColor"</span>
        <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 20 20"</span>
        <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>
      &gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">path</span>
          <span class="hljs-attr">d</span>=<span class="hljs-string">"M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"</span>
        &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
        <span class="hljs-attr">id</span>=<span class="hljs-string">"theme-toggle-light-icon"</span>
        <span class="hljs-attr">class</span>=<span class="hljs-string">"w-5 h-5 hidden"</span>
        <span class="hljs-attr">fill</span>=<span class="hljs-string">"currentColor"</span>
        <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 20 20"</span>
        <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>
      &gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">path</span>
          <span class="hljs-attr">d</span>=<span class="hljs-string">"M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z"</span>
          <span class="hljs-attr">fill-rule</span>=<span class="hljs-string">"evenodd"</span>
          <span class="hljs-attr">clip-rule</span>=<span class="hljs-string">"evenodd"</span>
        &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- Dark mode switcher end --&gt;</span>

      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">data-collapse-toggle</span>=<span class="hljs-string">"mobile-menu-4"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"md:hidden text-gray-500 hover:bg-gray-100focus:outline-none focus:ring-2 focus:ring-gray-200 rounded-lg text-sm p-2 inline-flex items-center dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600"</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">"mobile-menu-4"</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"false"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sr-only"</span>&gt;</span>Open main menu<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"w-6 h-6"</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">"currentColor"</span> <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 20 20"</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">fill-rule</span>=<span class="hljs-string">"evenodd"</span> <span class="hljs-attr">d</span>=<span class="hljs-string">"M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z"</span> <span class="hljs-attr">clip-rule</span>=<span class="hljs-string">"evenodd"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">svg</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"hidden w-6 h-6"</span> <span class="hljs-attr">fill</span>=<span class="hljs-string">"currentColor"</span> <span class="hljs-attr">viewBox</span>=<span class="hljs-string">"0 0 20 20"</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">path</span> <span class="hljs-attr">fill-rule</span>=<span class="hljs-string">"evenodd"</span> <span class="hljs-attr">d</span>=<span class="hljs-string">"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"</span> <span class="hljs-attr">clip-rule</span>=<span class="hljs-string">"evenodd"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">path</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"hidden md:flex justify-between items-center w-full md:w-auto md:order-1"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"mobile-menu-4"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-col md:flex-row flex md:space-x-8 mt-4 md:mt-0 md:text-sm md:font-medium"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bg-blue-700 md:bg-transparent text-white block pl-3 pr-4 py-2 md:text-blue-700 md:p-0 rounded dark:text-white"</span> <span class="hljs-attr">aria-current</span>=<span class="hljs-string">"page"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-gray-700 hover:bg-gray-50 border-b border-gray-100 md:hover:bg-transparent md:border-0 block pl-3 pr-4 py-2 md:hover:text-blue-700 md:p-0 md:dark:hover:text-white dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-gray-700 hover:bg-gray-50 border-b border-gray-100 md:hover:bg-transparent md:border-0 block pl-3 pr-4 py-2 md:hover:text-blue-700 md:p-0 md:dark:hover:text-white dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700"</span>&gt;</span>Services<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-gray-700 hover:bg-gray-50 border-b border-gray-100 md:hover:bg-transparent md:border-0 block pl-3 pr-4 py-2 md:hover:text-blue-700 md:p-0 md:dark:hover:text-white dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700"</span>&gt;</span>Contact<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
<p>The end result should look something like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Screenshot-2021-12-03-at-11.25.15.png" alt="Image" width="600" height="400" loading="lazy">
<em>Dark mode switch (light mode)</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Screenshot-2021-12-03-at-11.25.43.png" alt="Image" width="600" height="400" loading="lazy">
<em>Dark mode switch (dark mode)</em></p>
<p>Now whenever a user clicks on the button the whole layout will change from dark to light and vice-versa. This is all of the code that you need to create a dark mode switcher using Tailwind CSS and Flowbite. </p>
<h2 id="heading-flowbite-components-in-dark-mode">Flowbite Components in Dark Mode</h2>
<p>In this tutorial I would also like to show you some of the components from Flowbite that already support dark mode and how you can use them in your Tailwind CSS project.</p>
<p>After the <a target="_blank" href="https://flowbite.com/docs/getting-started/changelog/">release of Flowbite v1.2</a> an important feature was added to this open source component library: a full integration of dark mode for all of the components and plugin.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-2021-11-30-at-14.18.40.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flowbite - Tailwind CSS component in dark mode</em></p>
<p>This can help you tremendously when it comes to building a user interface with Tailwind CSS where you need to support dark mode as well. The components from Flowbite will work with dark mode out-of-the-box because of the <code>.dark:{*}</code> classes.</p>
<p>A good example would be the <a target="_blank" href="https://flowbite.com/docs/components/modal/">modal component</a> which completely changes the appearance when switching from light to dark:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-2021-11-30-at-14.21.32.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flowbite - Tailwind CSS modal (light mode)</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-2021-11-30-at-14.21.25.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flowbite - Tailwind CSS modal (dark mode)</em></p>
<p>I've already written an article on how to use <a target="_blank" href="https://www.freecodecamp.org/news/tailwind-css-components-flowbite/">Flowbite here on freeCodeCamp</a> and you can check it out to learn more about how you can use the components from this library.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope that this tutorial has helped you with your Tailwind CSS and Flowbite journey when it comes to building a dark version for your website. It is great to see open source projects evolve and make the web a better place.</p>
<p>Let me know on Twitter which color scheme you prefer when browsing websites: dark or light mode?</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
