Simple Dark Mode Button Pure HTML & CSS

Syiainfoku make a Simple Dark Mode Button Pure HTML and CSS
Simple Dark Mode Button Pure HTML & CSS

Hello!

Today you will learn together on the Syiainfoku blog how to make Simple Dark Mode Button no JavaScript pure HTML and CSS.

Okay, let's get started

Preview Simple Dark Mode Button

Preview Simple Dark Mode Button

More or less the result will be like in the image above.

Source Code and Brief Explanation

First, create an HTML file with the name index.html and paste the given code in your HTML file. Remember, you must create a file with an .html extension.

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Simple Dark Mode Button | hitoricoding</title>
<link rel="stylesheet" href="./assets/style.css">
</head>

<body>
<main>
<label>
<input type="checkbox">
<span class="check"></span>
</label>
</main>
</body>

</html>

Finally, create a CSS file with the name style.css and paste the given code in your CSS file. Remember, you must create a file with a .css extension.

main {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
min-height: 100vh;
}

input[type="checkbox"] {
-moz-appearance: none;
-webkit-appearance: none;
visibility: hidden;
display: none;
}

.check {
position: relative;
display: block;
width: 95px;
height: 40px;
background: #0b1d26;
cursor: pointer;
border-radius: 20px;
overflow: hidden;
transition: ease-in 0.5s;
}

input[type="checkbox"]:checked~.check {
background: #fff;
box-shadow: 0 0 0 1200px #0b1d26;
}

.check::before {
content: '';
position: absolute;
top: 5px;
left: 5px;
background: #fff;
width: 30px;
height: 30px;
border-radius: 50%;
transition: 0.5s;
}

input[type="checkbox"]:checked~.check::before {
transform: translateX(-50px);
}

.check::after {
content: '';
position: absolute;
top: 5px;
right: 5px;
background: #0b1d26;
width: 30px;
height: 30px;
border-radius: 50%;
transition: 0.5s;
transform: translateX(50px);
}

input[type="checkbox"]:checked~.check::after {
transform: translateX(0px);
}

That's it, now you have successfully created a Simple Dark Mode Button only HTML & CSS, If your code is not working or you are facing any error/problem, please download the source code file from the given download button. It's free and a .zip file will be downloaded then you have to extract it.

Closing

Thank you for those of you who have read and downloaded this source code, hopefully it can be useful and add to your insight.

If you found this article useful, you can share it. That's all from me, and THANK YOU