Toggle switches offer a slick way to handle binary UI states like on/off or light/dark. This collection of JavaScript toggle switches features animated transitions, theme toggles, accessibility enhancements, and custom styling.
26 JavaScript Toggle Switches
Skeuomorphic Egg Toggle Switch
demo & codeThis is a Skeuomorphic Egg Toggle Switch. It transforms a standard binary input into a playful, highly tactile 3D object resembling an egg sliding in a frying pan. Its function is to inject personality and physical weight into a micro-interaction, replacing flat state changes with an immersive, multi-layered physics simulation entirely rendered in CSS.
Slingshot Elastic Stretch Toggle
demo & codeThe Slingshot Elastic Stretch Toggle is an experimental UI switch that utilizes exaggerated spatial movement to signal state changes. It replaces the standard sliding thumb with a “dual-handle” system that appears to shoot across the viewport using a high-velocity slingshot effect. Its function is to provide an high-energy alternative to traditional toggles, making a simple boolean selection feel like a physical, kinetic event.
Skeuomorphic 3D Elastic Toggle Switch
demo & codeThis is a Skeuomorphic 3D Elastic Toggle Switch. It utilizes multi-layered shadowing and complex keyframe sequences to mimic a physical sliding component embedded in a technical grid. Its function is to transform a standard checkbox into a high-fidelity micro-interaction that emphasizes physical mass and momentum.
Animated Star Toggle Switch
demo & codeThis is an Animated Star Toggle Switch. It replaces a standard HTML checkbox with a highly expressive, character-driven micro-interaction. Its function is to provide emotional feedback to a binary choice (like “favorite” or “bookmark”), launching the star into the air where it physically morphs between a sad, grey orb and a happy, bright yellow star.
Morphing Liquid Toggle Switch
demo & codeThis Morphing Liquid Toggle Switch takes the standard UI control to a new level of polish. Instead of a rigid circle sliding back and forth, the handle behaves like a viscous fluid. When toggled, it stretches, snaps, and settles into place with a satisfying elastic bounce, creating a delightful tactile experience for the user.
Elastic SVG Morphing Form Controls
demo & codeThis Elastic SVG Morphing Form Controls set redefines standard UI elements by treating them as organic, malleable shapes. Instead of rigid CSS transitions, it utilizes GSAP’s MorphSVGPlugin to physically warp the vector paths of checkboxes, radio buttons, and switches during interaction. The result is a tactile, “gummy” feel where elements squish upon clicking and snap elastically into their active states.
Interactive CSS Light Bulb Toggle
demo & codeThis Interactive CSS Light Bulb Toggle transforms a standard theme switch into a playful interaction. It creates a convincing illusion of a physical pull-cord using standard click events. Rather than using a complex physics engine, it relies on precise timing between mouse/touch events and CSS transforms to mimic the tension and release of a rope when the user clicks the button.
Checkbox Switcher
A skeuomorphic toggle switch with a springy tactile press effect and smooth sliding animation.
See the Pen Checkbox Switcher.
Silky Smooth Toggles Volume 2
A collection of advanced SVG toggle switches featuring intricate micro-interactions powered by the Web Animations API. JavaScript classes orchestrate complex transforms on individual SVG rect elements - ranging from staggered offsets to randomized scattering - creating fluid, matrix-like transitions upon state change.
See the Pen Silky Smooth Toggles Volume 2.
Playful Toss Toggle Switch
A playful, tactile toggle switch where the container seemingly ‘spits out’ or lobs the indicator ball to the opposing side.
See the Pen Playful Toss Toggle Switch.
Day and Night Toggle with SVG Animation
An atmospheric day/night toggle where a minimal JavaScript classList.toggle trigger activates a cinematic transition across complex SVG layers. The scenery leverages linear-gradient masking and mix-blend-mode for dynamic lighting, while long-duration CSS transform properties orchestrate a seamless, parallax-like shift between solar and lunar states.
See the Pen Day and Night Toggle with SVG Animation.
Friendly Donut Toggle Switch
This animated donut character employs multiple GSAP timelines with elastic easing functions to create independent yet synchronized animations for body sway, facial expressions, and arm gestures.
See the Pen Friendly Donut Toggle Switch.
3D Capsule Slider Button
A combination of the ‘checkbox hack’ and 3D transforms to create an interactive neumorphism-style switcher. JavaScript only adds classes, while the entire transform: rotateX() animation and complex box-shadow are controlled by CSS.
See the Pen 3D Capsule Slider Button.
Liquid Gooey UI Elements
Explore the powerful tandem of GSAP and CSS Variables, where to/fromTo with keyframes control SVG elements inside Radio/Checkbox/Switch. The animations utilize the feColorMatrix filter (the “Gooey” effect) and SVG transforms to create smoothly “flowing” shapes and stylish toggles.
See the Pen Liquid Gooey UI Elements.
Control Interaction with GSAP
A sleek, animated segmented control using GSAP for smooth slide and a subtle 3D-like tilt effect on click, providing a polished micro-interaction.
See the Pen Control Interaction with GSAP.
Airplane Mode Animation Toggle Switch
A modern toggle switch animation utilizing pure CSS :checked selector states to drive complex plane take-off/landing @keyframes, augmented by vanilla JavaScript’s Web Animations API (WAAPI) for dynamic smoke particle generation and cleanup.
See the Pen Airplane Mode Animation Toggle Switch.
Claymorphic Toggle Switch with GSAP and SVG
A modern, interactive Claymorphism UI toggle built entirely with scalable SVG vector graphics and animated via GSAP showcases intricate shadow effects and the “liquid” transition of its internal elements.
See the Pen Claymorphic Toggle Switch with GSAP and SVG.
Toggle Animation with CSS & State Machines!
State-driven toggle implementation with CSS custom properties, SVG animations, and synchronized visual states for complex UI interactions
See the Pen Toggle Animation with CSS & State Machines!.
Airplane Mode Toggle Switch
An elegant switch with a unique “airport/sky” animation that guarantees responsiveness and smoothness, powered by the GSAP library. Notice the infinite cloud scrolling technique and the precise, container-size-based element positioning, making this a genuinely technically interesting demo.
See the Pen Airplane Mode Toggle Switch.
Animated Checkboxes Demonstration
A demonstration of styling hidden input[type="checkbox"] functionality with modern CSS. It features four distinct, responsive styles, from minimalist SVG-drawing and pill toggles to complex pop and anime.js timeline animations.
See the Pen Animated Checkboxes Demonstration.
Liquid Toggle Switch
An interactive toggle with a “liquid” switching effect, built with GSAP and SVG filters. The demo shows how to combine physics-based animation (Draggable) with dynamic SVG effects (feGaussianBlur, feColorMatrix) to create a realistic, fluid user experience.
See the Pen Liquid Toggle Switch.