AI CSS Animations

Candy Stripe Button

A glossy candy pill with diagonal stripes rolling through it like a barber pole or a busy progress bar. The stripes are one square tile of gradient on a wider layer that slides by exactly one tile.

Also known as: barber pole button css, animated striped button, candy cane button.

HTML

<button class="btn-candy-stripe" type="button">Sweet deal</button>

CSS

.btn-candy-stripe {
  --c: var(--btn-color, #3b82f6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.6em;
  border: 0;
  border-radius: 0.6em;
  font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 0.85em 2em;
  border-radius: 2em;
  background: var(--c);
  color: #fff;
  text-shadow: 0 0.06em 0.15em color-mix(in srgb, var(--c) 55%, #000);
  box-shadow:
    inset 0 -0.22em 0 color-mix(in srgb, var(--c) 72%, #000),
    0 0.35em 0.8em -0.25em color-mix(in srgb, var(--c) 60%, transparent);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);}
.btn-candy-stripe::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -1.6em;
  z-index: -1;
  width: calc(100% + 1.6em);
  background: linear-gradient(-45deg, rgba(255, 255, 255, 0.3) 25%, transparent 25% 50%, rgba(255, 255, 255, 0.3) 50% 75%, transparent 75%) 0 0 / 1.6em 1.6em;
  animation: btn-candy-stripe-roll 0.9s linear infinite;
}
.btn-candy-stripe::after {
  content: "";
  position: absolute;
  top: 0.18em;
  right: 1em;
  left: 1em;
  z-index: -1;
  height: 42%;
  border-radius: 2em;
  background: linear-gradient(rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));
}
.btn-candy-stripe:active { transform: scale(0.95); }
@keyframes btn-candy-stripe-roll {
  to { transform: translateX(1.6em); }
}

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