AI CSS Animations

Liquid Glass Magnifier Lens

A drop of liquid glass drifts over small print and a dot grid, magnifying the middle and squeezing the rim like a real lens. Chromium only for the bend; other browsers show a clear glass bead.

Also known as: css magnifying glass effect, liquid glass lens css, glass lens refraction css.

HTML

<div class="gls-liquid-glass-magnifier">
  <p class="gls-liquid-glass-magnifier-print" aria-hidden="true">Small print gets bigger under a drop of liquid glass. Refraction in plain CSS and SVG.</p>
  <span class="gls-liquid-glass-magnifier-path" aria-hidden="true"><span class="gls-liquid-glass-magnifier-lens"></span></span>
  <svg class="gls-liquid-glass-magnifier-svg" width="0" height="0" aria-hidden="true" focusable="false">
    <filter id="gls-liquid-glass-magnifier-lens" x="0" y="0" width="1" height="1" color-interpolation-filters="sRGB">
      <feImage href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1' preserveAspectRatio='none'%3E%3ClinearGradient id='x'%3E%3Cstop offset='0' stop-color='%23800000'/%3E%3Cstop offset='0.16' stop-color='%23cc0000'/%3E%3Cstop offset='0.5' stop-color='%23800000'/%3E%3Cstop offset='0.84' stop-color='%23330000'/%3E%3Cstop offset='1' stop-color='%23800000'/%3E%3C/linearGradient%3E%3ClinearGradient id='y' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23008000'/%3E%3Cstop offset='0.16' stop-color='%2300cc00'/%3E%3Cstop offset='0.5' stop-color='%23008000'/%3E%3Cstop offset='0.84' stop-color='%23003300'/%3E%3Cstop offset='1' stop-color='%23008000'/%3E%3C/linearGradient%3E%3Crect width='1' height='1' fill='url(%23x)'/%3E%3Crect width='1' height='1' fill='url(%23y)' style='mix-blend-mode:screen'/%3E%3C/svg%3E" preserveAspectRatio="none" result="map"/>
      <feDisplacementMap in="SourceGraphic" in2="map" scale="28" xChannelSelector="R" yChannelSelector="G"/>
    </filter>
  </svg>
</div>

CSS

.gls-liquid-glass-magnifier {
  --c: var(--gls-color, #3b82f6);
  font-size: var(--gls-size, 16px);
  position: relative;
  display: grid;
  place-items: center;
  width: 22em;
  height: 12em;
  border-radius: 1.25em;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(circle, rgb(255 255 255 / 0.3) 0.08em, transparent 0.1em) 0 0 / 0.7em 0.7em, linear-gradient(135deg, color-mix(in srgb, var(--c) 55%, #0f172a), color-mix(in srgb, var(--c) 35%, #4c1d95));
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.3;
}
.gls-liquid-glass-magnifier-print {
  width: 17em;
  margin: 0;
  font-size: 1em;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  background: linear-gradient(90deg, #fff, color-mix(in srgb, var(--c) 40%, #fff), #fde68a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.gls-liquid-glass-magnifier-path {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5.4em;
  height: 5.4em;
  margin: -2.7em 0 0 -2.7em;
  animation: gls-liquid-glass-magnifier-x 5.2s ease-in-out infinite alternate;
}
.gls-liquid-glass-magnifier-lens {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, rgb(255 255 255 / 0.35), transparent 30%);
  -webkit-backdrop-filter: saturate(1.4) brightness(1.08);
  backdrop-filter: url(#gls-liquid-glass-magnifier-lens) saturate(1.4) brightness(1.08);
  box-shadow:
    inset 0.08em 0.1em 0.06em -0.04em rgb(255 255 255 / 0.75),
    inset -0.08em -0.1em 0.06em -0.04em rgb(255 255 255 / 0.4),
    inset 0 0 0 1px rgb(255 255 255 / 0.22),
    inset 0.25em 0 0.4em -0.3em rgb(34 211 238 / 0.6),
    inset -0.25em 0 0.4em -0.3em rgb(244 114 182 / 0.6),
    0 0.8em 1.5em -0.6em rgb(0 0 0 / 0.6);
  animation: gls-liquid-glass-magnifier-y 3.4s ease-in-out infinite alternate;
}
.gls-liquid-glass-magnifier-svg {
  position: absolute;
  width: 0;
  height: 0;
}
@keyframes gls-liquid-glass-magnifier-x {
  from { transform: translateX(-7em); }
  to { transform: translateX(7em); }
}
@keyframes gls-liquid-glass-magnifier-y {
  from { transform: translateY(-2.4em); }
  to { transform: translateY(2.4em); }
}

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

Customizing this snippet

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