AI CSS Animations

Background Task Toast

A stacked toast springs up to say tests are running in the background, fills its progress line, flips to Tests passed with a check, then slides away. The toast behind it is one pseudo-element.

Also known as: background task notification, toast notification animation, task complete toast.

Running in backgroundTests passed pnpm test --watch128 passed in 24s View

HTML

<div class="aia-background-task-toast" role="status" aria-label="Background task">
  <div class="aia-background-task-toast-card">
    <span class="aia-background-task-toast-icon" aria-hidden="true">
      <i class="aia-background-task-toast-spin"></i>
      <svg class="aia-background-task-toast-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5.5 12.5 4 4 9-9.5"/></svg>
    </span>
    <span class="aia-background-task-toast-text">
      <span class="aia-background-task-toast-swap"><b>Running in background</b><b>Tests passed</b></span>
      <span class="aia-background-task-toast-swap"><span>pnpm test --watch</span><span>128 passed in 24s</span></span>
    </span>
    <a class="aia-background-task-toast-link" href="#">View</a>
    <span class="aia-background-task-toast-bar" aria-hidden="true"></span>
  </div>
</div>

CSS

.aia-background-task-toast {
  --c: var(--aia-color, #7c5cff);
  font-size: var(--aia-size, 16px);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.4;
  --d: 7s;
  --ok: color-mix(in srgb, #16a34a 78%, currentColor);
  position: relative;
  width: 20em;
  padding-top: 0.7em;
  animation: aia-background-task-toast-move var(--d) cubic-bezier(0.34, 1.4, 0.64, 1) infinite;
}
/* the older toast peeking out behind */
.aia-background-task-toast::before {
  content: "";
  position: absolute;
  left: 0.9em;
  right: 0.9em;
  top: 0;
  height: 2em;
  border-radius: 0.8em;
  clip-path: inset(0 0 1.28em 0);
  background: color-mix(in srgb, currentColor 4%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 9%, transparent);
}
.aia-background-task-toast-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75em;
  overflow: hidden;
  padding: 0.8em 0.95em;
  border-radius: 0.85em;
  background: color-mix(in srgb, currentColor 3%, transparent);
  -webkit-backdrop-filter: blur(1em);
  backdrop-filter: blur(1em);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 12%, transparent), 0 1em 2em -1em rgb(0 0 0 / 0.35);
}
.aia-background-task-toast-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.9em;
  height: 1.9em;
  border-radius: 50%;
  animation: aia-background-task-toast-well var(--d) ease infinite;
}
.aia-background-task-toast-icon > * {
  grid-area: 1 / 1;
}
.aia-background-task-toast-spin {
  width: 1em;
  height: 1em;
  box-sizing: border-box;
  border-radius: 50%;
  border: 0.14em solid color-mix(in srgb, var(--c) 25%, transparent);
  border-top-color: var(--c);
  animation:
    aia-background-task-toast-spin 0.8s linear infinite,
    aia-background-task-toast-a var(--d) ease infinite;
}
.aia-background-task-toast-check {
  width: 1.1em;
  height: 1.1em;
  color: var(--ok);
  stroke-width: 2.8;
  stroke-dasharray: 22;
  animation: aia-background-task-toast-tick var(--d) cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
}
.aia-background-task-toast-text {
  display: grid;
  gap: 0.1em;
  min-width: 0;
}
.aia-background-task-toast-swap {
  display: grid;
}
.aia-background-task-toast-swap > * {
  grid-area: 1 / 1;
  white-space: nowrap;
}
.aia-background-task-toast-swap b { font-size: 0.9em; }
.aia-background-task-toast-swap span {
  color: color-mix(in srgb, currentColor 55%, transparent);
  font: 0.75em ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
.aia-background-task-toast-swap > :first-child { animation: aia-background-task-toast-a var(--d) ease infinite; }
.aia-background-task-toast-swap > :last-child { animation: aia-background-task-toast-b var(--d) ease infinite; }
.aia-background-task-toast-link {
  padding: 0.35em 0.65em;
  border-radius: 0.45em;
  background: color-mix(in srgb, currentColor 7%, transparent);
  color: inherit;
  font-size: 0.78em;
  font-weight: 600;
  text-decoration: none;
}
.aia-background-task-toast-link:focus-visible {
  outline: 2px solid var(--c);
  outline-offset: 2px;
}
.aia-background-task-toast-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0.14em;
  background: var(--c);
  transform-origin: left;
  animation: aia-background-task-toast-bar var(--d) cubic-bezier(0.3, 0, 0.3, 1) infinite;
}
@keyframes aia-background-task-toast-move {
  0% { opacity: 0; transform: translateY(1.6em) scale(0.96); }
  8%, 86% { opacity: 1; transform: none; }
  94%, 100% { opacity: 0; transform: translateY(1.6em) scale(0.96); animation-timing-function: ease-in; }
}
@keyframes aia-background-task-toast-well {
  0%, 54%, 100% { background: color-mix(in srgb, var(--c) 12%, transparent); }
  58%, 96% { background: color-mix(in srgb, #16a34a 14%, transparent); }
}
@keyframes aia-background-task-toast-a {
  0%, 54%, 100% { opacity: 1; transform: none; }
  58%, 99% { opacity: 0; transform: translateY(-0.5em); }
}
@keyframes aia-background-task-toast-b {
  0%, 54% { opacity: 0; transform: translateY(0.5em); }
  58%, 100% { opacity: 1; transform: none; }
}
@keyframes aia-background-task-toast-tick {
  0%, 54% { opacity: 0; stroke-dashoffset: 22; transform: scale(0.5); }
  64%, 100% { opacity: 1; stroke-dashoffset: 0; transform: scale(1); }
}
@keyframes aia-background-task-toast-bar {
  0%, 8% { transform: scaleX(0); opacity: 1; }
  20% { transform: scaleX(0.3); }
  34% { transform: scaleX(0.46); }
  54% { transform: scaleX(1); background: var(--c); opacity: 1; }
  60%, 100% { transform: scaleX(1); background: var(--ok); opacity: 0; }
}
@keyframes aia-background-task-toast-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .aia-background-task-toast,
  .aia-background-task-toast *,
  .aia-background-task-toast *::before {
    animation-play-state: paused;
    animation-delay: calc(var(--d) * -0.75);
  }
}

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

Customizing this snippet

  • Color: set --aia-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --aia-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 ai animations