Skip to content

Checkbox

Choose yes or no by clicking the box or its label; the tick shows the value the app accepted.

Notifications

<script setup lang="ts">import { ref } from 'vue'import { UiCard, UiStack, UiCheckbox } from 'grani' const receipt = ref(true) const reminders = ref(false) const consent = ref(false) const contract = ref(false)</script> <template>  <UiCard title="Notifications" class="w-full max-w-sm">    <UiStack gap="tight">      <UiCheckbox v-model="receipt">Send me the receipt by email</UiCheckbox>      <UiCheckbox v-model="reminders">Remind me three days before an invoice is due</UiCheckbox>      <UiCheckbox v-model="consent">        Keep my contact details for as long as the account is open, and use them only for the        receipts and the notices this account asks for      </UiCheckbox>      <UiCheckbox v-model="contract" required>I have read the contract</UiCheckbox>    </UiStack>  </UiCard></template>

Also called check box, tick box.

Usage

<UiCheckbox v-model="value">…</UiCheckbox>

With GraniResolver in the Vite config, a template needs no import: set it up once.

API

Name · typeDefaultDescription
Value
modelValue*booleanWhether the checkbox is checked (v-model).
Behavior
indeterminateboolean= falsefalseShows a mixed state when some of the items it represents are checked. Display only.
valuestringNative value submitted with the form when checked.
Look
sizexs | sm | mdStep of the control ladder: the box is 16, 18 or 20 px beside text-sm. Unset, the app's size (createGrani({ size })), sm by default.
Form and access
namestringNative name for forms.
idstringOwn id when standalone. Inside UiField, the field's id takes precedence.
disabledboolean= falsefalsePrevents toggling.
invalidboolean= falsefalseMarks the control as invalid. Inside UiField, the error state sets this automatically.
ariaLabelstringAccessible name when the slot is empty and there is no field label; slot text wins over it.
requiredboolean= falsefalseStandalone only: the box must be checked, said to a reader and to a form (native required), with a star after its text. Inside UiField the field's required says so.

Attributes: class and style stay on the outer element; the rest (native attributes, aria-*, data-testid) reach the control inside it.

When to use another component

When you needTake
A setting applied at onceSwitch
One answer out of a fewRadio group
Several picks from a list in a panelSelect multiple