Interactive online courses HTML Academy
2026-03-09 10:54 Diff

There are two coordinate systems in SVG:

  1. The viewport coordinate system: viewport space
  2. and the content coordinate system: user space

Initially, the systems and their units correspond to each other:

<svg width="350" height="200"> … </svg>

Currently, only the content coordinate system is visible (shown in red), because the systems are the same and one is hidden underneath the other.

If you add a viewbox or transform, the content and its coordinate system will begin to shift and scale:

<svg width="350" height="200" viewBox="0 0 237 300"> … </svg>

Content coordinates are calculated starting from the top-left corner (at 0,0). Without the viewbox, this is the upper left corner of the viewport (turquoise point), but with the viewbox, this is the upper left edge of the viewbox (red point).

That is, now the location of the content will be measured relative to the new coordinate system and not from the viewport. Because of this, the figure will not appear to the left, but closer to the center, and the coordinate systems will no longer match.