Checks and radios

Create consistent cross-browser and cross-device checkboxes and radios with our completely rewritten checks component.

On this page

Approach

Browser default checkboxes and radios are replaced with the help of FormCheck, a series of classes for both input types that improves the layout and behavior of their HTML elements, that provide greater customization and cross browser consistency.

Checkboxes are for selecting one or several options in a list, while radios are for selecting one option from many.

Structurally, our FormCheckInputs and FormCheckLabels are sibling elements as opposed to an FormCheckInput within a FormCheckLabel.

This is slightly more verbose as you must specify id and for attributes to relate the FormCheckInput and FormCheckLabel.

We use the sibling selector (~) for all our FormCheckInput states, like :checked or :disabled.

When combined with the .form-check-label class, we can easily style the text for each item based on the FormCheckInput's state.

Our checks use custom Bootstrap icons to indicate checked or indeterminate states.

Checks

Checkbox 1
false
Checkbox 2
true
vue
<template>
  <BFormCheck>
    <BFormCheckInput v-model="checkbox1" />
    <BFormCheckLabel>Default checkbox</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput v-model="checkbox2" />
    <BFormCheckLabel>Checked checkbox</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput checked />
    <BFormCheckLabel>Static checked checkbox</BFormCheckLabel>
  </BFormCheck>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Checkbox 1
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox1 }}
    </b-dd>
    <b-dt col="sm-3">
      Checkbox 2
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox2 }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const checkbox1 = ref(false)
const checkbox2 = ref(true)
</script>

Custom value Model Binding

Checkbox 1
ng
Checkbox 2
ok
vue
<template>
  <BFormCheck>
    <BFormCheckInput
      v-model="checkbox1"
      true-value="ok"
      false-value="ng"
    />
    <BFormCheckLabel>Default checkbox</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput
      v-model="checkbox2"
      true-value="ok"
      false-value="ng"
    />
    <BFormCheckLabel>Checked checkbox</BFormCheckLabel>
  </BFormCheck>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Checkbox 1
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox1 }}
    </b-dd>
    <b-dt col="sm-3">
      Checkbox 2
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox2 }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const checkbox1 = ref('ng')
const checkbox2 = ref('ok')
</script>

Indeterminate

Checkboxes can utilize the indeterminate attributes when manually set.

vue
<template>
  <BFormCheck>
    <BFormCheckInput indeterminate />
    <BFormCheckLabel>
      Indeterminate checkbox
    </BFormCheckLabel>
  </BFormCheck>
</template>

Disabled

Add the disabled attribute and the associated FormCheckLabels are automatically styled to match with a lighter color to help indicate the input's state.

vue
<template>
  <BFormCheck>
    <BFormCheckInput disabled />
    <BFormCheckLabel>Disabled checkbox</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput
      checked
      disabled
    />
    <BFormCheckLabel>Disabled checked checkbox</BFormCheckLabel>
  </BFormCheck>
</template>

Radios

