Press to squash it flat and wide, let go and it springs back with real damped overshoot. The release uses a linear() easing sampled from a spring, with a cubic-bezier fallback for older browsers.
Also known as: spring animation button css, elastic click button, css linear() spring easing.
<button class="btn-spring-press" type="button">Boing</button>
.btn-spring-press {
--c: var(--btn-color, #3b82f6);
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: 0.75em 1.6em;
border: 0;
border-radius: 0.6em;
font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
padding: 0.85em 2em;
border-radius: 1em;
background: var(--c);
color: #fff;
box-shadow: 0 0.45em 1em -0.45em var(--c);
transition: transform 0.7s cubic-bezier(0.3, 1.8, 0.5, 1);
transition: transform 0.9s linear(0, 0.135, 0.451, 0.812, 1.113, 1.294, 1.346, 1.294, 1.182, 1.058, 0.956, 0.896, 0.881, 0.9, 0.94, 0.983, 1.017, 1.037, 1.041, 1.034, 1.02, 1.005, 0.993, 0.987, 0.986, 0.989, 0.993, 0.999, 1.002, 1.005, 1.005, 1.004, 1.002, 1);}
.btn-spring-press:active {
transform: scale(1.1, 0.8);
transition: transform 0.15s cubic-bezier(0.3, 0, 0.6, 1);
}
.btn-spring-press:focus-visible {
outline: 2px solid var(--c);
outline-offset: 0.2em;
}
@media (prefers-reduced-motion: reduce) {
.btn-spring-press, .btn-spring-press *, .btn-spring-press::before, .btn-spring-press::after, .btn-spring-press *::before, .btn-spring-press *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--btn-color on the element or a parent.
Currently previewing #3b82f6.--btn-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 18px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.