AI CSS Animations

Profile Follow Button

A profile chip with a Follow pill: press it and the pill turns into a quiet Following with a check, a ring draws around the avatar and the follower count rolls up by one. Pure CSS on a checkbox.

Also known as: follow buttons for website, follow profile card button, follow following toggle css, creator follow button.

HTML

<label class="btn-follow-profile">
  <input class="btn-follow-profile-input" type="checkbox" aria-label="Follow Lena Park">
  <span class="btn-follow-profile-card" aria-hidden="true">
    <span class="btn-follow-profile-avatar">LP</span>
    <span class="btn-follow-profile-meta">
      <span class="btn-follow-profile-name">Lena Park</span>
      <span class="btn-follow-profile-count"><span class="btn-follow-profile-roll"><span>12.4k</span><span>12.5k</span></span> followers</span>
    </span>
    <span class="btn-follow-profile-pill">
      <span>Follow</span>
      <span><svg viewBox="0 0 16 16"><path d="M3.5 8.5l3 3 6-7" /></svg>Following</span>
    </span>
  </span>
</label>

CSS

@property --btn-follow-profile-p {
  syntax: "<percentage>";
  inherits: true;
  initial-value: 0%;
}
.btn-follow-profile {
  --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-follow-profile-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.btn-follow-profile-card {
  --btn-follow-profile-p: 0%;
  display: flex;
  align-items: center;
  gap: 0.7em;
  padding: 0.55em 0.55em 0.55em 0.6em;
  border-radius: 1.6em;
  background: #fff;
  color: #111827;
  box-shadow: 0 0 0 1px rgb(17 24 39 / 0.08), 0 0.15em 0.4em rgb(17 24 39 / 0.06), 0 0.8em 1.6em -0.6em rgb(17 24 39 / 0.18);
  transition: --btn-follow-profile-p 0.7s cubic-bezier(0.65, 0, 0.35, 1), box-shadow 0.25s ease;
}
.btn-follow-profile-avatar {
  display: grid;
  place-items: center;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--c) 55%, #fff), var(--c)) padding-box,
    conic-gradient(var(--c) var(--btn-follow-profile-p), rgb(17 24 39 / 0.08) 0) border-box;
  border: 0.14em solid transparent;
  box-shadow: inset 0 0 0 0.12em #fff;
  color: #fff;
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.btn-follow-profile-meta {
  display: grid;
  gap: 0.15em;
  text-align: left;
}
.btn-follow-profile-name {
  font-size: 0.9em;
  line-height: 1.1;
}
.btn-follow-profile-count {
  display: flex;
  gap: 0.3em;
  font-size: 0.72em;
  font-weight: 500;
  line-height: 1.25;
  color: #6b7280;
}
.btn-follow-profile-roll {
  display: grid;
  height: 1.25em;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.btn-follow-profile-roll span {
  grid-area: 1 / 1;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s, opacity 0.3s ease 0.15s;
}
.btn-follow-profile-roll span:last-child {
  transform: translateY(110%);
  opacity: 0;
  color: var(--c);
}
.btn-follow-profile-pill {
  display: grid;
  margin-left: 0.4em;
  padding: 0.6em 1.1em;
  border-radius: 1.2em;
  background: var(--c);
  color: #fff;
  font-size: 0.85em;
  box-shadow: inset 0 0 0 1px transparent;
  transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-follow-profile-pill > span {
  grid-area: 1 / 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  transition: opacity 0.2s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-follow-profile-pill > span:last-child {
  opacity: 0;
  transform: scale(0.6);
}
.btn-follow-profile-pill svg {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 14;
  stroke-dashoffset: 14;
  transition: stroke-dashoffset 0.4s cubic-bezier(0.65, 0, 0.35, 1) 0.15s;
}
.btn-follow-profile:hover .btn-follow-profile-card {
  box-shadow: 0 0 0 1px rgb(17 24 39 / 0.12), 0 0.2em 0.5em rgb(17 24 39 / 0.08), 0 1em 2em -0.6em rgb(17 24 39 / 0.24);
}
.btn-follow-profile:hover .btn-follow-profile-pill { background-color: color-mix(in srgb, var(--c) 86%, #000); }
.btn-follow-profile:active .btn-follow-profile-pill { transform: scale(0.94); }
.btn-follow-profile-input:focus-visible ~ .btn-follow-profile-card {
  outline: 2px solid var(--c);
  outline-offset: 0.2em;
}
.btn-follow-profile-input:checked ~ .btn-follow-profile-card { --btn-follow-profile-p: 100%; }
.btn-follow-profile-input:checked ~ .btn-follow-profile-card .btn-follow-profile-pill {
  background-color: #fff;
  color: #374151;
  box-shadow: inset 0 0 0 1px rgb(17 24 39 / 0.16);
}
.btn-follow-profile-input:checked ~ .btn-follow-profile-card .btn-follow-profile-pill > span:first-child { opacity: 0; transform: scale(0.6); }
.btn-follow-profile-input:checked ~ .btn-follow-profile-card .btn-follow-profile-pill > span:last-child { opacity: 1; transform: none; }
.btn-follow-profile-input:checked ~ .btn-follow-profile-card .btn-follow-profile-pill svg { stroke-dashoffset: 0; color: var(--c); }
.btn-follow-profile-input:checked ~ .btn-follow-profile-card .btn-follow-profile-roll span:first-child { transform: translateY(-110%); opacity: 0; }
.btn-follow-profile-input:checked ~ .btn-follow-profile-card .btn-follow-profile-roll span:last-child { transform: none; opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .btn-follow-profile, .btn-follow-profile *, .btn-follow-profile *::before, .btn-follow-profile *::after { animation: none; transition-duration: 0.01s; }
}

@media (prefers-reduced-motion: reduce) {
  .btn-follow-profile, .btn-follow-profile *, .btn-follow-profile::before, .btn-follow-profile::after, .btn-follow-profile *::before, .btn-follow-profile *::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