Table of Contents
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
- A professional impression for your website.
- Better user experience.
- 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
How do I add a dark theme to my website?
Step 01
First, follow these steps to get your template ready:
- Login to you Blogger dashboard.
- Backup your template first.
- Head to Template then edit HTML.
- With Ctrl+C to copy and Ctrl+V to paste the following codes in their appropriate places.
- Search for the line of code by hitting Ctrl+F
- 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.
We love to hear from you ????????.