Toggle Switch Feedback
A switch highlights on hover and preserves its on/off state when clicked.
A switch highlights on hover and preserves its on/off state when clicked.
Live Demo
Hover over the element or use Tab to focus.
Source Code
Copy the HTML, CSS or JavaScript you need for your project.
<label class="tbx-1042"><span class="tbx-1042__text"><b>Receive updates</b><small>Notify me of updates</small></span><input type="checkbox" checked aria-label="Notify me of updates"><span class="tbx-1042__track" aria-hidden="true"><span class="tbx-1042__knob"></span></span></label>
.tbx-1042{display:flex;align-items:center;gap:12px;justify-content:space-between;width:min(277px,100%);padding:17px 14px;border:1px solid #d6e1ea;border-radius:10px;background:white;cursor:pointer;position:relative;font-family:system-ui;transition:background .2s,border .2s}
.tbx-1042__text{display:grid;gap:4px}.tbx-1042__text b{font-size:12px;color:#243d52}.tbx-1042__text small{font-size:10px;color:#7a8d9c}
.tbx-1042 input{position:absolute;opacity:0;width:1px;height:1px}.tbx-1042__track{width:44px;height:26px;border-radius:99px;background:#bfc9d3;padding:3px;flex:none;transition:background .24s,box-shadow .24s}
.tbx-1042__knob{display:block;width:20px;height:20px;border-radius:50%;background:white;box-shadow:0 1px 4px #0a233032;transition:transform .24s}
.tbx-1042 input:checked+.tbx-1042__track{background:#2c806e}.tbx-1042 input:checked+.tbx-1042__track .tbx-1042__knob{transform:translateX(18px)}
.tbx-1042:hover{background:#f2faf7;border-color:#9cc5bb}.tbx-1042:hover .tbx-1042__track{box-shadow:0 0 0 5px #4a98801a}
.tbx-1042:focus-within{outline:2px solid #cc8d56;outline-offset:2px}
@media(prefers-reduced-motion:reduce){.tbx-1042,.tbx-1042__track,.tbx-1042__knob{transition:none}}
How to Use
Insert the HTML and add the CSS to your stylesheet. Adjust colors and sizes and avoid class conflicts.
Use Case
Useful for forms and settings sections.
Technical Notes
Keep controls usable on touch devices. Test keyboard focus and reduced-motion preferences.
Mobile: Ensure the interactive content remains accessible without hover on touch devices.
Browser: Uses modern CSS. Check behavior in the browsers you support.
Reduced Motion: Check that prefers-reduced-motion is respected.