Dark CSS

Dark Light Toggle using only Html CSS

Facebook
Twitter
WhatsApp

code preview

Html code

				
					<!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</title>
    <link rel="stylesheet" href="style.css">
</head>

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

</html>
				
			

css code

				
					/* Basic Styling */
html,
body {
    display: grid;
    height: 100vh;
    place-items: center;
    background: #fff;
    transition: background 0.3s ease;
}

body {
    width: 100%;
    height: 100%; 
}

/* Hide Default Checkbox */
input {
    appearance: none;
    position: absolute;
}

/* Switch Styling */
.switch span {
    display: block;
    width: 40px;
    height: 20px;
    background: #ddd;
    border-radius: 20px;
    transition: 0.3s;
    position: relative;
    cursor: pointer;
}

/* Toggle Button */
span::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    margin: 2px;
    transition: 0.3s;
}

input:checked+span {
    background: #4ecdc4;
}

input:checked+span::before {
    transform: translateX(20px);
}

body:has(input:checked) {
    background: #212121;
}