Search to Back
A copy-paste animated icons component in pure HTML, CSS & vanilla JS. Zero dependencies, framework-agnostic, MIT-licensed.
Animated IconsHTMLCSSJavaScriptany framework
Copy into your project
HTML
<button class="nuda-icon-search" type="button" aria-label="Search" aria-pressed="false">
<svg class="nuda-icon-search__svg" viewBox="0 0 24 24" aria-hidden="true">
<circle class="nuda-icon-search__lens" cx="11" cy="11" r="6" />
<line class="nuda-icon-search__handle" x1="20" y1="20" x2="15.5" y2="15.5" />
<polyline class="nuda-icon-search__head" points="11 7 7 12 11 17" />
</svg>
</button>CSS
/* Search to Back
The lens fades out, the handle rotates flat into a shaft, and an arrow head
draws in via stroke-dashoffset. GPU-only: transform + opacity + dashoffset.
Customize: --icon-accent */
.nuda-icon-search {
--icon-accent: #e4ff54;
display: inline-flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
background: #09090b;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
color: #fafafa;
cursor: pointer;
transition: border-color 0.25s, color 0.25s;
}
.nuda-icon-search:hover,
.nuda-icon-search:focus-visible {
border-color: rgba(228, 255, 84, 0.4);
outline: none;
}
.nuda-icon-search:focus-visible {
box-shadow: 0 0 0 2px rgba(228, 255, 84, 0.5);
}
.nuda-icon-search[aria-pressed="true"] { color: var(--icon-accent); }
.nuda-icon-search__svg {
width: 24px;
height: 24px;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
fill: none;
}
.nuda-icon-search__lens {
transition: transform 0.4s cubic-bezier(0.4, 0.2, 0.2, 1), opacity 0.3s;
transform-origin: center;
will-change: transform, opacity;
}
.nuda-icon-search__handle {
transition: transform 0.4s cubic-bezier(0.4, 0.2, 0.2, 1), opacity 0.3s;
transform-origin: 11px 11px;
will-change: transform;
}
.nuda-icon-search__head {
stroke-dasharray: 18;
stroke-dashoffset: 18;
opacity: 0;
transition: stroke-dashoffset 0.4s, opacity 0.3s;
}
.nuda-icon-search[aria-pressed="true"] .nuda-icon-search__lens {
opacity: 0;
transform: scale(0.4);
}
.nuda-icon-search[aria-pressed="true"] .nuda-icon-search__handle {
transform: rotate(-45deg) scaleX(1.35);
}
.nuda-icon-search[aria-pressed="true"] .nuda-icon-search__head {
opacity: 1;
stroke-dashoffset: 0;
transition-delay: 0.12s;
}
@media (prefers-reduced-motion: reduce) {
.nuda-icon-search__lens,
.nuda-icon-search__handle,
.nuda-icon-search__head { transition: none; }
}JavaScript
/* Search to Back — vanilla JS
Flips aria-pressed and label; CSS morphs the glyph. */
(function () {
document.querySelectorAll(".nuda-icon-search").forEach(function (btn) {
btn.addEventListener("click", function () {
var back = btn.getAttribute("aria-pressed") !== "true";
btn.setAttribute("aria-pressed", String(back));
btn.setAttribute("aria-label", back ? "Back" : "Search");
});
});
})();How to use Search to Back
Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.
Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.