Skip to documentation
BoobstrapDocs
Forms

Switch

Build accessible on/off toggle switches, descriptions, groups, disabled states, and validation feedback.

Forms guideCopy-ready referencev0.7.0 current
Forms

Switch

The .bs-switch modifier turns any .bs-check checkbox into a toggle switch with smooth pill animations and full keyboard accessibility.

Basic switch

HTML · Basic switch
<label class="bs-check bs-switch">
  <input class="bs-check-input" type="checkbox" name="airplane_mode" />
  <span class="bs-check-label">Airplane mode</span>
</label>

Checked state

HTML · Checked switch
<label class="bs-check bs-switch">
  <input class="bs-check-input" type="checkbox" name="wifi" checked />
  <span class="bs-check-label">Wi-Fi networking (Active)</span>
</label>

Switch with descriptions

HTML · Switch with description
<label class="bs-check bs-switch">
  <input class="bs-check-input" type="checkbox" name="auto_deploy" checked />
  <span class="bs-check-label">Automatic deployment</span>
  <span class="bs-check-description">
    Trigger preview deployments automatically on every commit to pull requests.
  </span>
</label>

Switch group

Security preferences
HTML · Switch group
<fieldset class="bs-check-group">
  <legend class="bs-label">Security preferences</legend>
  <label class="bs-check bs-switch">
    <input class="bs-check-input" type="checkbox" name="mfa" checked />
    <span class="bs-check-label">Multi-factor authentication</span>
    <span class="bs-check-description">Require a hardware key or TOTP token on sign-in.</span>
  </label>
  <label class="bs-check bs-switch">
    <input class="bs-check-input" type="checkbox" name="single_session" checked />
    <span class="bs-check-label">Single concurrent session</span>
    <span class="bs-check-description">Terminate previous sessions when signing in elsewhere.</span>
  </label>
</fieldset>

Disabled state

HTML · Disabled switches
<label class="bs-check bs-switch">
  <input class="bs-check-input" type="checkbox" disabled />
  <span class="bs-check-label">Early access previews (Unavailable)</span>
</label>

<label class="bs-check bs-switch">
  <input class="bs-check-input" type="checkbox" checked disabled />
  <span class="bs-check-label">Compliance audit log (Enforced)</span>
</label>

Valid state

HTML · Valid switch
<div class="bs-form-group">
  <label class="bs-check bs-switch">
    <input class="bs-check-input bs-is-valid" type="checkbox" checked aria-invalid="false" aria-describedby="ssl-msg" />
    <span class="bs-check-label">Enforce HTTPS & TLS 1.3</span>
  </label>
  <span class="bs-form-feedback bs-form-feedback-valid" id="ssl-msg">
    TLS certificate active and verified.
  </span>
</div>

Invalid state

Apply aria-invalid="true" or .bs-is-invalid when a required switch setting has not been confirmed or accepted. The switch track and focus ring show the danger tone and the error message appears below.

Production migration
HTML · Invalid switch
<div class="bs-form-group">
  <fieldset class="bs-check-group">
    <legend class="bs-label">Production migration <span class="bs-label-required" aria-hidden="true">*</span></legend>
    <label class="bs-check bs-switch">
      <input
        class="bs-check-input"
        type="checkbox"
        name="confirm_migration"
        aria-invalid="true"
        aria-describedby="migration-error"
        required
      />
      <span class="bs-check-label">Confirm schema migration on live production cluster</span>
    </label>
    <span class="bs-form-feedback bs-form-feedback-invalid" id="migration-error">
      You must enable the confirmation toggle before running database migrations.
    </span>
  </fieldset>
</div>

Instant settings

Switches represent instant on/off toggles. For multi-field forms submitted via a button, standard checkboxes are often preferred.

Role="switch" support

Add role="switch" to the input element when appropriate for screen reader software to announce the control as a switch.

Switch API

Switch classes format smooth sliding toggle switches with label association and validation feedback.

ClassPurpose
.bs-checkBase wrapper element binding input, label, and description.
.bs-switchModifier turning standard check input into a smooth pill-shaped toggle switch.
.bs-check-inputSwitch checkbox input element with sliding thumb animation.
.bs-check-labelLabel text adjacent to the toggle switch.
.bs-check-descriptionSupporting explanatory description text indented below the switch label.
.bs-check-groupFieldset container grouping multiple switches into an organized list.
.bs-is-validPositive validation state styling for switch controls.
.bs-is-invalidNegative validation state styling with error border and track highlights.
.bs-form-feedback-validSuccess message text associated with valid switch state.
.bs-form-feedback-invalidError message text describing required or invalid switch toggles.