AI CSS Animations

Emoji Smiley Checkbox

A face drawn with three spans that goes from a flat mouth to a wide grin when checked, fills with the accent, blinks and wiggles. No emoji font needed, so it renders the same on every OS.

Also known as: emoji checkbox css, smiley face checkbox, happy face toggle css.

HTML

<label class="chk-emoji-smile">
  <input type="checkbox">
  <span class="chk-emoji-smile-face" aria-hidden="true">
    <i class="chk-emoji-smile-eye"></i>
    <i class="chk-emoji-smile-eye"></i>
    <i class="chk-emoji-smile-mouth"></i>
  </span>
  <span class="chk-emoji-smile-text">This was helpful</span>
</label>

CSS

.chk-emoji-smile {
  --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;
}
.chk-emoji-smile input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.chk-emoji-smile-face {
  position: relative;
  flex: none;
  width: 1.7em;
  height: 1.7em;
  border: 0.12em solid color-mix(in srgb, currentColor 38%, transparent);
  border-radius: 50%;
  color: color-mix(in srgb, currentColor 75%, transparent);
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}
.chk-emoji-smile-eye {
  position: absolute;
  top: 30%;
  left: 27%;
  width: 0.19em;
  height: 0.24em;
  border-radius: 50%;
  background: currentColor;
}
.chk-emoji-smile-eye + .chk-emoji-smile-eye {
  left: auto;
  right: 27%;
}
.chk-emoji-smile-mouth {
  position: absolute;
  left: 50%;
  top: 60%;
  width: 0.66em;
  height: 0.12em;
  margin-left: -0.33em;
  border-radius: 0.06em;
  background: currentColor;
  transition: height 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), border-radius 0.35s ease, top 0.35s ease;
}
.chk-emoji-smile-text {
  transition: color 0.25s ease;
}
.chk-emoji-smile:hover .chk-emoji-smile-face {
  border-color: var(--c);
}
.chk-emoji-smile input:checked + .chk-emoji-smile-face {
  background: var(--c);
  border-color: var(--c);
  color: #fff;
  animation: chk-emoji-smile-wiggle 0.6s ease-out;
}
.chk-emoji-smile input:checked + .chk-emoji-smile-face .chk-emoji-smile-eye {
  animation: chk-emoji-smile-blink 0.35s ease-in-out 0.25s;
}
.chk-emoji-smile input:checked + .chk-emoji-smile-face .chk-emoji-smile-mouth {
  top: 52%;
  height: 0.34em;
  border-radius: 0.05em 0.05em 0.33em 0.33em;
}
.chk-emoji-smile input:checked ~ .chk-emoji-smile-text {
  color: var(--c);
}
.chk-emoji-smile input:focus-visible + .chk-emoji-smile-face {
  outline: 0.12em solid var(--c);
  outline-offset: 0.18em;
}
@keyframes chk-emoji-smile-wiggle {
  0% { transform: rotate(0deg) scale(1); }
  30% { transform: rotate(-14deg) scale(1.12); }
  60% { transform: rotate(9deg) scale(1.04); }
  100% { transform: rotate(0deg) scale(1); }
}
@keyframes chk-emoji-smile-blink {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.15); }
}

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