A ring springs out from the button's edge and hangs a small gap away, while the button gives a touch. It is an outline with a transitioned outline-offset, so the same rule doubles as the focus style.
Also known as: focus ring button, outline offset hover, ring on hover.
<button class="btn-offset-ring">Save changes</button>
.btn-offset-ring {
--c: var(--btn-color, #3b82f6);
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5em;
font: 600 var(--btn-size, 18px)/1.2 system-ui, sans-serif;
cursor: pointer;
padding: 0.8em 1.7em;
border: 0;
border-radius: 0.6em;
background: var(--c);
color: #fff;
outline: 2px solid transparent;
outline-offset: -2px;
transition:
outline-offset 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
outline-color 0.2s ease,
transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);}
.btn-offset-ring:is(:hover, :focus-visible) {
outline-color: var(--c);
outline-offset: 0.25em;
transform: scale(0.97);
}
@media (prefers-reduced-motion: reduce) {
.btn-offset-ring, .btn-offset-ring *, .btn-offset-ring::before, .btn-offset-ring::after, .btn-offset-ring *::before, .btn-offset-ring *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}The same effect using Tailwind utility classes. No custom CSS or config needed.
<button class="rounded-lg bg-blue-500 px-6 py-3 font-semibold text-white outline outline-2 -outline-offset-2 outline-transparent transition-all duration-300 hover:scale-[.97] hover:outline-offset-4 hover:outline-blue-500"> Save changes </button>
--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.