AI CSS Animations

AI Upscale Before and After

A before and after handle glides across a night skyline: the left side is soft and pixel gridded at 512 px, the right crisp at 4x. One animated @property drives the clip, the line and the knob.

Also known as: ai upscale animation, before after slider css, image enhance animation, upscaling comparison.

HTML

<div class="aia-upscale-compare" role="img" aria-label="Upscaled image compared with the original">
  <span class="aia-upscale-compare-city"><i style="--l: 0%; --w: 13%; --h: 46%; --o: 0.8"></i><i style="--l: 11%; --w: 9%; --h: 66%; --o: 0.55"></i><i style="--l: 22%; --w: 15%; --h: 52%; --o: 0.9"></i><i style="--l: 36%; --w: 8%; --h: 74%; --o: 0.6"></i><i style="--l: 45%; --w: 14%; --h: 40%; --o: 0.85"></i><i style="--l: 60%; --w: 10%; --h: 60%; --o: 0.7"></i><i style="--l: 71%; --w: 15%; --h: 48%; --o: 0.9"></i><i style="--l: 87%; --w: 13%; --h: 64%; --o: 0.6"></i></span>
  <span class="aia-upscale-compare-lo aia-upscale-compare-city"><i style="--l: 0%; --w: 13%; --h: 46%; --o: 0.8"></i><i style="--l: 11%; --w: 9%; --h: 66%; --o: 0.55"></i><i style="--l: 22%; --w: 15%; --h: 52%; --o: 0.9"></i><i style="--l: 36%; --w: 8%; --h: 74%; --o: 0.6"></i><i style="--l: 45%; --w: 14%; --h: 40%; --o: 0.85"></i><i style="--l: 60%; --w: 10%; --h: 60%; --o: 0.7"></i><i style="--l: 71%; --w: 15%; --h: 48%; --o: 0.9"></i><i style="--l: 87%; --w: 13%; --h: 64%; --o: 0.6"></i></span>
  <span class="aia-upscale-compare-tag">512 px</span>
  <span class="aia-upscale-compare-tag aia-upscale-compare-tag-hi">
    <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2C12.6 7.6 16.4 11.4 22 12C16.4 12.6 12.6 16.4 12 22C11.4 16.4 7.6 12.6 2 12C7.6 11.4 11.4 7.6 12 2Z"/></svg>Upscaled 4x
  </span>
  <span class="aia-upscale-compare-handle"><i><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 7l-4 5 4 5M15 7l4 5-4 5"/></svg></i></span>
</div>

CSS

@property --aia-upscale-compare-x {
  syntax: "<percentage>";
  inherits: true;
  initial-value: 30%;
}
.aia-upscale-compare {
  --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;
  position: relative;
  width: 18em;
  height: 10.5em;
  border-radius: 0.9em;
  overflow: hidden;
  box-shadow: 0 0 0 1px color-mix(in srgb, currentColor 12%, transparent), 0 1em 2em -1.1em rgba(0, 0, 0, 0.5);
  animation: aia-upscale-compare-slide 3.6s cubic-bezier(0.65, 0, 0.35, 1) infinite alternate;
}
.aia-upscale-compare-city {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 56% 24%, #fdf6e3 0 4.5%, transparent 5%),
    radial-gradient(circle at 56% 24%, color-mix(in srgb, var(--c) 50%, transparent), transparent 28%),
    linear-gradient(180deg, color-mix(in oklab, var(--c) 40%, #090718), color-mix(in oklab, var(--c) 65%, #2a1d50) 80%);
}
.aia-upscale-compare-city i {
  position: absolute;
  bottom: 0;
  left: var(--l);
  width: var(--w);
  height: var(--h);
  border-radius: 0.15em 0.15em 0 0;
  background:
    radial-gradient(circle, rgba(255, 214, 140, var(--o)) 0 0.07em, transparent 0.09em) 0.12em 0.3em / 0.42em 0.52em,
    linear-gradient(180deg, #241f46, #120f25);
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.06);
}
.aia-upscale-compare-city i:nth-child(odd) {
  z-index: 1;
  filter: brightness(0.82);
}
.aia-upscale-compare-lo {
  clip-path: inset(0 calc(100% - var(--aia-upscale-compare-x)) 0 0);
  filter: blur(0.2em) saturate(0.6) contrast(0.88);
}
.aia-upscale-compare-lo::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.3) 1px, transparent 1px) 0 0 / 0.6em 0.6em,
    linear-gradient(0deg, rgba(0, 0, 0, 0.3) 1px, transparent 1px) 0 0 / 0.6em 0.6em,
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 50%, transparent 50%) 0 0 / 1.2em 100%;
}
.aia-upscale-compare-tag {
  position: absolute;
  z-index: 2;
  top: 0.6em;
  left: 0.6em;
  display: flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.25em 0.55em;
  border-radius: 99em;
  font-size: 0.72em;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(0.4em);
  backdrop-filter: blur(0.4em);
}
.aia-upscale-compare-tag-hi {
  left: auto;
  right: 0.6em;
  color: #111;
  background: rgba(255, 255, 255, 0.92);
}
.aia-upscale-compare-tag svg {
  width: 1em;
  fill: var(--c);
}
.aia-upscale-compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--aia-upscale-compare-x);
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0.6em rgba(0, 0, 0, 0.4);
}
.aia-upscale-compare-handle i {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.7em;
  height: 1.7em;
  border-radius: 50%;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  background: #fff;
  box-shadow: 0 0.2em 0.6em rgba(0, 0, 0, 0.35), 0 0 0 0.2em color-mix(in srgb, var(--c) 45%, transparent);
}
.aia-upscale-compare-handle svg {
  width: 1em;
  fill: none;
  stroke: #222;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@keyframes aia-upscale-compare-slide {
  from { --aia-upscale-compare-x: 22%; }
  to { --aia-upscale-compare-x: 78%; }
}
@media (prefers-reduced-motion: reduce) {
  .aia-upscale-compare { animation: none; --aia-upscale-compare-x: 50%; }
}

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