AI CSS Animations

Bookmark Icon Button

A square icon button: press it and the outlined bookmark slips down out of view while a filled one drops in from the top, squashes on landing and settles. Two SVG icons in a clipped window.

Also known as: bookmark button, bookmark icon animation css, save for later button, bookmark toggle css.

HTML

<label class="btn-bookmark-drop">
  <input class="btn-bookmark-drop-input" type="checkbox" aria-label="Bookmark">
  <span class="btn-bookmark-drop-face" aria-hidden="true">
    <span class="btn-bookmark-drop-window">
      <svg class="btn-bookmark-drop-outline" viewBox="0 0 24 24"><path d="M6.5 4.5h11v15.5l-5.5-4-5.5 4z" /></svg>
      <svg class="btn-bookmark-drop-filled" viewBox="0 0 24 24"><path d="M6.5 4.5h11v15.5l-5.5-4-5.5 4z" /></svg>
    </span>
  </span>
</label>

CSS

.btn-bookmark-drop {
  --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-bookmark-drop-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.btn-bookmark-drop-face {
  display: grid;
  place-items: center;
  width: 2.8em;
  height: 2.8em;
  border-radius: 0.8em;
  background: color-mix(in srgb, var(--c) 10%, transparent);
  color: var(--c);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 22%, transparent);
  transition: background-color 0.3s ease, box-shadow 0.3s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.btn-bookmark-drop-window {
  position: relative;
  display: block;
  width: 1.5em;
  height: 1.5em;
  overflow: hidden;
}
.btn-bookmark-drop-window svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
}
.btn-bookmark-drop-outline {
  fill: none;
  transition: transform 0.35s cubic-bezier(0.55, 0, 0.75, 0.2), opacity 0.35s ease;
}
.btn-bookmark-drop-filled {
  fill: currentColor;
  transform: translateY(-110%);
  transform-origin: 50% 100%;
}
.btn-bookmark-drop:hover .btn-bookmark-drop-face { background-color: color-mix(in srgb, var(--c) 16%, transparent); }
.btn-bookmark-drop:active .btn-bookmark-drop-face { transform: scale(0.92); }
.btn-bookmark-drop-input:focus-visible ~ .btn-bookmark-drop-face {
  outline: 2px solid var(--c);
  outline-offset: 0.2em;
}
.btn-bookmark-drop-input:checked ~ .btn-bookmark-drop-face {
  background-color: var(--c);
  color: #fff;
  box-shadow: inset 0 0 0 1px var(--c), 0 0.5em 1.1em -0.5em var(--c);
}
.btn-bookmark-drop-input:checked ~ .btn-bookmark-drop-face .btn-bookmark-drop-outline {
  transform: translateY(110%);
  opacity: 0;
}
.btn-bookmark-drop-input:checked ~ .btn-bookmark-drop-face .btn-bookmark-drop-filled {
  transform: none;
  animation: btn-bookmark-drop-land 0.7s 0.1s both;
}
@keyframes btn-bookmark-drop-land {
  0%   { transform: translateY(-110%); animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.4); }
  45%  { transform: translateY(0) scale(1.12, 0.82); animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1); }
  70%  { transform: translateY(-6%) scale(0.95, 1.06); }
  100% { transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .btn-bookmark-drop, .btn-bookmark-drop *, .btn-bookmark-drop *::before, .btn-bookmark-drop *::after { animation: none; transition-duration: 0.01s; }
}

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