Selected Value
two
vue
<template>
  <BFormCheck>
    <BFormCheckInput
      v-model="radioValue"
      value="one"
      type="radio"
    />
    <BFormCheckLabel>Default radio</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput
      v-model="radioValue"
      value="two"
      type="radio"
    />
    <BFormCheckLabel>Default checked radio</BFormCheckLabel>
  </BFormCheck>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Selected Value
    </b-dt>
    <b-dd col="sm-9">
      {{ radioValue }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const radioValue = ref('two')
</script>

Disabled

Add the disabled attribute and the associated FormCheckLabels are automatically styled to match with a lighter color to help indicate the input's state.

vue
<template>
  <BFormCheck>
    <BFormCheckInput
      type="radio"
      name="flexRadioDisabled"
      disabled
    />
    <BFormCheckLabel>Disabled radio</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput
      type="radio"
      name="flexRadioDisabled"
      checked
      disabled
    />
    <BFormCheckLabel>Disabled checked radio</BFormCheckLabel>
  </BFormCheck>
</template>

Switches

A switch has the markup of a custom checkbox but uses the switch class to render a toggle switch. Consider using role="switch" to more accurately convey the nature of the control to assistive technologies that support this role. In older assistive technologies, it will simply be announced as a regular checkbox as a fallback. Switches also support the disabled attribute.

Checkbox 1
false
Checkbox 2
true
Checkbox 3
false
vue
<template>
  <BFormCheck switch>
    <BFormCheckInput v-model="checkbox1" />
    <BFormCheckLabel>Default switch checkbox input</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck switch>
    <BFormCheckInput v-model="checkbox2" />
    <BFormCheckLabel>Checked switch checkbox input</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck switch>
    <BFormCheckInput
      v-model="checkbox3"
      :disabled="checkbox1 != checkbox2"
    />
    <BFormCheckLabel>Disabled switch checkbox input</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck switch>
    <BFormCheckInput
      checked
      disabled
    />
    <BFormCheckLabel>Disabled checked switch checkbox input</BFormCheckLabel>
  </BFormCheck>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Checkbox 1
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox1 }}
    </b-dd>
    <b-dt col="sm-3">
      Checkbox 2
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox2 }}
    </b-dd>
    <b-dt col="sm-3">
      Checkbox 3
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox3 }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const checkbox1 = ref(false)
const checkbox2 = ref(true)
const checkbox3 = ref(false)
</script>

Default (stacked)

By default, any number of checkboxes and radios that are immediate sibling will be vertically stacked and appropriately spaced with FormCheck.

vue
<template>
  <BFormCheck>
    <BFormCheckInput />
    <BFormCheckLabel>Default checkbox</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput disabled />
    <BFormCheckLabel>Disabled checkbox</BFormCheckLabel>
  </BFormCheck>
</template>
vue
<template>
  <BFormCheck>
    <BFormCheckInput
      type="radio"
      name="exampleRadios"
      value="option1"
      checked
    />
    <BFormCheckLabel>Default radio</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput
      type="radio"
      name="exampleRadios"
      value="option2"
    />
    <BFormLabel>Second default radio</BFormLabel>
  </BFormCheck>
  <BFormCheck>
    <BFormCheckInput
      type="radio"
      name="exampleRadios"
      value="option3"
      disabled
    />
    <BFormCheckLabel>Disabled radio</BFormCheckLabel>
  </BFormCheck>
</template>

Inline

Group checkboxes or radios on the same horizontal row by adding inline to any FormCheck.

vue
<template>
  <BFormCheck inline>
    <BFormCheckInput value="option1" />
    <BFormCheckLabel>1</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck inline>
    <BFormCheckInput value="option2" />
    <BFormCheckLabel>2</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck inline>
    <BFormCheckInput
      value="option3"
      disabled
    />
    <BFormCheckLabel>3 (disabled)</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck inline>
    <BFormCheckInput
      type="radio"
      name="inlineRadioOptions"
      value="option1"
    />
    <BFormCheckLabel>1</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck inline>
    <BFormCheckInput
      type="radio"
      name="inlineRadioOptions"
      value="option2"
    />
    <BFormCheckLabel>2</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck inline>
    <BFormCheckInput
      type="radio"
      name="inlineRadioOptions"
      value="option3"
      disabled
    />
    <BFormCheckLabel>3 (disabled)</BFormCheckLabel>
  </BFormCheck>
</template>

Reverse

Put your checkboxes, radios, and switches on the opposite side with the reverse modifier class.

vue
<template>
  <BFormCheck reverse>
    <BFormCheckInput value="" />
    <BFormCheckLabel>Reverse checkbox</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck reverse>
    <BFormCheckInput
      value=""
      disabled
    />
    <BFormCheckLabel>Disabled reverse checkbox</BFormCheckLabel>
  </BFormCheck>
  <BFormCheck
    switch
    reverse
  >
    <BFormCheckInput value="option3" />
    <BFormCheckLabel>Reverse switch checkbox input</BFormCheckLabel>
  </BFormCheck>
</template>

Without labels

Omit the wrapping FormCheck for checkboxes and radios that have no label text.

Remember to still provide some form of accessible name for assistive technologies (for instance, using aria-label).

