Frontend Forever App
We have a mobile app for you to download and use. And you can unlock many features in the app.
Get it now
Intall Later
Run
HTML
CSS
Javascript
Output
Document
Is this checkbox using CSS to pretend to be a toggle element?
@charset "UTF-8"; @import url(https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800); *, :after, :before { box-sizing: border-box; padding: 0; margin: 0; } body { font-size: 1.8rem; font-family: sans-serif; background: #E0DFDB; background-image: repeating-linear-gradient(45deg, rgba(#FFF, .1), rgba(#FFF, .1) 30px, transparent 0, transparent 60px); padding: 1rem; } .content { min-height: 100vh; display: flex; justify-content: center; align-items: center; } .visually-hidden { clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; } .checkbox-group { display: flex; flex-direction: row; gap: .75rem; justify-content: center; align-items: center; background-color: #fff; border: 1px solid #e8e8e8; border-radius: 0.3rem; padding: 5rem 3rem; box-shadow: 0 5px 5px #0005; } .toggle { display: flex; min-width: 6rem; height: 3rem; border-radius: 25rem; padding: 0.25rem; transition: background 0.3s ease; background-color: #bababa; position: relative; } .toggle::before { content: ""; position: absolute; top: 50%; left: 0.75rem; transform: translateY(-50%); width: 3rem; height: 3rem; border-radius: 50%; background-color: #444; transition: opacity 0.3s ease, transform 0.3s ease; } .toggle::after { content: ""; position: absolute; top: 50%; left: .85rem; transform: translateY(-50%); width: 3rem; height: 3rem; border-radius: 50%; background-color: #00ff94; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 61 45'%3E%3Cpath d='M48.7498 2.28142C51.3913 -0.359957 55.6739 -0.359921 58.3153 2.28153C60.7556 4.72181 60.9404 8.55699 58.8749 11.2134L58.8041 11.3044L58.3963 11.7663L27.5701 42.5925C25.1298 45.0327 21.2946 45.2175 18.6382 43.152L18.5472 43.0812L18.0853 42.6734L2.63175 27.2198C-0.00973761 24.5784 -0.00973773 20.2957 2.63175 17.6542C5.07203 15.2139 8.9072 15.0291 11.5636 17.0946L11.6546 17.1654L12.1164 17.5731L22.7871 28.2419L48.7498 2.28142C48.7498 2.28138 48.7497 2.28146 48.7498 2.28142Z'/%3E%3C/svg%3E") no-repeat center / 60%; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 61 45'%3E%3Cpath d='M48.7498 2.28142C51.3913 -0.359957 55.6739 -0.359921 58.3153 2.28153C60.7556 4.72181 60.9404 8.55699 58.8749 11.2134L58.8041 11.3044L58.3963 11.7663L27.5701 42.5925C25.1298 45.0327 21.2946 45.2175 18.6382 43.152L18.5472 43.0812L18.0853 42.6734L2.63175 27.2198C-0.00973761 24.5784 -0.00973773 20.2957 2.63175 17.6542C5.07203 15.2139 8.9072 15.0291 11.5636 17.0946L11.6546 17.1654L12.1164 17.5731L22.7871 28.2419L48.7498 2.28142C48.7498 2.28138 48.7497 2.28146 48.7498 2.28142Z'/%3E%3C/svg%3E") no-repeat center / 60%; opacity: 0; /* Hidden by default */ transition: opacity 0.3s ease, transform 0.3s ease; } .toggle:has(input[type="checkbox"]:checked) { background-color: #00ff94; } .toggle:has(input[type="checkbox"]:checked)::after { opacity: 1; transform: translate(75%, -50%); } .toggle:has(input[type="checkbox"]:checked)::before { background-color: #333; transform: translate(75%, -50%); }
console.log("Event Fired")