Text on a path
Text sliding along a curved path with animated startOffset
Techniques: textPath · startOffset · SMIL-animate · defs
<!--
============================================================
SVGarden — https://www.svgarden.dev
Author : Simon-Pierre Boucher
Contact: contact@spboucher.ai
File : snippets/text/text-on-path.html
Desc : Text sliding along a curved path with animated startOffset
============================================================
-->
<div class="sg-text-on-path" style="--sg-color:#7F77DD; --sg-size:300px;">
<svg viewBox="0 0 300 90" aria-hidden="true" focusable="false">
<defs>
<path id="sg-text-on-path-curve" d="M8 55 C 60 15, 110 85, 160 50 C 205 20, 250 70, 292 45" />
</defs>
<use href="#sg-text-on-path-curve" class="sg-text-on-path-rail" />
<text class="sg-text-on-path-text">
<textPath href="#sg-text-on-path-curve" startOffset="-60%">
surfing along the bézier wave…
<animate attributeName="startOffset" from="-60%" to="110%" dur="7s" repeatCount="indefinite" />
</textPath>
</text>
</svg>
</div>
<style>
.sg-text-on-path {
width: var(--sg-size);
}
.sg-text-on-path svg {
display: block;
width: 100%;
}
.sg-text-on-path-rail {
fill: none;
stroke: rgba(128, 128, 128, 0.35);
stroke-width: 1.5;
stroke-dasharray: 4 5;
}
.sg-text-on-path-text {
font-family: inherit;
font-size: 15px;
font-weight: 600;
fill: var(--sg-color);
}
</style>