AI CSS Animations

Pure CSS Custom Checkbox

A custom checkbox with no extra markup: appearance: none turns the input itself into the box, and a clip-path checkmark on ::before springs in. The real input keeps focus, keyboard and forms.

Also known as: custom checkbox css, css checkbox style, appearance none checkbox.

HTML

<label class="chk-custom-checkbox">
  <input type="checkbox">
  Keep me signed in
</label>

CSS

.chk-custom-checkbox {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chk-custom-checkbox input {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  display: grid;
  place-content: center;
  flex: none;
  width: 1.25em;
  height: 1.25em;
  margin: 0;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0.125em solid currentColor;
  border-radius: 0.25em;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease;
}
.chk-custom-checkbox input::before {
  content: "";
  width: 0.7em;
  height: 0.7em;
  background: var(--c);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  transform: scale(0);
  transform-origin: bottom left;
  transition: transform 0.12s ease-in;
}
.chk-custom-checkbox input:checked {
  border-color: var(--c);
}
.chk-custom-checkbox input:checked::before {
  transform: scale(1);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-custom-checkbox input:active {
  transform: scale(0.9);
}
.chk-custom-checkbox input:focus-visible {
  outline: 0.125em solid var(--c);
  outline-offset: 0.18em;
}

@media (prefers-reduced-motion: reduce) {
  .chk-custom-checkbox, .chk-custom-checkbox *, .chk-custom-checkbox::before, .chk-custom-checkbox::after, .chk-custom-checkbox *::before, .chk-custom-checkbox *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --chk-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --chk-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 24px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar checkboxes