Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Checkbox examples · Standard

Todo Style Checkbox for React

A to-do item whose label is struck through and muted once its checkbox is checked.

Framework
UI library

To-do lists live on one interaction: tick a task, see it done. The checkbox here is controlled, and its checked state drives the label's classes: once checked, line-through and text-muted-foreground strike the task out and fade it, with transition-colors easing the fade. The task stays in place, so people can see what they finished and untick it. Use it for checklists, task lists and shopping lists.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does the strikethrough styling work?

The checked value lives in state, and cn() adds line-through text-muted-foreground to the FieldLabel when it's true. Ticking the box updates the state, and the label restyles on the next render. The state is updated in onCheckedChange.

Can I customize the completion animation?

transition-colors fades the color; change the speed with duration-300 or duration-75. The line itself can't animate with a plain class, so keep the effect short: completion should feel instant.

Does the task text stay when the box is checked?

Yes. The label stays in place. While checked is true, line-through and text-muted-foreground apply. Clearing the box drops those classes, because cn() adds them only for that state.

Why is this checkbox controlled?

The label has to read the same value as the box. This demo keeps checked in state, starts it at false, and passes it through. An uncontrolled box would update itself and the label would not know.

How do I start with the task already done?

Start the state at true and the task renders already struck through. The checkbox stays controlled, so the label and the box share that one value. Pass checked.

Are todo checkboxes accessible with strikethrough?

Yes. The strikethrough is only visual; screen readers announce the label and whether the box is checked, which already says the task is done. Keep the text in place rather than swapping it for an icon, and Space toggles the box from the keyboard.