The magnifier grows a little, catches a glint on its lens and circles in a small loop as if it were scanning the page. The loop is an offset rotate that keeps the handle pointing the same way.
Also known as: magnifying glass animation css, search icon animation, magnifier hover effect.
<button class="hfx-search-icon-scan" aria-label="Search"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.9-3.9"/><path class="hfx-search-icon-scan-glint" d="M8 9a3.5 3.5 0 0 1 2.6-2.2"/></svg></button>
.hfx-search-icon-scan {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 3.5em;
height: 3.5em;
padding: 0;
border: 0;
border-radius: 50%;
cursor: pointer;
background: color-mix(in srgb, var(--c) 12%, transparent);
color: var(--c);
transition: background-color 0.25s ease;}
.hfx-search-icon-scan svg {
width: 1.6em;
height: 1.6em;
transition: scale 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hfx-search-icon-scan-glint {
opacity: 0;
transition: opacity 0.25s ease;
}
.hfx-search-icon-scan:is(:hover, :focus-visible) { background: color-mix(in srgb, var(--c) 20%, transparent); }
.hfx-search-icon-scan:is(:hover, :focus-visible) svg {
scale: 1.12;
animation: hfx-search-icon-scan-loop 1.4s linear infinite;
}
.hfx-search-icon-scan:is(:hover, :focus-visible) .hfx-search-icon-scan-glint { opacity: 1; }
/* a circle that passes through the rest position, so it starts without a jump */
@keyframes hfx-search-icon-scan-loop {
from { transform: translateX(-0.14em) rotate(0turn) translateX(0.14em) rotate(0turn); }
to { transform: translateX(-0.14em) rotate(1turn) translateX(0.14em) rotate(-1turn); }
}
@media (prefers-reduced-motion: reduce) {
.hfx-search-icon-scan, .hfx-search-icon-scan *, .hfx-search-icon-scan::before, .hfx-search-icon-scan::after, .hfx-search-icon-scan *::before, .hfx-search-icon-scan *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.