Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

What is the unit SVG text coordinates?

H i all. Can someone explain me what is the unit of Svg text coordinates? And how we translate them to pixels? Thank U.


Thanks to Robert to his answer; But I have a problem with using it. Here is my code:

<svg viewBox="0 0 1000 1000"> 

<text x="23.5625" y="195.98749542236328" fill="red" style="font-size: 60px">Hi</text>


<input style="position: absolute; left: 23.5625px; top: 195.987px">

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Per the SVG specification omitted units are the same as pixels.

One px unit is defined to be equal to one user unit. Thus, a length of "5px" is the same as a length of "5".

Note that a viewBox applies a transform that makes the SVG responsive. If you want to match an absolutely positioned input then you don't want that. Also the baseline for text by default is the bottom of most letters, if we use hanging as the baseline instead then that will match the input.

I've also made the input opacity 0.5 so you can see the SVG is now underneath the input element.

html, body, svg {
  width: 100%;
  height: 100%;

<text x="23.5625" y="195.98749542236328" fill="red" style="font-size: 20px;dominant-baseline: hanging;">Hi</text>


<input style="position: absolute; left: 23.5625px; top: 195.987px;opacity: 0.5;">

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers


48.4k users