AI CSS Animations

Bookmark Button

A 'Save' button with a ribbon tucked into its top edge. Click and the ribbon drops down past the bottom like a real bookmark, swings once and settles. The notch is a clip-path polygon.

Also known as: save button animation css, bookmark toggle button, ribbon bookmark button.

HTML

<label class="btn-bookmark">
  <input class="btn-bookmark-input" type="checkbox" aria-label="Save">
  <span class="btn-bookmark-face" aria-hidden="true">
    <span class="btn-bookmark-text"><span>Save</span><span>Saved</span></span>
    <span class="btn-bookmark-ribbon"></span>
  </span>
</label>

CSS

.btn-bookmark {
  --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-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.btn-bookmark-face {
  position: relative;
  display: flex;
  align-items: center;
  width: 7.4em;
  height: 2.8em;
  box-sizing: border-box;
  padding-left: 1.3em;
  border-radius: 0.6em;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  color: var(--c);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent);
  transition: transform 0.2s ease;
}
.btn-bookmark-text { display: grid; }
.btn-bookmark-text span {
  grid-area: 1 / 1;
  transition: opacity 0.25s ease 0.1s;
}
.btn-bookmark-text span:last-child { opacity: 0; }
.btn-bookmark-ribbon {
  position: absolute;
  top: -0.15em;
  right: 1.1em;
  width: 1em;
  height: 2.5em;
  background: color-mix(in srgb, var(--c) 35%, transparent);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  transform: scaleY(0.4);
  transform-origin: 50% 0;
  transition: transform 0.3s ease, background-color 0.3s ease;
}
.btn-bookmark:active .btn-bookmark-face { transform: scale(0.96); }
.btn-bookmark-input:focus-visible ~ .btn-bookmark-face {
  outline: 2px solid var(--c);
  outline-offset: 0.2em;
}
.btn-bookmark-input:checked ~ .btn-bookmark-face .btn-bookmark-text span:first-child { opacity: 0; }
.btn-bookmark-input:checked ~ .btn-bookmark-face .btn-bookmark-text span:last-child { opacity: 1; }
.btn-bookmark-input:checked ~ .btn-bookmark-face .btn-bookmark-ribbon {
  background-color: var(--c);
  transform: scaleY(1);
  animation: btn-bookmark-drop 0.9s cubic-bezier(0.3, 0.7, 0.4, 1);
}
@keyframes btn-bookmark-drop {
  0% { transform: scaleY(0.4) rotate(0deg); }
  35% { transform: scaleY(1.12) rotate(0deg); }
  50% { transform: scaleY(0.96) rotate(7deg); }
  68% { transform: scaleY(1.02) rotate(-4deg); }
  84% { transform: scaleY(1) rotate(1.5deg); }
  100% { transform: scaleY(1) rotate(0deg); }
}

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