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.

Wi-Fi changes a setting. Task checkbox selects a task.

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.

html
<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.

Distinguish an action from a pressed choice

An action button starts something: Save changes, Download, or Open menu. A toggle button represents a persistent pressed or unpressed choice, such as Bold in an editor. Use aria-pressed for an appropriate toggle button and keep its accessible label stable. Its selected appearance should remain clear after the pointer leaves.

Keep form behavior explicit by selecting the right button type. A supporting action inside a form often needs type="button"; the intended submit control can use type="submit". Do not turn a navigation link into an action button only to copy its appearance. People should be able to predict whether a control changes a setting, sends data, or takes them elsewhere.

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.

More practical guides

Button states: hover, focus, loading, success, and errorDesign clear button states with an interactive example, keyboard focus, loading feedback, and practical HTML, CSS, and JavaScript guidance.Animated buttons with HTML, CSS, and JavaScriptBuild purposeful button animation with CSS transitions, clear interaction states, reversible motion, and a reduced-motion alternative.