BloggingBloggerWordPress

How To Add Dark Mode Toggle to Your Website

What is Dark Mode / Night Mode?

As we all know, the use of mobile phones and laptop have become one of the most common routines in our life. Consequently, most of us use it obviously at night. Unfortunately, if you do so , you may have eyeache especially if you spend long hours in front of the screen at night.

Why Should You Add a Dark Mode Toggle

Having such a feature in your website – regardless of the platform you are using Blogger or WordPress – will add a bunch of advantages:
  1. A professional impression for your website.
  2. Better user experience.
  3. Increase the bounce rate as visitors will stay longer because they feel more comfortable reading your content.

How To Add Dark Mode Toggle to WordPress

The dark mode toggle has been introduced to WordPress few years ago. That's why there are several plugins that provides this option with just few click of installation. Raqmedia has reviewed the most popular ones. Here are the free plugins that we recommend:

Blackout: Dark Mode Widget

WP Night Mode

How do I add a dark theme to my website?

This awesome feature is also introduced to the Blogger platform. You just need to make some adjustments by injecting some lines of code into your Blogger template. To do so, follow our four-step guide below.

Step 01

First, follow these steps to get your template ready:

  1. Login to you Blogger dashboard.
  2. Backup your template first.
  3. Head to Template then edit HTML.
  4. With Ctrl+C to copy and Ctrl+V to paste the following codes in their appropriate places.
  5.  Search for the line of code by hitting Ctrl+F
  6. Save your template and exit.;

Step 02

Next paste the following code just before </head>

<style type=’text/css’>
/* Night Mode By Raqmedia.com*/
.nightly{color:#999;font-size:13px}
.Switchbtn{position:fixed;text-align:center;display:inline-block;align-items:center;z-index:100;left:20px;top:20px}
.togglenight{display:none;}
.togglenight + .togglenight-btn{outline:0;display:inline-block;width:45px;height:10px;position:relative;cursor:pointer;margin-right:5px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}
.togglenight + .togglenight-btn:after,.togglenight + .togglenight-btn:before{position:relative;display:block;content:””;width:50%;height:100%}
.togglenight-switch + .togglenight-btn{background:#d5d2fc;border-radius:99em;transition:all .4s ease}
.togglenight-switch + .togglenight-btn:after{content:”;border-radius:100px;background:#887fff;transition:right 0.3s cubic-bezier(0.175,0.885,0.32,1.275),padding 0.3s ease,margin 0.3s ease;position:absolute;width:20px;height:20px;top:-5px;right:0;box-shadow:0 3px 6px rgba(0,0,0,0.16),0 3px 6px rgba(0,0,0,0.23)}
.togglenight-switch:checked + .togglenight-btn{background:rgba(255,255,255,.15)}
.togglenight:checked + .togglenight-btn:after{content:”;right:55%;background:#ff9f43}
.nightmode{background:#202124;color:rgba(255,255,255,.7)}
.nightmode a{color:rgba(255,255,255,.7)!important}
.nightmode a:hover{color:rgba(255,255,255,.4)!important}
.nightmode .class-baru{}
.nightmode .class-baru{}
</style>

Step 03

Now, search ]]></b:skin> line and paste the following CSS code just above that ]]></b:skin>.

.Switchbtn {
	position: fixed;
	text-align: center;
	display: inline-block;
	align-items: center;
	z-index: 100;
	left: 20px;
	top: 20px;
}

.Switchbtn {
	top: 10px;
	left: 80px;
}}

@media screen and (max-width:480px) {
	.Switchbtn {
		left: 50px;
	}

	.nightly {
		display: none;
	}
}

@media screen and (max-width:240px) {
	.Switchbtn {
		display: none;
	}
}

Step 04

After that search for <body/> tag and PASTE the below code just before it.

<div class=’Switchbtn’>
<span class=’nightly’>الوضع الليلي</span> <input class=’togglenight togglenight-switch’ id=’nightmode’ type=’checkbox’/>
<label class=’togglenight-btn’ for=’nightmode’/></div>
<script type=’text/javascript’>
//<![CDATA[
// Night Mode
$(“#nightmode”).click(function() {
	$(“body”).toggleClass(“nightmode”);
}),$(“body”).toggleClass(localStorage.toggled),$(“#nightmode”).click(function() {
	“nightmode”!=localStorage.toggled?($(“body”).toggleClass(“nightmode”,!0),localStorage.toggled=”nightmode”): ($(“body”).toggleClass(“nightmode”,!1),localStorage.toggled=””);
});
//]]>
</script>

How to Add Blogger Widgets or Components into Dark Mode With CSS

After carrying the previous steps, you may notice that some parts of your template is not affected by the script and does not shift to Night mode. To fix this problem, you need to add these items or Class Ids using the following Css line. Just change .header with your new Class / item Id, you can also adjust the color to your favourite one.

.nightmode .header{background:#222}

Important Notice For Blogger Users

 ⚠ Note: The Night Mode script may not work for all the blogger templates. Always backup your template before making any changes.

???? Subscribe to our channel to get exclusive & free tech tips & hacks ????
 
Eh! Voila! you have successfully added a stylish dark mode toggle to Blogger or WordPress. If you face any problems or find ways to improve this script or better WordPress Plugins, do share your thoughts and feedback.

We love to hear from you ????????.

Other Popular Articles ...

Leave a Reply

Back to top button
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Sharing is caring

Ad Blocker Detected :(

Please consider supporting us by disabling your ad blocker.

من فضلك قم بتعطيل أداة مانع الإعلانات أدبلوك من المتصفح للدخول للموقع أو إستخدم متصفح آخر
شكرا لتفهمك وزيارتك