AI CSS Animations

Marching Ants Text

Letter outlines crawl like a photo editor's selection, dark dashes marching over a pale track. Two SVG text copies: a solid faint stroke, and a dashed one whose offset moves one dash per loop.

Also known as: dashed outline text animation, animated dashed stroke, selection outline text.

Select Select

HTML

<svg class="txt-marching-ants-text" viewBox="0 0 400 110" role="img" aria-label="Select">
  <text x="200" y="84" text-anchor="middle" font-size="92">Select</text>
  <text x="200" y="84" text-anchor="middle" font-size="92">Select</text>
</svg>

CSS

.txt-marching-ants-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;
  width: 9em;
  height: auto;
  overflow: visible;}
.txt-marching-ants-text text {
  font-family: "Arial Black", "Helvetica Neue", Arial, sans-serif;
  font-weight: 900;
  fill: color-mix(in srgb, var(--c) 10%, transparent);
  stroke: color-mix(in srgb, var(--c) 35%, transparent);
  stroke-width: 2.6;
}
.txt-marching-ants-text text:nth-child(2) {
  fill: none;
  stroke: var(--c);
  stroke-dasharray: 7 6;
  animation: txt-marching-ants-text-march 0.55s linear infinite;
}
/* 13 = one dash plus one gap */
@keyframes txt-marching-ants-text-march {
  to { stroke-dashoffset: -13; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-marching-ants-text, .txt-marching-ants-text *, .txt-marching-ants-text::before, .txt-marching-ants-text::after, .txt-marching-ants-text *::before, .txt-marching-ants-text *::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