Dark Theme with One-line code

anjalbinayak

Anjal Binayak Adhikari

Posted on August 7, 2020

Dark Theme with One-line code

In the present context, Dark Theme is like a vital thing for any website. The first thing I search while visiting the website is the theme toggler. Seriously, it is very uneasy to see the light-themed website now, at least for me.

So recently I implemented Dark Theme in my portfolio site. The funny thing is I didn't have to write the whole another CSS file for a dark theme. So let us begin on how you can implement the dark theme on your website using one line of code.

At first, inside your head tag

insert the following script and link files.

<script src="https://binayak.codes/dark-theme-switcher/app.js"></script>
 <link rel="stylesheet" href="https://binayak.codes/dark-theme-switcher/styles/style.css">
Enter fullscreen mode Exit fullscreen mode

Now place following code after closing the body tag

<script>
window.ThemeSwitcher().Init();
</script>
Enter fullscreen mode Exit fullscreen mode

And that's it, After doing that you will see a moon icon floating in website

Light Theme

After Clicking in that glowy floating icon, your website theme is changed

Dark Theme

The best part about this glowy icon is, visitors of your website can customize its location. Its draggable element. And it stores the current location where it is dragged and saves it.

Alt Text

You better use it yourself to see how it works
Demo Of Dark Theme

Github Repo here

Give your judgments!

💖 💪 🙅 🚩
anjalbinayak
Anjal Binayak Adhikari

Posted on August 7, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Dark Theme with One-line code
javascript Dark Theme with One-line code

August 7, 2020