Unkey
Components

FormCheckbox

A form checkbox component with built-in label, description, and error handling capabilities.

FormCheckbox

A comprehensive checkbox component that combines labels, descriptions, and validation states. Perfect for creating accessible, user-friendly forms that require selection inputs with proper labeling and helpful context.

Default

The default FormCheckbox includes a label and optional description text, providing clear context for users.

We'll send you occasional updates about our products

Checkbox States

Required Field

Use the required prop to indicate mandatory fields. This automatically adds a "Required" tag to the label.

You must accept our terms to continue

Required Field with Error

When a required field has an error, the "Required" tag changes to error styling to draw more attention.

Optional Field

Use the optional prop to explicitly indicate non-mandatory fields. This adds an "Optional" badge to the label.

Get the latest updates directly to your inbox

Success State

Indicates successful validation or acceptance of selection. The success icon and text provide positive feedback.

Your account is now more secure

Warning State

Used for potentially impactful selections that should be made with caution. Includes a warning icon and explanatory text.

This includes anonymous activity information

Error State

Shows validation errors or other issues that need user attention. Features prominent error styling and message.

Disabled State

Apply when the field should be non-interactive, such as during form submission or based on other field values.

Only available to authorized personnel

Checked State

Pre-selected checkbox with an initial checked state that users can toggle.

Save your settings for future visits

Variants

Outline Variant

A subtler alternative to the primary variant with transparent background when checked.

A summary of your account activity

Ghost Variant

The most minimal styling for checkboxes that need less visual emphasis.

Display additional configuration options

Different Sizes

Checkboxes can be sized appropriately for different UI needs.

Please verify before submission

Complex Usage

Example of FormCheckboxes with multiple props configured for a specific use case, such as a cookie consent form.

Enable all cookie types for the best experience
Required for the website to function
Help us improve site performance and usability
Enable advanced features and personalization
Allow us to provide relevant advertisements

Props

The FormCheckbox component extends the standard Checkbox component props with additional form-specific properties:

PropTypeDefault
label
string
-
description
ReactNode
-
required
boolean
-
optional
boolean
-
error
string
-
variant
"default" | "primary" | "outline" | "ghost"
-
color
"default" | "success" | "warning" | "danger" | "info"
-
size
"sm" | "md" | "lg" | "xlg"
-

Accessibility

FormCheckbox is built with accessibility in mind:

  • Labels are properly associated with checkboxes using htmlFor/id
  • Error messages are announced to screen readers using role="alert"
  • Required fields are marked both visually and via aria-required
  • Helper text is linked to checkboxes using aria-describedby
  • Error states are indicated using aria-invalid
  • Checkboxes maintain proper focus states for keyboard navigation

Best Practices

When using the FormCheckbox component:

  • Always provide clear, concise labels that describe the action being taken
  • Use description text to provide additional context about the implications of selection
  • Write labels as positive statements (what will happen if checked)
  • Keep error messages specific and actionable
  • Use required fields sparingly and logically
  • Group related checkboxes together with a descriptive heading
  • Consider the mobile experience with appropriate touch targets
  • Maintain consistent validation patterns across your form
  • Test with screen readers and keyboard navigation to ensure accessibility

Layout Guidelines

  • Labels should be positioned to the right of the checkbox
  • Error messages should appear immediately below the checkbox
  • Description text should be helpful but not too lengthy
  • Consider using the optional badge for clarity in forms with many fields
  • For groups of related checkboxes, consider using a fieldset with legend
  • Maintain consistent spacing between multiple checkboxes in a group
  • Use appropriate visual hierarchy when nesting checkboxes (e.g., for "select all" patterns)

On this page