DEV Community

Shantanu Nighot
Shantanu Nighot

Posted on • Originally published at magbanum.tech on

1 1

Dark/Light theme switcher for your Website.

Dark light theme switcher
Nowadays, the use of dark UI has been increased by web developers to make their websites more effective in low light. Popular websites with the dark mode are GitHub, Youtube, Medium, FreeCodeCamp and Hashnode Blogs. Not only websites but lots of mobile apps like Chrome, Instagram, Whatsapp have dark UI in them. Dark_UI.pngSome advantages of the dark UI are,

  • It reduces the energy consumption as the use of pixels are reduced (more effective on OLED and AMOLED screens.
  • Reduces eye strain in low light conditions.
  • Reduces screen glare and blue light
  • Make your website or app look amazing

But using the dark mode in bright conditions can cause eye fatigue. Hence, in order to make it user friendly, we will need something for the visitor to be able to switch between dark and light theme as per its need. That's where the Dark/Light theme switcher is introduced.

Dark/light theme switcher can be created using HTML, CSS and JavaScript for any Website. I have provided the source code for such a button that I used in one of my project #magbanum.blog. I hope you will find it helpful.

HTML:

https://gist.github.com/magbanum/71f8b83057e30e0d8549f8193c19d38c

CSS:

https://gist.github.com/magbanum/017ab397dd6eef0f0a807f5f4fc3f2d3

JavaScript:

https://gist.github.com/magbanum/ef286bb67dff238c97e9df8d2eabcfaf

Do visit the GitHub repo for more information.

Do you have a dark mode on your website? let me know by commenting below.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay