The two halves of a chain link icon pull apart and snap back together, over and over, like a tug test. Each half is its own path moving along the diagonal with a spring on the return.
Also known as: copy link icon animation, hyperlink icon hover css, link icon tug.
<button class="hfx-link-icon-chain" aria-label="Copy link"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path class="hfx-link-icon-chain-a" d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.8 1.7"/><path class="hfx-link-icon-chain-b" d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></svg></button>
.hfx-link-icon-chain {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 3.5em;
height: 3.5em;
padding: 0;
border: 0;
border-radius: 50%;
cursor: pointer;
border-radius: 0.85em;
background: color-mix(in srgb, var(--c) 12%, transparent);
color: var(--c);
transition: background-color 0.25s ease, color 0.25s ease;}
.hfx-link-icon-chain svg {
width: 1.55em;
height: 1.55em;
overflow: visible;
}
.hfx-link-icon-chain-a,
.hfx-link-icon-chain-b {
transform-box: view-box;
}
.hfx-link-icon-chain:is(:hover, :focus-visible) {
background: var(--c);
color: #fff;
}
.hfx-link-icon-chain:is(:hover, :focus-visible) .hfx-link-icon-chain-a {
animation: hfx-link-icon-chain-tug-a 1.3s infinite;
}
.hfx-link-icon-chain:is(:hover, :focus-visible) .hfx-link-icon-chain-b {
animation: hfx-link-icon-chain-tug-b 1.3s infinite;
}
@keyframes hfx-link-icon-chain-tug-a {
0%, 100% { transform: translate(0, 0); animation-timing-function: cubic-bezier(0.3, 0, 0.2, 1); }
35% { transform: translate(9%, -9%); animation-timing-function: cubic-bezier(0.6, 0, 0.9, 0.4); }
52% { transform: translate(-2%, 2%); animation-timing-function: ease-out; }
64% { transform: translate(0, 0); }
}
@keyframes hfx-link-icon-chain-tug-b {
0%, 100% { transform: translate(0, 0); animation-timing-function: cubic-bezier(0.3, 0, 0.2, 1); }
35% { transform: translate(-9%, 9%); animation-timing-function: cubic-bezier(0.6, 0, 0.9, 0.4); }
52% { transform: translate(2%, -2%); animation-timing-function: ease-out; }
64% { transform: translate(0, 0); }
}
@media (prefers-reduced-motion: reduce) {
.hfx-link-icon-chain, .hfx-link-icon-chain *, .hfx-link-icon-chain::before, .hfx-link-icon-chain::after, .hfx-link-icon-chain *::before, .hfx-link-icon-chain *::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.