AI CSS Animations

Notification Bell Checkbox

A bell that rings when you turn notifications on: it swings with a decaying wobble, the clapper lags a beat behind and two sound arcs fade out at its sides. Fills with the accent while checked.

Also known as: notify me checkbox, bell ring animation css, subscribe bell toggle.

HTML

<label class="chk-bell-notify">
  <input type="checkbox">
  <span class="chk-bell-notify-icon" aria-hidden="true">
    <i class="chk-bell-notify-wave"></i>
    <svg class="chk-bell-notify-bell" viewBox="0 0 24 24"><path d="M6.2 16.8V11a5.8 5.8 0 0 1 11.6 0v5.8l1.6 1.9H4.6zM12 5.2V3.4"/><path class="chk-bell-notify-clapper" d="M9.8 20.6a2.2 2.2 0 0 0 4.4 0z"/></svg>
    <i class="chk-bell-notify-wave"></i>
  </span>
  <span class="chk-bell-notify-text">Notify me</span>
</label>

CSS

.chk-bell-notify {
  --c: var(--chk-color, #3b82f6);
  font-size: var(--chk-size, 24px);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  line-height: 1.3;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  gap: 0.75em;}
.chk-bell-notify input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-bell-notify-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  border-radius: 0.35em;
}
.chk-bell-notify-bell {
  width: 1.4em;
  height: 1.4em;
  fill: transparent;
  stroke: color-mix(in srgb, currentColor 70%, transparent);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-origin: 50% 12%;
  transition: fill 0.25s ease, stroke 0.25s ease;
}
.chk-bell-notify-clapper {
  transform-box: fill-box;
  transform-origin: 50% 0;
}
.chk-bell-notify-wave {
  --dir: -1;
  position: absolute;
  top: 18%;
  left: -0.3em;
  width: 0.45em;
  height: 0.9em;
  border: 0.11em solid transparent;
  border-left-color: var(--c);
  border-radius: 50%;
  opacity: 0;
}
.chk-bell-notify-bell + .chk-bell-notify-wave {
  --dir: 1;
  left: auto;
  right: -0.3em;
  border-left-color: transparent;
  border-right-color: var(--c);
}
.chk-bell-notify-text {
  transition: color 0.25s ease;
}
.chk-bell-notify:hover .chk-bell-notify-bell {
  stroke: var(--c);
}
.chk-bell-notify input:checked + .chk-bell-notify-icon .chk-bell-notify-bell {
  fill: var(--c);
  stroke: var(--c);
  animation: chk-bell-notify-ring 0.9s ease-in-out;
}
.chk-bell-notify input:checked + .chk-bell-notify-icon .chk-bell-notify-clapper {
  animation: chk-bell-notify-clap 0.9s ease-in-out 0.06s;
}
.chk-bell-notify input:checked + .chk-bell-notify-icon .chk-bell-notify-wave {
  animation: chk-bell-notify-wave 0.8s ease-out 0.1s;
}
.chk-bell-notify input:checked ~ .chk-bell-notify-text {
  color: var(--c);
}
.chk-bell-notify input:focus-visible + .chk-bell-notify-icon {
  outline: 0.12em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-bell-notify-ring {
  0%, 100% { transform: rotate(0deg); }
  12% { transform: rotate(22deg); }
  28% { transform: rotate(-18deg); }
  44% { transform: rotate(12deg); }
  60% { transform: rotate(-8deg); }
  76% { transform: rotate(4deg); }
}
@keyframes chk-bell-notify-clap {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-35%); }
  40% { transform: translateX(30%); }
  60% { transform: translateX(-18%); }
  80% { transform: translateX(8%); }
}
@keyframes chk-bell-notify-wave {
  0% { opacity: 0; transform: translateX(0) scale(0.6); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateX(calc(var(--dir) * 0.3em)) scale(1.1); }
}

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