Skip to content

Checkbox

Turn an option on or off, alone or in a group. Same markup and props in every style: switch the style in the header to see it change.

Basic

A real checkbox input with its label. Clicking the label toggles it.

checkbox-basic.html
<div class="vin-choice">
  <input id="terms" class="vin-checkbox" type="checkbox">
  <div class="vin-choice__body">
    <label class="vin-choice__label" for="terms">Accept the terms</label>
  </div>
</div>

With a description

Extra text under the label is linked with aria-describedby, so it is read out with the checkbox.

A short email every Monday with what changed.

checkbox-description.html
<div class="vin-choice" style="max-width: 340px">
  <input id="digest" class="vin-checkbox" type="checkbox" checked aria-describedby="digest-desc">
  <div class="vin-choice__body">
    <label class="vin-choice__label" for="digest">Weekly digest</label>
    <p class="vin-choice__desc" id="digest-desc">A short email every Monday with what changed.</p>
  </div>
</div>

Group

Wrap related checkboxes in a fieldset with a legend, so the group has a name.

Notify me about
checkbox-group.html
<fieldset style="display: grid; gap: 10px; margin: 0; padding: 0; border: 0; min-width: 0">
  <legend class="vin-label" style="padding: 0; margin-bottom: 10px">Notify me about</legend>
  <div class="vin-choice">
    <input id="n-comments" class="vin-checkbox" type="checkbox" checked>
    <div class="vin-choice__body"><label class="vin-choice__label" for="n-comments">Comments</label></div>
  </div>
  <div class="vin-choice">
    <input id="n-mentions" class="vin-checkbox" type="checkbox" checked>
    <div class="vin-choice__body"><label class="vin-choice__label" for="n-mentions">Mentions</label></div>
  </div>
  <div class="vin-choice">
    <input id="n-releases" class="vin-checkbox" type="checkbox">
    <div class="vin-choice__body"><label class="vin-choice__label" for="n-releases">New releases</label></div>
  </div>
  <div class="vin-choice">
    <input id="n-billing" class="vin-checkbox" type="checkbox" checked disabled>
    <div class="vin-choice__body"><label class="vin-choice__label" for="n-billing">Billing (always on)</label></div>
  </div>
</fieldset>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add checkbox
React
import { Checkbox } from "@/components/vin/checkbox";
Vue
import Checkbox from "@/components/vin/checkbox.vue";
Svelte
import Checkbox from "$lib/components/vin/checkbox.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.

API

From spec/checkbox.json, which every framework version is tested against.

PropValuesDefaultIn HTML
label
Visible label, linked to the checkbox. Without it, pass an aria-label.
ReactNode—<label class="vin-choice__label" for="…">
description
Smaller text under the label, read out with the checkbox.
ReactNode—<p class="vin-choice__desc" id="…"> + aria-describedby
controlPosition
Put the checkbox after the text, full width.
startendstartvin-choice--end
indeterminate
The "some selected" dash. In HTML, set input.indeterminate = true with a line of JavaScript.
booleanfalseel.indeterminate = true
checked / defaultCheckedboolean—checked attribute
disabledbooleanfalsedisabled attribute

Parts

React, Vue, SvelteHTML classes
<Checkbox>.vin-choice.vin-choice--end.vin-choice__body.vin-choice__label.vin-choice__desc.vin-checkbox

Accessibility

  • A native <input type="checkbox">: Space toggles it, and forms submit it with no extra code.
  • Every checkbox has a label: a <label for> or an aria-label.
  • Descriptions are linked with aria-describedby.
  • Related checkboxes sit in a <fieldset> with a <legend>.
  • Visible focus ring in every style and mode; the tick is drawn, not a font icon.