AI CSS Animations

Spirit Level Loader

A glass vial of tinted liquid rocks gently while its air bubble slides to the high end, stretching as it moves and settling at the marks. The bubble lags the tilt a beat, which sells the liquid.

Also known as: bubble level animation, level tool loader, liquid bubble slider.

HTML

<div class="ldr-spirit-level" role="status" aria-label="Loading"><span></span></div>

CSS

.ldr-spirit-level {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  position: relative;
  box-sizing: border-box;
  width: calc(var(--s) * 2.2);
  height: calc(var(--s) * 0.46);
  border: calc(var(--s) / 22) solid color-mix(in srgb, var(--ldr-color, #3b82f6) 55%, transparent);
  border-radius: calc(var(--s) * 0.23);
  background: linear-gradient(color-mix(in srgb, var(--ldr-color, #3b82f6) 16%, transparent), color-mix(in srgb, var(--ldr-color, #3b82f6) 40%, transparent));
  box-shadow: 0 0 calc(var(--s) / 4) color-mix(in srgb, var(--ldr-color, #3b82f6) 25%, transparent);
  animation: ldr-spirit-level-tilt 2.6s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
.ldr-spirit-level::before {
  content: "";
  position: absolute;
  top: 10%;
  bottom: 10%;
  left: 50%;
  width: calc(var(--s) * 0.58);
  margin-left: calc(var(--s) * -0.29);
  border-left: calc(var(--s) / 26) solid color-mix(in srgb, var(--ldr-color, #3b82f6) 65%, transparent);
  border-right: calc(var(--s) / 26) solid color-mix(in srgb, var(--ldr-color, #3b82f6) 65%, transparent);
}
.ldr-spirit-level span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--s) * 0.5);
  height: calc(var(--s) * 0.24);
  margin: calc(var(--s) * -0.12) 0 0 calc(var(--s) * -0.25);
  border-radius: 50%;
  background: radial-gradient(ellipse at 38% 32%, color-mix(in srgb, var(--c) 8%, #fff), color-mix(in srgb, var(--c) 32%, #fff) 75%);
  box-shadow: inset 0 0 0 calc(var(--s) / 36) color-mix(in srgb, var(--ldr-color, #3b82f6) 75%, transparent);
  animation: ldr-spirit-level-slide 2.6s cubic-bezier(0.5, 0, 0.4, 1) 0.15s infinite alternate backwards;
}
@keyframes ldr-spirit-level-tilt {
  from { transform: rotate(4deg); }
  to   { transform: rotate(-4deg); }
}
@keyframes ldr-spirit-level-slide {
  from { transform: translateX(calc(var(--s) * -0.68)) scale(1, 1); }
  50%  { transform: translateX(0) scale(1.25, 0.84); }
  to   { transform: translateX(calc(var(--s) * 0.68)) scale(1, 1); }
}

@media (prefers-reduced-motion: reduce) {
  .ldr-spirit-level, .ldr-spirit-level *, .ldr-spirit-level::before, .ldr-spirit-level::after, .ldr-spirit-level *::before, .ldr-spirit-level *::after {
    animation-duration: 3s;
  }
}

Customizing this loader

  • Color: set --ldr-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --ldr-size. Every dimension in the snippet is derived from it. Currently previewing 64px.
  • Speed: change the duration on the animation shorthand. Delays on the children are relative, so they keep their rhythm.
  • Accessibility: the root carries role="status" and an aria-label so screen readers announce the wait. The reduced-motion rule at the end slows the animation for users who asked for less motion.

Similar loaders