How to Create Website Dark & Light Mode Toggle Using HTML & CSS Only

 Hello Guys in this post we will learn how to create Dark & Light Mode Toggle to switch website back ground dark or light. 

In today's time most of website comes with dark and light mode switch option. A user can switch website mode into light and dark using / by clicking on the dark light toggle button 

So In this tutorial i will show you to create light or dark switch button by using only HTML &  CSS.


dark light toggle button


Prerequisite:

  • HTML :- HTML is use to create a Structure of a layout. HTML is like an skeleton of website.
  • CSS :- CSS is Used to design or Beautify the HTML Structure.

Here is the HTML OF Dark Light toggle Button👇



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dark light toggle button</title>
    <!-- Font Awesome Icon CDN -->
    <script src="https://kit.fontawesome.com/8385bc9e15.js" crossorigin="anonymous"></script>
    <!-- link CSS  -->
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="switcher">
        <input type="checkbox" name="check" id="toggle" checked>
        <label for="toggle">
            <i class="fa-solid fa-sun sun"></i>
            <i class="fa-solid fa-moon"></i>
        </label>
    </div>
</body>
</html>



Here is the CSS OF Dark Light toggle Button👇



*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body{
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #ffffff;
    transition: all 0.6s ease-in-out;
}

input {
    display: none;
}

label {
    display: block;
    width: 280px;
    height: 100px;
    border-radius: 60px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.4),
                inset 0 -3px 20px rgba(255 , 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    cursor: pointer;
    transition: all 0.6s ease-in-out;
}

label i {
    font-size: 2.5rem;
    padding: 16px 20px;
    position: relative;
    transition: all 0.6s ease-in-out;
}

label i.sun{
    color: #ffffff;
}
label i.moon{
    color: #5d5d5d;
}
input:checked + label i.moon {
    color: #ffffff;
}
input:checked + label i.sun {
    color: #5d5d5d;
}

label::before{
    content: "";
    position: absolute;
    top: 10px;
    width: 80px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: linear-gradient(180deg, #ffcc96, #d8865d);
    box-shadow: -3px -3px 10px #00000040,
                3px 3px 20px #00000040;
    transition: all 0.6s ease-in-out;
}

input:checked + label::before{
    transform: translateX(222%);
    background: linear-gradient(180deg, #777, #3a3a3a);
}
body:has(input:checked){
    background: #242424;
}



Watch full Video of website Dark Light toggle button 👇



Download Source Code from my Telegram Channel 👇





Post a Comment

0Comments
Post a Comment (0)
email-signup-form-Image

Subscribe Us

To Get Notification About Our Latest Tutorial.