The button shakes side to side a few times, each swing smaller than the last, then comes to rest. A one-shot keyframe on hover: the same motion a login form uses to say no.
Also known as: hvr-wobble-horizontal, shake button on hover, head shake hover css.
<button class="hfx-wobble-horizontal">Try again</button>
.hfx-wobble-horizontal {
--c: var(--hfx-color, #3b82f6);
display: inline-flex;
align-items: center;
gap: 0.5em;
padding: 0.7em 1.6em;
border-radius: 0.5em;
font: 600 var(--hfx-size, 16px) system-ui, sans-serif;
cursor: pointer;
border: 0;
background: color-mix(in srgb, var(--c) 14%, transparent);
color: var(--c);
transition: background-color 0.25s ease;}
.hfx-wobble-horizontal:is(:hover, :focus-visible) {
background: color-mix(in srgb, var(--c) 22%, transparent);
animation: hfx-wobble-horizontal-shake 0.9s ease-in-out;
}
@keyframes hfx-wobble-horizontal-shake {
16% { transform: translateX(0.55em); }
33% { transform: translateX(-0.4em); }
50% { transform: translateX(0.26em); }
66% { transform: translateX(-0.14em); }
83% { transform: translateX(0.05em); }
}
@media (prefers-reduced-motion: reduce) {
.hfx-wobble-horizontal, .hfx-wobble-horizontal *, .hfx-wobble-horizontal::before, .hfx-wobble-horizontal::after, .hfx-wobble-horizontal *::before, .hfx-wobble-horizontal *::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.