Custom Checkbox

An animated checkbox with a checkmark that draws itself in when checked.

Tailwind CSS
<style>
  .tw-checkbox .tick { stroke-dasharray: 26; stroke-dashoffset: 26; transition: stroke-dashoffset 0.25s ease 0.08s; }
  .tw-checkbox input:checked + span { background-color: #4f46e5; border-color: #4f46e5; }
  .tw-checkbox input:checked + span .tick { stroke-dashoffset: 0; }
</style>
<label class="tw-checkbox inline-flex cursor-pointer items-center gap-3 select-none">
  <input type="checkbox" checked class="sr-only" />
  <span class="grid h-6 w-6 place-items-center rounded-md border-2 border-slate-300 bg-white transition-colors duration-200">
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4 text-white"><path class="tick" d="M5 13l4 4L19 7"/></svg>
  </span>
  <span class="text-sm text-slate-700 dark:text-slate-200">Email me product updates</span>
</label>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Emerald round

The round emerald checkbox suits friendly signup flows and consent screens.

Tailwind CSS

Large

The large size gives touch users a bigger target on mobile settings screens.

Tailwind CSS

Unchecked opt-in

Start unchecked for optional opt-ins so consent is a deliberate choice.

Tailwind CSS

About this custom checkbox

The default browser checkbox looks different in every browser and clashes with a custom design system. This tailwind custom checkbox replaces it with a clean rounded box where the checkmark draws itself in with a short stroke animation the moment it is checked.

The trick is a tiny bit of CSS next to the Tailwind classes. The check path gets a stroke-dasharray matching its length and starts fully offset, so it is invisible. When the hidden input is checked, the adjacent span selector sets stroke-dashoffset to 0 and the check visibly draws. The box itself flips from a neutral border to indigo with a color transition, and the whole label is clickable since the input sits inside it.

Use this anywhere a form needs brand-consistent inputs: signup forms, settings pages, filter panels, cookie consent. Keep the sr-only input in the DOM rather than removing it, because that preserves keyboard focus and screen reader support for free.

The native checkbox is a design-system intruder: it renders differently in every browser and ignores your brand entirely. On a polished settings page or checkout form, that one gray square undermines everything around it. A custom checkbox keeps the native input's behavior while wearing your design, so forms feel crafted instead of assembled.

The check path gets a stroke-dasharray matching its length and starts fully offset, rendering it invisible. When the hidden input is checked, an adjacent-sibling selector sets stroke-dashoffset to 0 and the check visibly draws itself over 0.25 seconds. The box flips from a neutral border to indigo with a color transition, and the whole label is clickable because the input lives inside it.

Wrap the box and its label text in a single label element so clicking anywhere on the row toggles it; tiny 16px boxes are rage-click territory on mobile. For checkbox groups, indent child options under their parent and wire the parent to the indeterminate state. In dark mode, the unchecked border needs more opacity than you think; a 20% white border disappears, 40% reads clearly. Test the checked state at 200% zoom; the check path must stay centered when everything scales.

The trap is styling the checked state beautifully while dropping the focus ring. Keyboard users tab to the checkbox and see nothing change, because the custom box never shows focus-visible. Add a visible focus ring on the box tied to the input's focus state. If keyboard users cannot tell where they are, the custom control is a downgrade from the native one.

Where to use it

  • ✓ Newsletter signup forms
  • ✓ Settings and preferences pages
  • ✓ Product filter sidebars
  • ✓ Terms and consent checkboxes

Customization tips

Swap indigo-600 for your brand color in the style block and the checked classes. Change rounded-md to rounded-full for a circular check. For a softer motion, lengthen the 0.25s draw duration or remove the 0.08s delay.

Design notes

When to use

A custom checkbox earns its place when the native control clashes with a designed interface, like a polished settings page or a checkout form. The checkmark that draws itself in gives a tiny moment of satisfaction that makes the control feel crafted. Keep it for binary choices that take effect immediately or on submit, exactly where users expect a checkbox.

What to avoid

Do not restyle a checkbox so heavily it no longer reads as a checkbox, novelty that confuses is worse than a plain control. Avoid using a checkbox for mutually exclusive options, that is a radio button's job. And do not shrink the tap target below 24 pixels to match a delicate design, missed taps will follow.

Accessibility

Keep the real input in the DOM and visually hidden rather than replacing it with a div, so keyboard and screen reader support come free. The drawn checkmark is decorative, and the label must be programmatically associated with the input.

Frequently asked questions

How do I style a checkbox with Tailwind? I heard peer-checked works.

peer-checked styles siblings of the input, but the animated check draw needs a stroke-dashoffset change on a nested SVG path. A small style block with input:checked + span selectors is more reliable here. Keep Tailwind for layout and colors.

Is a custom checkbox still accessible?

Yes, as long as the real input stays in the DOM. The sr-only class hides it visually but keeps it focusable and readable by screen readers. Always pair it with a visible text label.

Why does my checkmark look clipped?

The stroke-width is 3 on a 24-unit viewBox inside a 16px icon. If you resize the icon, keep stroke-linecap round and enough padding in the viewBox so the round caps are not cut off.

How do I style a disabled checkbox in Tailwind?

Add disabled:opacity-50 and disabled:cursor-not-allowed to the visual box so it clearly reads as inactive. Keep the native input disabled too, not just the styling, so keyboard users cannot reach it. Use the real disabled attribute rather than pointer-events none, which leaves the input focusable and confusing.

How do I draw the checkmark with pure CSS?

Use a small box with only right and bottom borders, then rotate it 45 degrees to form the tick shape. This element builds the checkmark from borders instead of an SVG, which keeps it crisp at any size. Size the tick relative to the box with em units so it scales if the checkbox grows.

How do I build a select all master checkbox?

Wire the master checkbox to toggle every child checkbox in its group, and set its indeterminate property to true when only some children are checked. The indeterminate state needs JavaScript, CSS alone cannot express a partial selection. Announce the state change with aria-checked mixed for screen reader users.

Customize it with our tools