Back to Base UIYou are on Checkbox.

Checkbox

A checkbox with a swelling fill and a check that draws itself.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks

Libraries

Base UI

Motion

Spring + short tween

Reduced motion

Fade in place
checkbox.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/checkbox.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/checkbox.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
checkbox.tsx
"use client";

import * as React from "react";
import { motion, useReducedMotion } from "motion/react";
import { cn } from "@/lib/utils";

export type CheckboxProps = {
  checked?: boolean;
  defaultChecked?: boolean;
  onCheckedChange?: (checked: boolean) => void;
  label?: React.ReactNode;
  disabled?: boolean;
  className?: string;
};

const checkSpring = { type: "spring", stiffness: 500, damping: 24 } as const;

export function Checkbox({
  checked,
  defaultChecked = false,
  onCheckedChange,
  label = "Accept terms",
  disabled = false,
  className,
}: CheckboxProps) {
  const [internal, setInternal] = React.useState(defaultChecked);
  const value = checked ?? internal;
  const reduce = useReducedMotion();

  const toggle = () => {
    if (disabled) return;
    const next = !value;
    if (checked === undefined) setInternal(next);
    onCheckedChange?.(next);
  };

  return (
    <label className={cn("flex items-center gap-2.5 text-[13px]", className)}>
      <button
        type="button"
        role="checkbox"
        aria-checked={value}
        disabled={disabled}
        onClick={toggle}
        className={cn(
          "relative flex size-4 items-center justify-center rounded-[4px] border outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50",
          value ? "border-foreground" : "border-input",
        )}
      >
        {value && (
          <motion.span
            aria-hidden="true"
            initial={reduce ? false : { scale: 0.5, opacity: 0 }}
            animate={{ scale: 1, opacity: 1 }}
            transition={checkSpring}
            className="absolute inset-0 rounded-[3px] bg-foreground"
          />
        )}
        <svg
          aria-hidden="true"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          strokeWidth="3"
          strokeLinecap="round"
          strokeLinejoin="round"
          className="relative size-3 text-background"
        >
          <motion.path
            d="m5 12 4 4L19 6"
            initial={reduce ? false : { pathLength: 0 }}
            animate={{ pathLength: value ? 1 : 0 }}
            transition={
              reduce
                ? { duration: 0 }
                : { duration: 0.25, ease: [0.23, 1, 0.32, 1] }
            }
          />
        </svg>
      </button>
      <span>{label}</span>
    </label>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/checkbox.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

checkbox.tsx
import { Checkbox } from "@/components/prequelui/checkbox";

export default function Demo() {
  return (
    <label className="flex items-center gap-3 text-[13.5px]">
      <Checkbox defaultChecked />
      Send me product updates
    </label>
  );
}
import { Checkbox } from "@/components/prequelui/checkbox";

export function Variant() {
  return (
    <Checkbox tempo={1.2}>
      …
    </Checkbox>
  );
}
03

Animation

A filled pill grows under the check first, then the stroke draws itself from the first point to the last. The fill and the border colour move together so the box never shows an empty checked state.

  • Fill: a 500 / 24 spring on scale and opacity.
  • Check: 300 ms with the draw curve, delayed 200 ms after the fill.
  • Unchecking removes the stroke in the same 300 ms window.
  • The indeterminate state draws a single horizontal line.
  • Reduced motion shows the final state without the draw.
check 300 msdelay 200 msspring 500 / 24draw curve
04

API Reference

Every part takes exactly the props of the Checkbox primitive. The animated surface adds only motion props, so the accessibility tree and keyboard behaviour stay the same.

Checkbox

PropTypeDefault
checkedboolean—
defaultCheckedbooleanfalse
indeterminatebooleanfalse
onCheckedChange(checked: boolean) => void—
disabledbooleanfalse
classNamestring—

Next component

Code Block

A code surface that types itself in, copies cleanly and follows the caret.