Placing Text on a Circle or Curve with React and SVG textPath
If you point an SVG <textPath> at a <path> that draws a circle or curve, the text lines up along that line. Don't draw the circle with <circle>. Draw it as a <path> made of two joined arcs. If you place the top half of the text on a clockwise circle and the bottom half on a counterclockwise circle, neither half ends up upside down.
I built three components: CircleText, which places text on the top and bottom of a circle; RingText, which spreads text evenly around the full circle; and CurvedText, which changes the bend of a curve with a slider. I measured the character positions in Chromium.
The test environment was Ubuntu 24.04, Node.js 22.23.4, and Chromium 153. I used react and react-dom 19.3.1, @types/react 19.3.0, typescript 7.0.2, esbuild 0.28.2, and Playwright 1.63.0. I type-checked the .tsx files with tsc, transpiled them with esbuild, and ran them in a development build. Japanese text was rendered with Noto Sans CJK JP. I did not test Firefox, Safari, mobile browsers, production builds, screen reader announcements, vertical writing, right-to-left scripts, or the method and spacing attributes of <textPath>.

- 1. Draw the circle as a path made of two arcs
- 2. Put top text on a clockwise circle and bottom text on a counterclockwise circle
- 3. Use dominantBaseline="central" to center text on the circle
- 4. Spread text evenly around the full circle
- 5. Follow a curve and change the bend with a slider
- 6. Text longer than the curve loses its end characters
- 7. Results of testing the path and side attributes in Chromium
Draw the circle as a path made of two arcs
First, I tried referencing a <circle> with href. I wrote the SVG directly without React, and in Chromium 153 every character stayed at (0, 0) and did not line up along the circle. When I drew the same circle as a <path> and referenced that, the characters lined up along it.
The description of the href attribute in the SVG 2 specification says that basic shapes such as <circle> can be referenced. Even so, in this version of Chromium, I needed a <path>.
The d attribute for the circle comes from the following function. It starts at the left end (the 9 o'clock position), draws an arc to the right end on the opposite side, and then draws an arc back to the left end.
// paths.ts
// Builds the d attribute for a circle drawn as two arcs starting from the left end (the 9 o'clock position)
// clockwise: goes clockwise (passes the top half first) / counterclockwise: goes counterclockwise (passes the bottom half first)
export function circlePath(
cx: number,
cy: number,
r: number,
direction: 'clockwise' | 'counterclockwise',
): string {
const sweep = direction === 'clockwise' ? 1 : 0;
return [
`M ${cx - r} ${cy}`,
`A ${r} ${r} 0 1 ${sweep} ${cx + r} ${cy}`,
`A ${r} ${r} 0 1 ${sweep} ${cx - r} ${cy}`,
].join(' ');
}
// Quadratic Bézier curve joining the left and right ends (at height y). The middle shifts up by bend (down if negative)
export function curvePath(width: number, y: number, bend: number): string {
return `M 0 ${y} Q ${width / 2} ${y - bend * 2} ${width} ${y}`;
}
When the fifth value of A (sweep) is 1, the arc goes clockwise. When it is 0, the arc goes counterclockwise. In the clockwise circle, the path goes from the left end over the top to the right end, so the text starts on the top half. In the counterclockwise circle, the path goes from the left end under the bottom to the right end. curvePath is used for the curve in a later section.
Put top text on a clockwise circle and bottom text on a counterclockwise circle
Characters in a <textPath> are placed in the direction the line runs. According to MDN's description of the side attribute, with the default value left, characters are placed on the left side of the direction of travel. The bottom half of a clockwise circle runs from right to left, so text placed there would be upside down. For that reason, I place the bottom text on a counterclockwise circle.
// CircleText.tsx
import { useId } from 'react';
import { circlePath } from './paths';
type Props = {
top: string; // Text placed clockwise along the top half
bottom?: string; // Text placed left to right along the bottom half
size?: number; // Width and height of the SVG
radius?: number; // Radius of the circle the text is placed on
fontSize?: number;
};
export function CircleText({ top, bottom, size = 240, radius = 90, fontSize = 20 }: Props) {
const id = useId();
const c = size / 2;
return (
<svg viewBox={`0 0 ${size} ${size}`} width={size} height={size} role="img" aria-label={[top, bottom].filter(Boolean).join(' ')}>
<defs>
<path id={`${id}-cw`} d={circlePath(c, c, radius, 'clockwise')} />
<path id={`${id}-ccw`} d={circlePath(c, c, radius, 'counterclockwise')} />
</defs>
<circle cx={c} cy={c} r={radius} fill="none" stroke="#00c8e8" strokeDasharray="4 4" />
<text fontSize={fontSize} dominantBaseline="central" fill="#1f2a30">
<textPath href={`#${id}-cw`} startOffset="25%" textAnchor="middle">
{top}
</textPath>
</text>
{bottom && (
<text fontSize={fontSize} dominantBaseline="central" fill="#1f2a30">
<textPath href={`#${id}-ccw`} startOffset="25%" textAnchor="middle">
{bottom}
</textPath>
</text>
)}
</svg>
);
}
Both circles start at the left end, so the 25% point of the circumference is straight up on the clockwise circle and straight down on the counterclockwise circle. When you write startOffset as a percentage, it is a fraction of the total length of the line. Setting text-anchor to middle puts the center of the string at that position.
I measured the angle of each character's center on a circle with radius 90. Angles are measured with the right side as 0° and the bottom as +90°. For the top text, "Sore nara neko no te de" (Japanese, roughly "Then, with a cat's paw"), the first character was at −134.6° and the last at −45.4°, so the text was split on either side of straight up (−90°). For the bottom text, "NEKO NOTE BLOG", the first character was at 138.7° and the last at 41.1°. The horizontal positions increased from left to right, and the text read from left to right.
The id of the referenced <path> is created with useId. If I hard-coded the id, two copies of the component on the same page would produce duplicate ids. When I placed two circles side by side, their hrefs were #_r_1_-cw and #_r_2_-cw, and the text in the second circle lined up along its own circle. In React 19.3.1, useId returned values such as _r_0_, and I could use them directly in href by adding # in front.
Attribute names are written in camelCase, as noted in React's list of SVG components. dominant-baseline becomes dominantBaseline, and text-anchor becomes textAnchor. You specify the reference with href. MDN's description of href says that xlink:href, which was in SVG specifications before SVG 2, has been replaced by href and is deprecated (in React, you write it as xlinkHref).
Use dominantBaseline="central" to center text on the circle
If you do not set dominantBaseline, the baseline (the line that Latin letters sit on) is placed on the circle. The top text then appears outside the circle and the bottom text appears inside it, so the two halves do not line up.

I measured the distance from each character's center to the center of the circle, using a circle with radius 90. Without dominantBaseline, the top text was 98.5 and the bottom text was 81.5. With dominantBaseline="central", both were 90.0, which means the center of each character sits on the circle.
Spread text evenly around the full circle
If you set textLength to a length and set lengthAdjust to spacing, the gaps between characters widen so the string reaches that length. However, if you set textLength to the circumference itself, the last character runs into the first.
I placed the 19 characters of "Sore nara neko no te de · NEKO NOTE ·" on a circle with radius 90 (circumference 565.5) and set textLength to the circumference. The gap between the first and second characters was 16.1. The gap between the last and first characters was −1.1, so they slightly overlapped. I divided the added space (565.5 − 279.5 = 286.0) by the 18 gaps between characters, which gives 15.9. That is almost the same as the gap between the first and second characters. No extra gap was added after the last character.
So I set the length to the circumference minus one gap. I measure the length of the unspaced string with an invisible <text>.
// RingText.tsx
import { useId, useLayoutEffect, useRef, useState } from 'react';
import { circlePath } from './paths';
type Props = {
text: string;
size?: number;
radius?: number;
fontSize?: number;
};
// Spreads the text evenly around the full circle
export function RingText({ text, size = 240, radius = 90, fontSize = 18 }: Props) {
const id = useId();
const measureRef = useRef<SVGTextElement>(null);
const [natural, setNatural] = useState(0); // Length of the text before spacing is widened
const c = size / 2;
const circumference = 2 * Math.PI * radius;
const count = Array.from(text).length;
// Measure the length before widening, using an invisible text
useLayoutEffect(() => {
setNatural(measureRef.current!.getComputedTextLength());
}, [text, fontSize]);
// Make every gap between characters equal (count gaps, including the gap between the last and first characters)
const gap = (circumference - natural) / count;
return (
<svg viewBox={`0 0 ${size} ${size}`} width={size} height={size} role="img" aria-label={text}>
<defs>
<path id={id} d={circlePath(c, c, radius, 'clockwise')} />
</defs>
<text ref={measureRef} fontSize={fontSize} visibility="hidden">
{text}
</text>
{natural > 0 && (
<text fontSize={fontSize} dominantBaseline="central" fill="#1f2a30">
<textPath href={`#${id}`} textLength={circumference - gap} lengthAdjust="spacing">
{text}
</textPath>
</text>
)}
</svg>
);
}
The unspaced length of the 19 characters was 279.5. The gap is (565.5 − 279.5) ÷ 19 = 15.1, so textLength is 565.5 − 15.1 = 550.4. In my measurements, the gaps between each character and the next were 14.9 to 15.3, and the gap between the last and first characters was 14.0. Only the last gap was about 1 unit narrower. This is almost the same difference as the −1.1 I got when I set textLength to the full circumference. Visually, the characters were almost evenly spaced.
When the text is placed around the full circle, the characters on the bottom half are upside down (the NOTE in the right image). If you want the bottom half to be readable, split the string into top and bottom parts, as CircleText does in the previous section.
Follow a curve and change the bend with a slider
For the curve, I used a quadratic Bézier curve (Q). curvePath puts the left and right ends at the same height and places the control point above the middle. If you raise the control point by twice bend, the middle of the curve rises by bend. With both ends at y = 100, the y coordinate of the middle point was 60.0 for a bend of 40 and 140.0 for a bend of −40.
// CurvedText.tsx
import { useId, useLayoutEffect, useRef, useState } from 'react';
import { curvePath } from './paths';
type Props = {
text: string;
width?: number;
fontSize?: number;
initialBend?: number;
};
export function CurvedText({ text, width = 320, fontSize = 20, initialBend = 40 }: Props) {
const id = useId();
const [bend, setBend] = useState(initialBend);
const pathRef = useRef<SVGPathElement>(null);
const textRef = useRef<SVGTextPathElement>(null);
const [overflow, setOverflow] = useState(false);
const height = 170;
const d = curvePath(width, 100, bend);
// Show a warning when the text is longer than the curve
useLayoutEffect(() => {
const pathLength = pathRef.current!.getTotalLength();
const textLength = textRef.current!.getComputedTextLength();
setOverflow(textLength > pathLength);
}, [d, text, fontSize]);
return (
<div>
<svg viewBox={`0 0 ${width} ${height}`} width={width} height={height} role="img" aria-label={text}>
<path ref={pathRef} id={id} d={d} fill="none" stroke="#00c8e8" strokeDasharray="4 4" />
<text fontSize={fontSize} fill="#1f2a30">
<textPath ref={textRef} href={`#${id}`} startOffset="50%" textAnchor="middle">
{text}
</textPath>
</text>
</svg>
<label>
曲がり具合:{bend}
<input type="range" min={-60} max={60} value={bend} onChange={(e) => setBend(Number(e.target.value))} />
</label>
{overflow && <p role="alert">文字が曲線に収まりきっていません</p>}
</div>
);
}
Because d is computed from bend on every render, moving the slider moves the curve and the text together. With startOffset="50%" and textAnchor="middle", the center of the string sits at the center of the curve.

These are the results when I changed the slider value on a curve 320 wide.
| Bend | Curve length | y coordinate of the middle character's center (larger is lower) |
|---|---|---|
| 60 | 347.9 | 31.7 |
| 40 | 332.9 | 51.7 |
| 0 | 320.0 | 91.5 |
| −40 | 332.9 | 131.3 |
| −60 | 347.9 | 151.3 |
When the value is negative, the curve bulges downward, but the text stays on the upper side of the curve and does not appear upside down. The curve runs from left to right, so the left side of the direction of travel is the upper side of the screen.
Text longer than the curve loses its end characters
The SVG 2 specification says that characters whose midpoint falls beyond the end of the line are not drawn. When the text is centered with textAnchor="middle", the characters that run past the line are the ones at both ends.
I placed "Sore nara neko no te de, kyokusen ni sotte moji o narabe" (20 characters, length 398.2) on a straight line of length 320.0. Only 16 characters were drawn. The first two characters (sore) and the last two (narabe) disappeared. When I set the bend to 60 (curve length 347.9), only the first character (so) and the last character (be) disappeared, but the text still did not fit.

In Chromium, no error or warning appeared in the console when characters disappeared. So CurvedText compares the text length measured with getComputedTextLength() against the curve length measured with getTotalLength(). If the text is longer, it shows a warning. The lengths are measured again whenever d changes, so the warning appears and disappears depending on the bend. For "Sore nara neko no te de, kyokusen ni sotte narabu" (17 characters, length 338.2), the warning appeared at bends of 0, 30, and 45. It disappeared at 60 (curve length 347.9).
However, the warning appears before any characters disappear. As noted earlier, the specification stops drawing characters only when a character's midpoint moves past the end of the line. In the 17-character example, all 17 characters were drawn at bends of 0, 30, and 45, where the warning appeared. CurvedText checks whether the whole string fits on the curve. If even one end character extends beyond the curve, it shows the warning before any characters disappear.
Results of testing the path and side attributes in Chromium
MDN's description of textPath also lists two experimental attributes. One is path, which lets you write the line's shape directly without referencing another element. The other is side, which controls which side of the line the text is placed on.
I wrote the SVG directly without React. In Chromium 153, when I wrote an arc in the path attribute, the characters were placed in the same positions as when I referenced a <path>. With side="right", the position of the characters was the same as without the attribute, and they did not move to the inside of the circle. In @types/react 19.3.0, the SVG props include path, but not side.





