A pen boxes in one word, one side at a time, each line a little crooked and running past the corner. Four empty elements that scale from their starting end, each delayed by its index.
Also known as: box around word animation, rough notation box, sketch border text.
<div class="txt-hand-drawn-box-text">Try it <span class="txt-hand-drawn-box-text-word">free<i style="--i: 0" aria-hidden="true"></i><i style="--i: 1" aria-hidden="true"></i><i style="--i: 2" aria-hidden="true"></i><i style="--i: 3" aria-hidden="true"></i></span></div>
.txt-hand-drawn-box-text {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
white-space: nowrap;}
.txt-hand-drawn-box-text-word {
position: relative;
display: inline-block;
margin-left: 0.15em;
padding: 0 0.24em;
color: var(--c);
}
.txt-hand-drawn-box-text-word i {
position: absolute;
border-radius: 0.04em;
background: var(--c);
animation: txt-hand-drawn-box-text-x 0.24s cubic-bezier(0.5, 0, 0.4, 1) forwards;
animation-delay: calc(0.3s + var(--i) * 0.2s);
}
/* top, left to right */
.txt-hand-drawn-box-text-word i:nth-child(1) {
--r: -1.2deg;
top: 0.02em; left: -0.06em; right: -0.14em;
height: 0.07em;
transform: rotate(var(--r)) scaleX(0);
transform-origin: 0 50%;
}
/* right, top to bottom */
.txt-hand-drawn-box-text-word i:nth-child(2) {
--r: 2deg;
top: -0.1em; bottom: -0.02em; right: 0.02em;
width: 0.07em;
transform: rotate(var(--r)) scaleY(0);
transform-origin: 50% 0;
animation-name: txt-hand-drawn-box-text-y;
}
/* bottom, right to left */
.txt-hand-drawn-box-text-word i:nth-child(3) {
--r: 0.8deg;
bottom: 0.04em; left: -0.12em; right: 0.04em;
height: 0.07em;
transform: rotate(var(--r)) scaleX(0);
transform-origin: 100% 50%;
}
/* left, bottom to top */
.txt-hand-drawn-box-text-word i:nth-child(4) {
--r: -2.2deg;
top: -0.02em; bottom: -0.12em; left: 0.04em;
width: 0.07em;
transform: rotate(var(--r)) scaleY(0);
transform-origin: 50% 100%;
animation-name: txt-hand-drawn-box-text-y;
}
@keyframes txt-hand-drawn-box-text-x {
to { transform: rotate(var(--r)) scaleX(1); }
}
@keyframes txt-hand-drawn-box-text-y {
to { transform: rotate(var(--r)) scaleY(1); }
}
@media (prefers-reduced-motion: reduce) {
.txt-hand-drawn-box-text, .txt-hand-drawn-box-text *, .txt-hand-drawn-box-text::before, .txt-hand-drawn-box-text::after, .txt-hand-drawn-box-text *::before, .txt-hand-drawn-box-text *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.