One of my favorite things to see on the web are curved paths with text on them... how to create irregular text paths and laying out text on them.
This post will discuss how to create text on a path using SVG, the advantages and disadvantages of using SVG for this purpose, and how to animate the text along the path.
## Creating Text on a Path
Creating text on a path in SVG is straightforward. You define a path using the `` element and then use the `` and `` elements to place the text along that path.
In the `` element we use a cubic Bezier curve to create a curved path. The `d` attribute defines the shape of the path using the `Q` command. The `fill` attribute is set to transparent to prevent color in the space generated by the curve and the `stroke` attribute is used to define the color of the path.
In the text element we define `font-size`, `fill`, and `font-family` attributes to style the text. The `textPath` element is used to bind the text to the path defined earlier. The `href` attribute points to the path's ID, and the `startOffset` attribute is used to control where the text starts along the path; we can move the text around the path as needed.
```xml
```
## Adding Animation
Adding animation is pretty straightforward. We add the `animate` element as a child of `textPath` and set the `attributeName` to `startOffset` (we want to animate the location of the text along the path).
The `from` and `to` attributes define the range of the animation, and the `dur` attribute specifies the duration of the animation.
The `repeatCount` attribute is set to `indefinite` to make the animation loop continuously.
```xml
```
## Advantages and Disadvantages
While I love these solutions, there are advantages and disadvantages to using SVG for text on a path.
### Advantages
* **Scalability**: SVG is vector-based, so it scales well without losing quality. This is particularly useful for responsive designs
* **Accessibility**: SVG text can be made accessible to screen readers, which is important for web accessibility
### Disadvantages
* **Complexity**: SVG can be more complex to work with than traditional HTML/CSS text. In particular, creating complex paths can be challenging
* **Lack of authoring tools**: While there are some tools for creating SVG paths, they are not as widely used or supported as traditional HTML/CSS authoring tools
## A full static example
This is a more complex example that includes a complex path and long text elements.