A settings cog that turns a half rotation on hover and turns back when you leave. A transition on transform, so the return trip is as smooth as the outbound.
Also known as: rotate icon hover, settings cog hover.
<button class="hfx-icon-spin" aria-label="Settings"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.6a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg> </button>
.hfx-icon-spin {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
display: grid;
place-items: center;
width: 2.75em;
height: 2.75em;
border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
border-radius: 0.6em;
background: transparent;
color: var(--c);
cursor: pointer;
transition: border-color 0.2s ease;
}
.hfx-icon-spin svg {
width: 1.4em;
height: 1.4em;
transition: transform 0.5s ease;
}
.hfx-icon-spin:hover { border-color: var(--c); }
.hfx-icon-spin:hover svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
.hfx-icon-spin, .hfx-icon-spin *, .hfx-icon-spin::before, .hfx-icon-spin::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.