Hand-circled word
Hand drawn circle around a word in CSS and SVG. The loop redraws itself on hover or focus with a stroke-dashoffset animation.
The loop is an inline SVG path absolutely positioned over the word, a little larger than the word on every side. The path has pathLength="1", so stroke-dasharray: 1 and a dashoffset between 1 and 0 act like a percentage whatever the real path length. At rest the offset is 0 and the circle is fully drawn; on hover or focus the hcw-draw keyframes run the offset from 1 to 0 over 0.6 seconds, which draws it again from the start. vector-effect: non-scaling-stroke keeps the line width steady as the SVG stretches, and the SVG is aria-hidden with pointer-events: none.
snippet.html26 lines
<p class="hcw">
Built for the
<a class="hcw__word" href="#">stubborn
<svg viewBox="0 0 200 80" preserveAspectRatio="none" aria-hidden="true"><path pathLength="1" d="M60 10 C 20 8, 3 30, 8 48 C 14 70, 80 76, 130 70 C 185 64, 200 40, 178 20 C 160 4, 90 2, 40 12"/></svg>
</a>
few.
</p>
<style>
.hcw {
--hcw-ink: #111111;
--hcw-accent: #0b8f6a;
margin: 0;
font: 400 clamp(2rem, 7vw, 3.5rem)/1.3 ui-serif, "Iowan Old Style", Georgia, serif;
letter-spacing: -0.01em;
color: var(--hcw-ink);
text-align: center;
}
.hcw__word { position: relative; display: inline-block; margin: 0 0.15em; color: inherit; text-decoration: none; }
.hcw__word:focus-visible { outline: 2px solid var(--hcw-ink); outline-offset: 6px; border-radius: 4px; }
.hcw__word svg { position: absolute; left: -0.35em; top: -0.3em; width: calc(100% + 0.7em); height: calc(100% + 0.55em); overflow: visible; fill: none; stroke: var(--hcw-accent); stroke-width: 2.5; stroke-linecap: round; pointer-events: none; }
.hcw__word path { vector-effect: non-scaling-stroke; stroke-dasharray: 1; stroke-dashoffset: 0; }
.hcw__word:hover path, .hcw__word:focus-visible path { animation: hcw-draw 0.6s cubic-bezier(0.6, 0, 0.2, 1); }
@keyframes hcw-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .hcw__word:hover path, .hcw__word:focus-visible path { animation: none; } }
</style>