AI CSS Animations

Animated Stripes Background

Wide diagonal stripes in two shades of your accent slide sideways without end, like a barber pole laid flat. One gradient tile, moved by exactly its own width each loop.

Also known as: css animated striped background, moving stripes background, barber pole stripes css.

HTML

<div class="bgx-diagonal-stripes" aria-hidden="true"></div>

CSS

.bgx-diagonal-stripes {
  --c: var(--bgx-color, #3b82f6);
  font-size: var(--bgx-size, 16px);
  position: absolute;
  inset: 0;
  overflow: hidden;
  --tile: 3em;
  background: var(--c);
}
.bgx-diagonal-stripes::before {
  content: "";
  position: absolute;
  inset: 0 0 0 calc(var(--tile) * -1);
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 78%, #fff) 25%, transparent 25% 50%, color-mix(in srgb, var(--c) 78%, #fff) 50% 75%, transparent 75%) 0 0 / var(--tile) var(--tile);
  animation: bgx-diagonal-stripes-slide 1.8s linear infinite;
}
.bgx-diagonal-stripes::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 90% at 50% 40%, transparent 40%, color-mix(in srgb, var(--c) 45%, #000));
  opacity: 0.55;
}
@keyframes bgx-diagonal-stripes-slide {
  to { transform: translateX(var(--tile)); }
}

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

Customizing this snippet

  • Color: set --bgx-color on the element or a parent. Currently previewing #3b82f6.
  • Pattern scale: set --bgx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 animated backgrounds