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.
<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>import { Checkbox } from "@/components/vin/checkbox";
export function CheckboxBasic() {
return <Checkbox label="Accept the terms" />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Checkbox from "@/components/vin/checkbox.vue";
</script>
<template>
<Checkbox label="Accept the terms" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Checkbox from "$lib/components/vin/checkbox.svelte";
</script>
<Checkbox label="Accept the terms" />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.
<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>A short email every Monday with what changed.
import { Checkbox } from "@/components/vin/checkbox";
export function CheckboxDescription() {
return <Checkbox label="Weekly digest" description="A short email every Monday with what changed." defaultChecked style={{ maxWidth: 340 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Checkbox from "@/components/vin/checkbox.vue";
</script>
<template>
<Checkbox label="Weekly digest" description="A short email every Monday with what changed." default-checked style="max-width: 340px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Checkbox from "$lib/components/vin/checkbox.svelte";
</script>
<Checkbox label="Weekly digest" description="A short email every Monday with what changed." checked style="max-width: 340px" />Group
Wrap related checkboxes in a fieldset with a legend, so the group has a name.
<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>import { Checkbox } from "@/components/vin/checkbox";
export function CheckboxGroup() {
return (
<fieldset style={{ display: "grid", gap: 10, margin: 0, padding: 0, border: 0, minWidth: 0 }}>
<legend className="vin-label" style={{ padding: 0, marginBottom: 10 }}>Notify me about</legend>
<Checkbox label="Comments" defaultChecked />
<Checkbox label="Mentions" defaultChecked />
<Checkbox label="New releases" />
<Checkbox label="Billing (always on)" defaultChecked disabled />
</fieldset>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Checkbox from "@/components/vin/checkbox.vue";
</script>
<template>
<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>
<Checkbox label="Comments" default-checked />
<Checkbox label="Mentions" default-checked />
<Checkbox label="New releases" />
<Checkbox label="Billing (always on)" default-checked disabled />
</fieldset>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Checkbox from "$lib/components/vin/checkbox.svelte";
</script>
<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>
<Checkbox label="Comments" checked />
<Checkbox label="Mentions" checked />
<Checkbox label="New releases" />
<Checkbox label="Billing (always on)" checked disabled />
</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:
npx @vinish/ui add checkboximport { Checkbox } from "@/components/vin/checkbox";import Checkbox from "@/components/vin/checkbox.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
labelVisible label, linked to the checkbox. Without it, pass an aria-label. | ReactNode | — | <label class="vin-choice__label" for="…"> |
descriptionSmaller text under the label, read out with the checkbox. | ReactNode | — | <p class="vin-choice__desc" id="…"> + aria-describedby |
controlPositionPut the checkbox after the text, full width. | startend | start | vin-choice--end |
indeterminateThe "some selected" dash. In HTML, set input.indeterminate = true with a line of JavaScript. | boolean | false | el.indeterminate = true |
checked / defaultChecked | boolean | — | checked attribute |
disabled | boolean | false | disabled attribute |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.