I recently discovered the alignment-baseline
and text-anchor
styles for SVG Text Element
s but, for some reason those attributes do not seem to work with SVG Path Element
s.
I am hoping for some way to center the test text in the below example without using javascript to set the 'x' and 'y' values of the aforementioned text element.
<svg width="600" height="600">
<!-- Ellipse -->
<g transform="translate(120,140)">
<ellipse cx="0" cy="0" rx="100" ry="50" stroke="#aaa" stroke-width="2" fill="#fff"></ellipse>
<text x="0" y="0" alignment-baseline="middle" font-size="12" stroke-width="0" stroke="#000" text-anchor="middle">HueLink</text>
</g>
<g>
<path d="M250 250 L250 0 A250,250,0,0,1,466.50635094610965,124.99999999999997 L250 250 Z" fill="#ddd" stroke="#ddd"></path>
<text style="font-size: 24px;" text-anchor="middle" alignment-baseline="middle" href="#p1">
test text
</text>
</g>
</svg>
[Edit]: Thanks @Gerarod Furtado for the clarification. My goal is to center the text on the shape rather than have the text follow the path like in @chrwahl's answer.
In conclusion it does seem that centering text on an svg path is impossible without javascript.