A pushpin that lies tipped over until checked, then swings upright, lifts and presses into the page with a small squash and a shadow under its point. Good for pinning notes, chats or rows to the top.
Also known as: pin to top checkbox, pin icon animation css, pushpin toggle css.
<label class="chk-pin-to-top">
<input type="checkbox">
<span class="chk-pin-to-top-icon" aria-hidden="true">
<i class="chk-pin-to-top-shadow"></i>
<svg class="chk-pin-to-top-pin" viewBox="0 0 24 24"><path class="chk-pin-to-top-head" d="M8.5 3h7l-1.2 5.6 3.2 3.2v1.7h-11v-1.7l3.2-3.2z"/><path d="M12 13.5V21"/></svg>
</span>
<span class="chk-pin-to-top-text">Pin to top</span>
</label>.chk-pin-to-top {
--c: var(--chk-color, #3b82f6);
font-size: var(--chk-size, 24px);
position: relative;
display: inline-flex;
align-items: center;
gap: 0.6em;
line-height: 1.3;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.chk-pin-to-top input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-pin-to-top-icon {
position: relative;
display: grid;
place-items: center;
width: 1.6em;
height: 1.6em;
border-radius: 0.35em;
}
.chk-pin-to-top-pin {
position: relative;
width: 1.45em;
height: 1.45em;
fill: none;
stroke: color-mix(in srgb, currentColor 70%, transparent);
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
transform-origin: 50% 88%;
transform: rotate(40deg) translateY(0) scaleY(1);
transition: transform 0.35s cubic-bezier(0.34, 1.3, 0.64, 1), stroke 0.25s ease;
}
.chk-pin-to-top-head {
fill: transparent;
transition: fill 0.25s ease;
}
.chk-pin-to-top-shadow {
position: absolute;
left: 50%;
bottom: 0.02em;
width: 0.5em;
height: 0.14em;
margin-left: -0.25em;
border-radius: 50%;
background: color-mix(in srgb, currentColor 25%, transparent);
transform: scale(0);
transition: transform 0.2s ease;
}
.chk-pin-to-top-text {
transition: color 0.25s ease;
}
.chk-pin-to-top:hover .chk-pin-to-top-pin {
stroke: var(--c);
}
.chk-pin-to-top input:checked + .chk-pin-to-top-icon .chk-pin-to-top-pin {
stroke: var(--c);
transform: rotate(0deg) translateY(0) scaleY(1);
animation: chk-pin-to-top-press 0.55s ease-out;
}
.chk-pin-to-top input:checked + .chk-pin-to-top-icon .chk-pin-to-top-head {
fill: var(--c);
}
.chk-pin-to-top input:checked + .chk-pin-to-top-icon .chk-pin-to-top-shadow {
transform: scale(1);
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s;
}
.chk-pin-to-top input:checked ~ .chk-pin-to-top-text {
color: var(--c);
}
.chk-pin-to-top input:focus-visible + .chk-pin-to-top-icon {
outline: 0.12em solid var(--c);
outline-offset: 0.18em;
}
@keyframes chk-pin-to-top-press {
0% { transform: rotate(40deg) translateY(0) scaleY(1); }
40% { transform: rotate(-6deg) translateY(-0.28em) scaleY(1); }
65% { transform: rotate(0deg) translateY(0.05em) scaleY(0.9); }
100% { transform: rotate(0deg) translateY(0) scaleY(1); }
}
@media (prefers-reduced-motion: reduce) {
.chk-pin-to-top, .chk-pin-to-top *, .chk-pin-to-top::before, .chk-pin-to-top::after, .chk-pin-to-top *::before, .chk-pin-to-top *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--chk-color on the element or a parent.
Currently previewing #3b82f6.--chk-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 24px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.