Dark Mode Toggle
Example: The dark mode toggle in setting on Twitter or Facebook
<div class="showcontent">
<div>
<label class="switch">
<input type="checkbox">
<span class="slider"></span>
</label>
<label class="switch" >
<input type="checkbox" checked>
<span class="slider"></span>
</label><br><br>
<label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label>
<label class="switch">
<input type="checkbox" checked>
<span class="slider round"></span>
</label>
</div>
</div>
Don't need any JavaScript.
.showcontent div{
background-color: white;
padding: 5px;
}
.switch{
cursor: pointer;
position: relative;
height: 34px;
width: 60px;
display: inline-block;
z-index: 100;
}
.switch:hover{
opacity: 0.9;
}
.switch input{
width: 0;
height: 0;
opacity: 0;
}
.slider{
position: absolute;
height: inherit;
width: inherit;
background-color: #333;
transition: 0.4s;
}
.slider.round{
border-radius: 34px;
}
.slider::before{
content:"";
position: absolute;
width: 26px;
height: 26px;
background-color:white;
left: 4px;
top: 4px;
transition: 0.4s;
}
.switch input:checked +.slider{
background-color: rgb(6, 252, 72);
}
.switch input:checked +.slider::before{
transform: translateX(26px);
}
.slider.round::before{
border-radius: 50%;
}
Example: The dark mode toggle in setting on Twitter or Facebook
Example: The Wi-Fi and Bluetooth toggles in the quick setting menu on Android or iOS devices.
Example: In the settings of a messaging app, you might have a toggle switch to enable or disable notifications for new messages.