DevPlatform
Home
Components
Search
Submit
Earn
Login
Sign Up Free
On-Off Toggle - Preview | DevPlatform
DevPlatform
Categories
Accordion
Animation
Box Shadow
Button
Card
Footer
Form
Gallery
Hero Section
Inputs
Loader
Marquee
Modal
Modules
Navbar
Progress Bar
Radio Buttons
Search-Bar
Sections
Slider
Tab
Timeline
Toggle
On-Off Toggle
rohit
Feb 13, 2026
12
0
Share
Live Preview
Refresh
Live Editor
HTML
CSS
JS
HTML
CSS
JavaScript
1
<div class="wrapper"> <div class="toggle" id="toggle"> <div class="slider"> <span class="label on">ON</span> <span class="label off">OFF</span> </div> </div> </div>
1
body { margin: 0; height: 100vh; background: #0b0b0f; display: flex; justify-content: center; align-items: center; font-family: Arial, sans-serif; } .wrapper { perspective: 800px; } .toggle { width: 200px; height: 80px; background: #111; border-radius: 60px; position: relative; cursor: pointer; box-shadow: 0 0 20px rgba(170, 0, 255, 0.5), 0 0 60px rgba(170, 0, 255, 0.3); transition: box-shadow 0.4s ease; } .slider { width: 100px; height: 80px; background: linear-gradient(145deg, #1a1a1f, #0e0e12); border-radius: 60px; position: absolute; left: 0; top: 0; display: flex; align-items: center; justify-content: center; transition: transform 0.5s cubic-bezier(.4,2,.6,1); box-shadow: inset -10px 0 20px rgba(255,255,255,0.1), 0 0 20px rgba(170, 0, 255, 0.6); } .label { color: white; font-weight: bold; font-size: 18px; letter-spacing: 2px; position: absolute; transition: opacity 0.3s ease; } .on { left: 25px; } .off { right: 25px; opacity: 0.5; } /* ACTIVE STATE */ .toggle.active { box-shadow: 0 0 25px rgba(200, 0, 255, 0.8), 0 0 80px rgba(200, 0, 255, 0.6); } .toggle.active .slider { transform: translateX(100px); box-shadow: inset 10px 0 25px rgba(255,255,255,0.2), 0 0 30px rgba(200, 0, 255, 0.9); } .toggle.active .off { opacity: 1; } .toggle.active .on { opacity: 0.5; }
1
const toggle = document.getElementById("toggle"); toggle.addEventListener("click", () => { toggle.classList.toggle("active"); });
Comments
0
Want to comment?
Please
login
or
sign up
to post comments.
No comments yet
Be the first to comment on this component!
Comments 0
Want to comment?
Please login or sign up to post comments.
No comments yet
Be the first to comment on this component!