AI CSS Animations

Liquid Fill Checkbox

Checking fills the box with liquid: a slowly turning rounded square rises from below, so its surface sloshes as it climbs, then the tick draws in white. Unchecking drains it back out.

Also known as: water fill checkbox, wave fill checkbox css.

HTML

<label class="chk-liquid-fill-checkbox">
  <input type="checkbox">
  <span class="chk-liquid-fill-checkbox-box">
    <span class="chk-liquid-fill-checkbox-liquid"></span>
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.5 12.5l4 4L18.5 7.5"/></svg>
  </span>
  Back up to cloud
</label>

CSS

.chk-liquid-fill-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-liquid-fill-checkbox input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-liquid-fill-checkbox-box {
  position: relative;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  flex: none;
  width: 1.4em;
  height: 1.4em;
  overflow: hidden;
  border: 0.125em solid color-mix(in srgb, currentColor 38%, transparent);
  border-radius: 0.35em;
  transition: border-color 0.3s ease 0.2s;
}
.chk-liquid-fill-checkbox-liquid {
  position: absolute;
  left: 50%;
  top: 0;
  width: 3.2em;
  height: 3.2em;
  margin-left: -1.6em;
  transform: translateY(1.4em);
  transition: transform 0.5s cubic-bezier(0.55, 0, 0.8, 0.5) 0.1s;
}
.chk-liquid-fill-checkbox-liquid::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 39%;
  background: var(--c);
  animation: chk-liquid-fill-checkbox-turn 2.4s linear infinite;
}
.chk-liquid-fill-checkbox-box svg {
  display: block;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  position: relative;
  width: 0.9em;
  height: 0.9em;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
  transition: stroke-dashoffset 0.12s ease-in;
}
.chk-liquid-fill-checkbox input:checked + .chk-liquid-fill-checkbox-box {
  border-color: var(--c);
  transition-delay: 0s;
}
.chk-liquid-fill-checkbox input:checked + .chk-liquid-fill-checkbox-box .chk-liquid-fill-checkbox-liquid {
  transform: translateY(-0.3em);
  transition: transform 0.8s cubic-bezier(0.25, 0.6, 0.3, 1);
}
.chk-liquid-fill-checkbox input:checked + .chk-liquid-fill-checkbox-box svg {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s ease-out 0.5s;
}
.chk-liquid-fill-checkbox input:focus-visible + .chk-liquid-fill-checkbox-box {
  outline: 0.125em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-liquid-fill-checkbox-turn {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .chk-liquid-fill-checkbox, .chk-liquid-fill-checkbox *, .chk-liquid-fill-checkbox::before, .chk-liquid-fill-checkbox::after, .chk-liquid-fill-checkbox *::before, .chk-liquid-fill-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