vue
<template>
  <b-div>
    <BFormCheckInput
      value=""
      aria-label="..."
    />
  </b-div>

  <b-div>
    <BFormCheckInput
      type="radio"
      name="radioNoLabel"
      value=""
      aria-label="..."
    />
  </b-div>
</template>

Toggle buttons

Create button-like checkboxes and radio buttons by using .btn styles rather than .form-check-label on the FormCheckLabel,elements.

These toggle buttons can further be grouped in a button group if needed.

Checkbox toggle buttons

Toggle 1
false
Toggle 2
true
vue
<template>
  <CheckboxToggleButton
    v-model="checkbox1"
    button="primary"
  >
    Single toggle 1
  </CheckboxToggleButton>
  <CheckboxToggleButton
    v-model="checkbox2"
    button="primary"
  >
    Single toggle 2
  </CheckboxToggleButton>
  <CheckboxToggleButton
    button="primary"
    checked
  >
    Checked
  </CheckboxToggleButton>
  <CheckboxToggleButton
    button="primary"
    disabled
  >
    Disabled
  </CheckboxToggleButton>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Toggle 1
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox1 }}
    </b-dd>
    <b-dt col="sm-3">
      Toggle 2
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox2 }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const checkbox1 = ref(false)
const checkbox2 = ref(true)
</script>
Toggle 1
false
Toggle 2
true
vue
<template>
  <CheckboxToggleButton v-model="checkbox1">
    Single toggle 1
  </CheckboxToggleButton>
  <CheckboxToggleButton v-model="checkbox2">
    Single toggle 2
  </CheckboxToggleButton>
  <CheckboxToggleButton
    disabled
  >
    Disabled
  </CheckboxToggleButton>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Toggle 1
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox1 }}
    </b-dd>
    <b-dt col="sm-3">
      Toggle 2
    </b-dt>
    <b-dd col="sm-9">
      {{ checkbox2 }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const checkbox1 = ref(false)
const checkbox2 = ref(true)
</script>

Radio toggle buttons

Toggle 1
one
vue
<template>
  <RadioToggleButton
    v-model="radio1"
    value="one"
    button="secondary"
    checked
  >
    Checked
  </RadioToggleButton>
  <RadioToggleButton
    v-model="radio1"
    value="two"
    button="secondary"
  >
    Radio
  </RadioToggleButton>
  <RadioToggleButton
    v-model="radio1"
    value="three"
    button="secondary"
    disabled
  >
    Disabled
  </RadioToggleButton>
  <RadioToggleButton
    v-model="radio1"
    value="four"
    button="secondary"
  >
    Radio
  </RadioToggleButton>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Toggle 1
    </b-dt>
    <b-dd col="sm-9">
      {{ radio1 }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const radio1 = ref('one')
</script>
Toggle 1
one
vue
<template>
  <RadioToggleButton
    v-model="radio1"
    value="one"
    checked
  >
    Checked
  </RadioToggleButton>
  <RadioToggleButton
    v-model="radio1"
    value="two"
  >
    Radio
  </RadioToggleButton>
  <RadioToggleButton
    v-model="radio1"
    value="three"
    disabled
  >
    Disabled
  </RadioToggleButton>
  <RadioToggleButton
    v-model="radio1"
    value="four"
  >
    Radio
  </RadioToggleButton>
  <b-dl margin="t-5">
    <b-dt col="sm-3">
      Toggle 1
    </b-dt>
    <b-dd col="sm-9">
      {{ radio1 }}
    </b-dd>
  </b-dl>
</template>
<script setup>
const radio1 = ref('one')
</script>

Outlined styles

Different variants of .btn, such at the various outlined styles, are supported.

vue
<template>
  <CheckboxToggleButton button="outline-primary">
    Single toggle
  </CheckboxToggleButton>
  <CheckboxToggleButton
    button="outline-secondary"
    checked
  >
    Checked
  </CheckboxToggleButton>
  <RadioToggleButton
    name="options-outlined"
    button="outline-success"
    checked
  >
    Checked success radio
  </RadioToggleButton>
  <RadioToggleButton
    name="options-outlined"
    button="outline-danger"
  >
    Danger radio
  </RadioToggleButton>
</template>