AI CSS Animations

Stroke Draw Text

The outline of each letter draws itself, then the fill fades in. This one is SVG text with an animated stroke dash, which is the only way to 'draw' letters without JavaScript.

Also known as: handwriting animation, svg text draw, outline drawing text.

Drawn

HTML

<svg class="txt-stroke-draw" viewBox="0 0 320 80" role="img" aria-label="Drawn">
  <text x="50%" y="62%" text-anchor="middle">Drawn</text>
</svg>

CSS

.txt-stroke-draw {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  width: 10em;
  overflow: visible;}
.txt-stroke-draw text {
  font: inherit;
  font-size: 64px;
  fill: var(--c);
  fill-opacity: 0;
  stroke: var(--c);
  stroke-width: 1.5;
  stroke-dasharray: 400;
  stroke-dashoffset: 400;
  animation: txt-stroke-draw-line 2s ease-out forwards, txt-stroke-draw-fill 0.6s ease-out 1.6s forwards;
}
@keyframes txt-stroke-draw-line {
  to { stroke-dashoffset: 0; }
}
@keyframes txt-stroke-draw-fill {
  to { fill-opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-stroke-draw, .txt-stroke-draw *, .txt-stroke-draw::before, .txt-stroke-draw::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar text animations