Toggle, checkbox, or button?
A switch, checkbox, and button can all react to a click, but they communicate different expectations. Choose the control by what a person is changing. The shape comes after the meaning: turning a setting on, selecting an option, or starting an action.
// glass-toggle-wifi · original package example
{
// Explicit offline demonstration. No backend operation is performed.
// For an application: use .mount(element, { onChange, onSubmit, ... }) instead.
const initialScene = "pastel";
const host = document.querySelector('[data-glass-toggle="wifi"]');
void(async()=>{const response=await fetch(new URL('./buttons.css',document.baseURI));if(!response.ok)throw Error('Styles unavailable');const cssText=await response.text();const controller = globalThis.SLGlassToggles["glass-toggle-wifi"].mountPreview(host, {scene:initialScene,cssText,assetBase:new URL('./',document.baseURI)});
window.addEventListener('pagehide', event => { if(!event.persisted) controller.destroy(); });})();
}
// glass-checkbox-task · original package example
{
// Explicit offline demonstration. No backend operation is performed.
// For an application: use .mount(element, { onChange, onSubmit, ... }) instead.
const initialScene = "pastel";
const host = document.querySelector('[data-glass-more="task"]');
void(async()=>{const response=await fetch(new URL('./buttons.css',document.baseURI));if(!response.ok)throw Error('Styles unavailable');const cssText=await response.text();const controller = globalThis.SLGlassMore["glass-checkbox-task"].mountPreview(host, {scene:initialScene,cssText,assetBase:new URL('./',document.baseURI)});
window.addEventListener('pagehide', event => { if(!event.persisted) controller.destroy(); });})();
}Interactive demo. No data is sent.
Begin with the thing being changed
Write the interaction as a sentence. Enable notifications describes an on-or-off setting. Include a receipt describes a choice in a larger form. Send receipt starts an action. Those sentences give you a stronger basis for choosing a control than matching whichever shape happens to look best beside the field.
Next, decide when the change takes effect. A setting that applies immediately creates a different expectation from a group of choices waiting for a Save button. The visual control, its label, and nearby explanation should agree about that timing. If persistence requires a request, communicate its pending or failed result rather than silently reverting the interface.
Use a switch for an on-or-off setting
A switch fits a binary setting such as notification delivery or a preview preference. Give it a stable label that names the setting. When it changes, the checked state communicates whether that setting is on. Renaming the label from Enable notifications to Disable notifications can make it harder to understand what the switch represents.
Provide the correct accessible role and state, and support keyboard interaction. A custom switch is more than a sliding circle: it needs a meaningful name, a focus indicator, and an announced on-or-off value. In the example above, changes affect the local demonstration only and are not saved as account settings.
<button type="button" role="switch"
aria-checked="false" aria-label="Notifications">
<span aria-hidden="true" class="thumb"></span>
</button>Use a checkbox for a selection
A checkbox works well when someone selects independent options, especially within a form. Several choices can be checked together. Put a visible label next to each one and associate it with the input so clicking the words selects the option too. A native input gives you a useful foundation for keyboard and form behavior.
A parent checkbox can also represent a partly selected group, using an indeterminate state where appropriate. Keep the relationship clear: selecting the parent should have a predictable effect on its children. Explain whether selections apply immediately or wait for submission. A checkbox’s meaning does not depend on drawing a square; the interaction and semantics matter together.
Review the control in context
Read the label aloud with its state, then try it using Tab and Space. Check a selected state, a failed change, and any disabled condition. Use text or another visible cue alongside color. On a narrow screen, keep the label associated with the control so wrapping does not create ambiguity about which option it describes.
SL UI Library lets you inspect different control types before choosing one. Pick the behavior that matches your task, adapt its palette, and take the complete source package. React and Next.js entries may need adjacent controller and style files. Connect persistence deliberately; a local checked state or a preview confirmation does not prove an account preference was saved.
Reference documentation
Technical documentation behind these examples. You can use the article without opening these links.