Search code examples
htmlgeometrylines

Multiple lines in HTML circle?


I would like to write multiple lines in this circles without css, but only if it's needed style tag.

Here's the code:

<svg height="300" width="300">
    <circle cx="150" cy="150" r="120" stroke="red" stroke-width=4 fill="#ffffff" />
    <text x="50%" y="50%" text-anchor="middle" stroke="#000000" stroke-width="1px" dy=".3em">My code<br/>isn't good</text>
</svg>

Thank you!


Solution

  • this is the best i was able to do. It works but its hardcoded which obviously is not ideal. I looked at this other post btw, might be of some help: How to linebreak an svg text within javascript?

    <svg height="300" width="300">
        <circle cx="150" cy="150" r="120" stroke="red" stroke-width=4 fill="#ffffff" />
        <text text-anchor="middle" stroke="#000000" stroke-width="1px" dy=".3em">
    
        <tspan x="50%" y="40%" dy="1.2em">very long text</tspan>
        <tspan x="50%" y="50%" dy="1.2em">I would like to linebreak</tspan>
        </text>
    </svg>