Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I use inline HTML elements in SVG?

Tags:

html

svg

I am wondering if there were a way to use inline HTML like <sup> and <sub> elements in SVG?

For example:

<svg>
  <text x="0" y="12">Some text with a superscript <sup>1</sup> and a subscript <sub>2</sub>.</text>
</svg>

I can not find anything about using inline HTML elements in SVG. I am hoping to use superscript without having to use a styled <tspan>.

like image 661
Lady Aleena Avatar asked Dec 11 '25 20:12

Lady Aleena


1 Answers

A possible solution to your problem is using tspan elements and the attribute baseline-shift like so:

tspan[baseline-shift]{font-size:50%;}
<svg viewBox="0 0 350 40">
  <text x="0" y="12">Some text with a superscript <tspan baseline-shift="super">1</tspan> and a subscript <tspan baseline-shift="sub">2</tspan>.</text>
</svg>
like image 148
enxaneta Avatar answered Dec 13 '25 09:12

enxaneta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!