AI CSS Animations

Record Button

A recorder button: click and the round dot morphs into a stop square, a halo pulses and a timer starts counting. The timer is a registered @property integer shown with counter(), zero padded.

Also known as: record button css, record stop button animation, voice recorder button.

HTML

<label class="btn-record">
  <input class="btn-record-input" type="checkbox" aria-label="Record">
  <span class="btn-record-face" aria-hidden="true">
    <span class="btn-record-dot"></span>
    <span class="btn-record-text"><span>Record</span><span class="btn-record-time"></span></span>
  </span>
</label>

CSS

@property --btn-record-s {
  syntax: "<integer>";
  inherits: false;
  initial-value: 0;
}
.btn-record {
  --c: var(--btn-color, #3b82f6);
  position: relative;
  display: inline-grid;
  place-items: center;
  font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-record-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.btn-record-face {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.45em 1.3em 0.45em 0.45em;
  border-radius: 2em;
  background-color: color-mix(in srgb, var(--c) 10%, transparent);
  color: var(--c);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 28%, transparent);
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 0.3s ease;
}
.btn-record-dot {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  width: 2em;
  height: 2em;
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.14em color-mix(in srgb, var(--c) 45%, transparent);
}
.btn-record-dot::before,
.btn-record-dot::after {
  content: "";
  grid-area: 1 / 1;
  width: 1.2em;
  height: 1.2em;
  border-radius: 50%;
  background: var(--c);
  transition: transform 0.4s cubic-bezier(0.3, 1.5, 0.5, 1), border-radius 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.btn-record-dot::after {
  z-index: -1;
  opacity: 0;
  transition: none;
}
.btn-record-text {
  display: grid;
  font-variant-numeric: tabular-nums;
}
.btn-record-text > span {
  grid-area: 1 / 1;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.btn-record-time {
  opacity: 0;
  transform: translateY(0.6em);
  counter-reset: btn-record-s var(--btn-record-s);
}
.btn-record-time::before { content: "00:" counter(btn-record-s, decimal-leading-zero); }
.btn-record:active .btn-record-face { transform: scale(0.95); }
.btn-record-input:focus-visible ~ .btn-record-face {
  outline: 2px solid var(--c);
  outline-offset: 0.2em;
}
.btn-record-input:checked ~ .btn-record-face { box-shadow: inset 0 0 0 2px var(--c); }
.btn-record-input:checked ~ .btn-record-face .btn-record-dot::before {
  border-radius: 0.2em;
  transform: scale(0.62);
}
.btn-record-input:checked ~ .btn-record-face .btn-record-dot::after {
  animation: btn-record-halo 1.4s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
}
.btn-record-input:checked ~ .btn-record-face .btn-record-text > span:first-child {
  opacity: 0;
  transform: translateY(-0.6em);
}
.btn-record-input:checked ~ .btn-record-face .btn-record-time {
  opacity: 1;
  transform: none;
  animation: btn-record-count 60s steps(60) infinite;
}
@keyframes btn-record-halo {
  0% { opacity: 0.55; transform: scale(1); }
  100% { opacity: 0; transform: scale(2.4); }
}
@keyframes btn-record-count {
  from { --btn-record-s: 0; }
  to { --btn-record-s: 60; }
}

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

Customizing this snippet

  • Color: set --btn-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --btn-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 18px.
  • 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 buttons