Skip to content

Toggle Switches with Labels

Dark Bootstrap 6 settings panel with .switch toggles in three sizes, labels with descriptions, disabled states and a simulated auto-save status.

Also known as: toggle switch settings, switch with description, on off toggle list, settings toggles, auto save settings panel

Bootstrap 6 Toggles & Switches Responsive Dark #dark #form #settings #switch #toggle

Toggle Switches with Labels live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A dark device-settings panel with Bootstrap 6 toggle switches. It shows the small, default and large sizes, a themed switch, a feature card with a description, and a notification list with icons and disabled states. A small status line simulates auto-save. Use it for account settings, privacy options or app preference screens.

How it works

Every toggle uses the Bootstrap 6 switch markup: <div class="switch"><input type="checkbox" role="switch" switch></div>. The native switch attribute and role="switch" make screen readers announce it as on or off.

  • Sizes card (.tsl-sizes): switch-sm, switch and switch-lg inside .form-field wrappers, plus a switch theme-success for a second color.
  • Feature card (.tsl-feature): a large switch with a .form-field-content column for the label and description.
  • Notifications (.tsl-list): each .tsl-row is a flex row with an icon, the label and description, and the switch at the end. Two rows use disabled: one is off and one is locked on.

The amber accent comes from --bs-control-checked-bg on .tsl-root. .tsl-root .switch sets a darker track (--bs-switch-bg) and border. A :has(input:checked) rule turns the knob dark on the amber track. Another :has() rule tints a row's .tsl-icon when its switch is on.

script.js listens for change on the root. It updates the .tsl-count-num badge for the notification list. It then shows "Saving…" in .tsl-status and confirms the change after a short simulated delay.

Customization

  • --tsl-accent and --tsl-accent-soft on .tsl-root: change the checked track, the icons, the count badge and the focus ring.
  • --bs-switch-bg and --bs-switch-border-color in .tsl-root .switch: restyle the unchecked track.
  • --bs-switch-height on a .switch: set any custom size. The width follows at 1.75× the height.
  • Change theme-success to theme-danger or theme-info, and edit the .switch.theme-success:has(input:checked) rule to match.
  • Add or remove disabled on any input to lock a setting. The label and icon dim automatically.
  • Replace the setTimeout in script.js with a fetch() PATCH to save each setting.

Use cases

  • Account and app settings: switches with labels and short descriptions explain each option
  • Preference screens: a simulated auto-save status confirms that changes were stored
  • Admin dashboards: three switch sizes fit different layouts and densities
  • Plan-limited features: disabled switches show options that are not available yet

Accessibility

Each switch has a <label for>. Rows with descriptions link them through aria-describedby. Switches work with Tab and Space and show the accent focus ring through --bs-focus-ring. The count badge is aria-live="polite", and the save message uses role="status". Icons are aria-hidden. Transitions are disabled under prefers-reduced-motion. The root sets data-bs-theme="dark", so the panel always renders dark.

Bootstrap 6 notes

Bootstrap 5's form-check form-switch wrapper becomes a .switch div around the input, with switch-sm / switch-lg sizes and theme-* colors on the wrapper. Labels go in .form-field or .form-field-content. Built on Bootstrap 6.0.0-alpha.1, so alpha APIs can still change. Icons come from Bootstrap Icons.

Toggle Switches with Labels at a glance

Framework
Bootstrap 6
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 6, Bootstrap Icons
Layout
Responsive, works on mobile, dark design
Category
Toggles & Switches
License
Free for personal and commercial use

Questions about this template

Can I use the Toggle Switches with Labels code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 6 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css">
  • <script type="module" src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">

Built for Bootstrap 6.0.0-alpha.1. Bootstrap 6 ships as an ES module, so its script and this component's JavaScript load with type="module". Alpha releases can still change before the stable version.

Toggle Switches with Labels – Bootstrap 6 toggles & switches component screenshot
Toggle Switches with Labels · Bootstrap 6 Toggles & Switches

More Toggles & Switches

iOS Style Toggle Switch – Pure CSS toggles & switches preview

iOS Style Toggle Switch

Pure CSS iOS style toggle switches built on real checkboxes, in a grouped settings list with three sizes, five colors and a disabled state.

Settings Toggles with Description – Tailwind CSS toggles & switches preview

Settings Toggles with Description

Tailwind CSS settings panel with accessible switches, label descriptions, a locked required option, restore defaults and an auto-save status message.

Day/Night Toggle – Pure CSS toggles & switches preview

Day/Night Toggle

Animated pure CSS day and night toggle switch where the sun turns into a cratered moon, clouds drift away and stars appear.