---
title: "Discussion on \"Dark Theme in your website with one line of Js Code\" | Hashnode"
description: "Discussion on \"Dark Theme in your website with one line of Js 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.\nSo recently I impl..."
url: "https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Dark Theme in your website with one line of Js Code](https://binayak.hashnode.dev/dark-theme-in-your-website-with-one-line-of-js-code?utm_source=hashnode&utm_medium=feed)

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 impl...

Aug 10, 2020 · 2 min read · binayak.hashnode.dev  
Updated Aug 21, 2020  
Read the article

-   [#js](https://hashnode.com/tag/js)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#css](https://hashnode.com/tag/css)
-   [#pwa](https://hashnode.com/tag/pwa)

## Written by

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

@anjalbinayakadhikari · London

  
[View profile](https://hashnode.com/@anjalbinayakadhikari)

Software Engineer

I code sometimes

## Responses 8

Markdown supported · ⌘↵ to post

[Godstime Onyibe](https://hashnode.com/@Godstime)

[Aug 20, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3f0239dfbb4247f7c14bc8)

Please could not add it in my web page. Am using it directly in the browser. Please some some one should help out.

[Luiz Filipe da Silva](https://hashnode.com/@luizfilipezs)

[Aug 21, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3f0239dfbb4247f7c14bc8#reply-5f3f2f555b3ac8481821c49e)

Hey, [Godstime Onyibe](https://hashnode.com/@Godstime)! Currently, the code is stable and works fine.

Add the script before the closing tag `body`, as it follows:

```
  ...
  <script src="cdn.jsdelivr.net/gh/luizfilipezs/dark-theme-switc…"></script>
  <script type="text/javascript">
    new ThemeSwitcherGenerator().init();
    // or
    new ThemeSwitcher(someElement).init();
  </script>
</body>
```

> Remember that what the package does is inverting the colors. So, to change the background of your body tag, as an example, you must give it a background color.

[Godstime Onyibe](https://hashnode.com/@Godstime)

[Sep 3, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3f0239dfbb4247f7c14bc8#reply-5f5161fe81d8ab6c5765ebfb)

[Luiz Filipe da Silva](https://hashnode.com/@luizfilipezs) Thanks i have applied it and is working great 😍💕

[Luiz Filipe da Silva](https://hashnode.com/@luizfilipezs)

[Sep 3, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3f0239dfbb4247f7c14bc8#reply-5f5172d081d8ab6c5765ec64)

🥳🥳 [Godstime Onyibe](https://hashnode.com/@Godstime)

[Luiz Filipe da Silva](https://hashnode.com/@luizfilipezs)

[Aug 11, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f32c2184332ee07eb55c8e5)

Good idea! I just [forked](https://github.com/luizfilipezs/dark-theme-switcher) the repository and I hope to contribute with it. Thanks for sharing!

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

[Aug 11, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f32c2184332ee07eb55c8e5#reply-5f32c52e2a23d9080d179c58)

Thanks, I would love that

[Astha Srivastava](https://hashnode.com/@asthaundefined)

[Aug 11, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f32bc7c2a23d9080d179c0a)

This is really amazing.. I tried and it worked perfectly fine.. Thanks for such great content. ❤

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

[Aug 11, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f32bc7c2a23d9080d179c0a#reply-5f32c5604332ee07eb55c922)

The pleasure is mine.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f315ed74332ee07eb55bdf2)

Great one Anjal.. I am gonna try it sooner for a project I am working on. Any plans to make it available as npm?

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f315ed74332ee07eb55bdf2#reply-5f31647c2a23d9080d1790ce)

Thanks, Tapas. It may take some time, but yes for sure.

[Rishab Kumar](https://hashnode.com/@rishabkumar7)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3152af4332ee07eb55bd71)

And you my friend, are a lifesaver! 😉

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3152af4332ee07eb55bd71#reply-5f3154a64332ee07eb55bd8e)

I am happy , you appreciated it.

[Nelson Michael](https://hashnode.com/@nmNelson)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f31465f84bff4054d85ae03)

this is so awesome, thanks for sharing.

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f31465f84bff4054d85ae03#reply-5f3148df84bff4054d85ae16)

Pleasure is mine mate

[Victoria Lo](https://hashnode.com/@victoria)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3132f4273a577b50ca63b3)

Very cool! Thanks! I hope to use it in a project someday :)

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f3132f4273a577b50ca63b3#reply-5f3148fc84bff4054d85ae1a)

Thank you, I am happy you liked it.

[Edidiong Asikpo (Didi)](https://hashnode.com/@didicodes)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f30feda273a577b50ca6134)

This is really amazing. I am going to try it out. Thanks for sharing.

[Anjal Binayak Adhikari](https://hashnode.com/@anjalbinayakadhikari)

[Aug 10, 2020](https://hashnode.com/posts/dark-theme-in-your-website-with-one-line-of-js-code/5f30c91c3348367b2fc3f98a/comment/5f30feda273a577b50ca6134#reply-5f30ff333348367b2fc3fbba)

Pleasure is mine
