SVG Standards & W3C Specs

SVG Coordinate Systems, ViewBox & Units Glossary: 40+ Terms Explained

SVG Coordinate Systems, Viewport, ViewBox and Aspect Ratio Scaling Vector Graphic
W3C SVG coordinate transformation pipeline: from local user coordinate space through viewBox projection to browser client screen pixels.

Interactive ViewBox & PreserveAspectRatio Simulator

Test how different preserveAspectRatio directives map a fixed 100x100 viewBox onto a wide 260x120 viewport container. Switch modes to observe meet letterboxing, slice overflow clipping, and anchor alignments.

ViewBox Projection Simulator
100x100
preserveAspectRatio="xMidYMid meet" scales the 100x100 user space uniformly to fit completely within the 280x130 viewport, leaving letterbox spacing on the left and right.

Coordinate Spaces & Unit Systems Matrix

Quick reference comparing how SVG establishes, calculates, and transforms coordinates across different rendering contexts:

Space / Unit Mode Origin Point (0,0) Scale / Calculation Base Primary Applications DOM Transformation API
userSpaceOnUse Top-left of local SVG user coordinate system Absolute user units defined by viewBox or viewport Patterns, gradients, masks matching shape geometry element.getCTM()
objectBoundingBox Top-left corner of the element's bounding box Relative fractions from 0.0 to 1.0 (0% to 100%) Stretching gradients & masks across dynamic shapes element.getBBox()
viewBox User Space Specified by min-x, min-y parameters Arbitrary resolution-independent unit grid (e.g. 24x24) Icon definitions, responsive illustrations svg.getScreenCTM().inverse()
Viewport (CSS Pixels) Top-left of rendered SVG container element Device pixel ratio scaled by browser layout zoom Container layout, responsive sizing, touch targets element.getBoundingClientRect()
Screen / Client Space Top-left of browser window / viewport Hardware pixels relative to device viewport window Mouse event tracking, cursor drag-and-drop, tooltips DOMPoint.matrixTransform()
1. Viewport, ViewBox & Coordinate Mapping 6 terms
viewportSVG Viewport Container

The finite rectangular layout window allocated to the SVG element on the web page. Established by CSS width/height or SVG presentation attributes. Serves as the clipping and projection frame for all vector content.

<svg width="400" height="300"> <!-- 400x300 CSS Viewport Window --></svg>
viewBoxviewBox="min-x min-y width height"

Defines the virtual camera aperture and internal user coordinate system. Specifies the rectangular bounds of vector space that the browser maps onto the external viewport.

<svg viewBox="0 0 24 24" width="48" height="48"> <!-- Scales 24x24 coords to 48px --></svg>
preserveAspectRatiopreserveAspectRatio="[align] [meetOrSlice]"

Controls how the browser projects the internal user coordinate system into an external viewport with a different aspect ratio. Dictates whether vectors scale uniformly or stretch non-uniformly.

preserveAspectRatio="xMidYMid meet" <!-- Uniform scale, centered, letterboxed -->
preserveAspectRatio: meetUniform Fit (Contain)

Scales the viewBox uniformly until both dimensions fit completely inside the viewport. Equivalent to CSS object-fit: contain. Never clips graphic content, but may create pillarbox or letterbox margins.

preserveAspectRatio="xMidYMid meet"
preserveAspectRatio: sliceUniform Cover (Clip)

Scales the viewBox uniformly until it completely covers the viewport container. Equivalent to CSS object-fit: cover. Fills the entire viewport with zero dead margin, but slices off vector parts extending past edges.

preserveAspectRatio="xMidYMid slice"
preserveAspectRatio: noneNon-Uniform Stretch (Fill)

Disables uniform aspect ratio preservation completely. Distorts vector geometry non-uniformly so the viewBox coordinates stretch to match the exact width and height of the host viewport.

preserveAspectRatio="none" <!-- Geometric shapes will warp -->
2. Aspect Ratio Alignment Anchors 9 terms
xMinYMinTop-Left Anchor

Aligns the minimum X coordinate of the viewBox with the left viewport edge, and the minimum Y with the top edge. Anchors content to top-left during aspect ratio scaling.

preserveAspectRatio="xMinYMin meet"
xMidYMinTop-Center Anchor

Horizontally centers the viewBox along the X-axis while anchoring its minimum Y edge flush with the top of the viewport.

preserveAspectRatio="xMidYMin meet"
xMaxYMinTop-Right Anchor

Aligns the maximum X boundary with the right edge of the viewport, anchored to the top.

preserveAspectRatio="xMaxYMin meet"
xMinYMidMiddle-Left Anchor

Aligns the left edge flush with the left viewport boundary while vertically centering the viewBox along the Y-axis.

preserveAspectRatio="xMinYMid meet"
xMidYMidCenter-Center Anchor (Default)

The W3C default alignment parameter. Centers the viewBox both horizontally and vertically inside the viewport space.

preserveAspectRatio="xMidYMid meet"
xMaxYMidMiddle-Right Anchor

Aligns the right boundary flush with the right viewport edge while vertically centering the viewBox along the Y-axis.

preserveAspectRatio="xMaxYMid meet"
xMinYMaxBottom-Left Anchor

Anchors the viewBox flush against the bottom-left corner of the viewport frame.

preserveAspectRatio="xMinYMax meet"
xMidYMaxBottom-Center Anchor

Horizontally centers the viewBox along the X-axis while anchoring its bottom edge to the bottom of the viewport.

preserveAspectRatio="xMidYMax meet"
xMaxYMaxBottom-Right Anchor

Anchors the viewBox flush against the bottom-right corner of the viewport frame.

preserveAspectRatio="xMaxYMax meet"
3. Coordinate Spaces & Reference Systems 6 terms
user coordinate system (User Space)Virtual Canvas Space

The infinite 2D Cartesian coordinate space in which path coordinates and shapes are defined. Positioned relative to an origin (0,0) with positive X extending right and positive Y extending downward.

<path d="M 10 20 L 50 80" /> <!-- Evaluated in User Space -->
viewport coordinate systemLayout Frame Coordinates

The physical pixel coordinate space established by the viewport on the rendered webpage. Its origin (0,0) sits at the top-left corner of the SVG container element.

svg.getBoundingClientRect() <!-- Measures Viewport Coordinate Space -->
initial coordinate systemUnscaled Default Space

The user coordinate system when no viewBox or transforms are active, where one user unit equals one CSS pixel on the host display.

<svg width="200" height="200"><circle cx="100" cy="100" r="50"/></svg>
client coordinate systemBrowser Window Pixels

The pixel coordinate system returned by mouse and pointer events (e.clientX, e.clientY). Mapped into SVG user space via getScreenCTM().inverse().

const pt = new DOMPoint(e.clientX, e.clientY).matrixTransform(svg.getScreenCTM().inverse());
current coordinate systemActive Transformed Frame

The active local coordinate system resulting from cumulative affine transformations applied by parent <g>, <svg>, or <use> elements.

<g transform="translate(40, 60) rotate(45)"><!-- Current coordinate system modified --></g>
transformed coordinate spaceRotated/Scaled Space

A localized user space whose axes have been rotated, translated, or sheared. Child elements position themselves relative to the newly modified axes rather than the root origin.

<g transform="scale(2)"><rect x="10" y="10" ... /><!-- Renders at (20,20) --></g>
4. Unit Interpretations & Relative Bounds 6 terms
userSpaceOnUseAbsolute User Coordinates

Specifies that coordinates and dimensions within paint servers, masks, or clip paths reference the current user coordinate system in absolute units (pixels), maintaining consistent scale regardless of target element dimensions.

gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="100" y2="100"
objectBoundingBoxRelative Fraction (0.0 – 1.0)

The default mode where coordinates are fractions of the bounding box of the element being painted. x1="0" x2="1" spans 100% of the element width.

gradientUnits="objectBoundingBox" x1="0%" y1="0%" x2="100%" y2="0%"
patternUnits & patternContentUnitsPattern Tile vs Inner Graphics

patternUnits governs whether the repeating tile box scales with the element or in user pixels. patternContentUnits governs whether shapes inside the tile calculate in user pixels or fractions.

<pattern patternUnits="userSpaceOnUse" patternContentUnits="userSpaceOnUse" ... >
maskUnits & maskContentUnitsMask Bounds vs Inner Shapes

maskUnits defines the coordinate system for the clipping bounds of the <mask> element. maskContentUnits dictates whether the inner luminance shapes calculate relative to the masked element.

<mask maskUnits="objectBoundingBox" maskContentUnits="userSpaceOnUse" ... >
clipPathUnitsClipping Boundary Units

Specifies whether vector paths inside a <clipPath> evaluate in userSpaceOnUse (fixed pixels) or objectBoundingBox (0-to-1 normalized fractions).

<clipPath id="circleClip" clipPathUnits="objectBoundingBox"> <circle cx="0.5" cy="0.5" r="0.5"/> </clipPath>
gradientUnitsGradient Vector Resolution

Controls whether linear/radial gradient vectors (x1, y1, x2, y2) are resolved in userSpaceOnUse or objectBoundingBox space.

<linearGradient id="grad" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="1" y2="1">
5. Units of Measurement & Dimension Scaling 6 terms
user units (unitless values)Standard Coordinate Unit

Numbers declared without units in SVG attributes (e.g. width="24", r="5"). Exactly equals 1 user space coordinate, mapping to 1 CSS pixel before viewBox transformations.

<circle cx="12" cy="12" r="10" /> <!-- 12 and 10 are unitless user units -->
CSS px in SVG96 DPI Reference Pixel

The standard CSS pixel unit defined as 1/96th of an inch. In SVG, appending px behaves identically to unitless user units in the absence of CSS font scaling.

<rect width="100px" height="50px" />
absolute length units (cm, mm, in, pt, pc)Physical Units

Physical measurement units converted to user units via standard CSS ratios: 1in = 96px, 1pt = 1.333px, 1pc = 16px, 1cm = 37.795px, 1mm = 3.7795px.

<line x1="0" y1="0" x2="2in" y2="0" stroke="black" /> <!-- 192 user units -->
font-relative units (em, ex, ch, rem)Typographic Units

Dynamic units computed from the computed font metrics of the SVG element. Allows vector icons to scale fluidly with neighboring typography when width="1em" height="1em" is set.

<svg width="1.2em" height="1.2em" viewBox="0 0 24 24"> <!-- Scales with font-size --></svg>
percentage units (%)Viewport-Relative Percentages

Lengths resolved as percentages against the width (for X coordinates), height (for Y coordinates), or normalized diagonal length of the nearest ancestor SVG viewport.

<rect width="50%" height="100%" fill="blue" />
vector-effect: non-scaling-strokeConstant Display Stroke

A vector styling property that instructs the browser GPU to calculate stroke thickness after all viewBox and CSS transforms, keeping line caliper locked to display pixels regardless of zoom.

path { vector-effect: non-scaling-stroke; stroke-width: 1.5px; }
6. Matrix Math & Coordinate Transformation Interfaces 6 terms
CTM (Current Transformation Matrix)Local to Viewport Matrix

The active 3x3 affine matrix transforming 2D coordinates from current user space into the nearest SVG viewport coordinate system.

const matrix = element.getCTM();
Screen CTM (getScreenCTM)User Space to Screen Pixels

The DOM method returning the transformation matrix that maps coordinates from local user space directly to the client screen display pixel grid.

const screenMatrix = svgElement.getScreenCTM();
SVGMatrix / DOMMatrixAffine Matrix Interface

The standard JavaScript API representing affine geometric transformation matrices. Provides multiplication, inversion, translation, and rotation methods for vector projection.

const m = new DOMMatrix().translate(10, 20).rotate(45);
matrix(a,b,c,d,e,f)Affine Matrix Function

Compact matrix notation representing [scaleX, skewY, skewX, scaleY, translateX, translateY]. Transforms any vector coordinate (x, y) via x' = ax + cy + e, y' = bx + dy + f.

<g transform="matrix(1, 0, 0, 1, 50, 100)"><!-- Pure translate(50,100) --></g>
transform-origin (SVG vs CSS)Transformation Anchor Point

In native SVG specification space, transform-origin defaults to (0,0) (top-left of the canvas), unlike HTML elements which default to (50%, 50%) (center of bounding box). Modern CSS allows transform-box: fill-box; transform-origin: center; to center rotations.

svg-element { transform-box: fill-box; transform-origin: center; }
currentTranslate & currentScaleInteractive Pan & Zoom

DOM properties on the root SVGSVGElement representing the user-agent panning translation point and magnification scale factor applied to the entire graphic.

svg.currentScale = 2.0; svg.currentTranslate.x = 50;
7. Viewport Clipping, Nesting & Overflow 5 terms
nested viewport (<svg> in <svg>)Sub-Viewports

An <svg> element nested inside another <svg> establishes its own local viewport, with an independent coordinate origin, width, height, and viewBox projection.

<svg viewBox="0 0 100 100"> <svg x="50" y="50" width="50" height="50" viewBox="0 0 24 24">...</svg> </svg>
symbol viewport mapping<symbol> with viewBox

When a <symbol> with its own viewBox is referenced via <use width="X" height="Y">, the browser creates a synthetic nested viewport, mapping the symbol's viewBox onto the use dimensions.

<symbol id="icon" viewBox="0 0 24 24">...</symbol> <use href="#icon" width="48" height="48"/>
overflow: visible vs hiddenViewport Clipping Boundary

Controls whether graphics rendered outside the rectangular viewport limits are clipped (default hidden) or allowed to spill into neighboring document layout (overflow: visible).

svg.icon-spill { overflow: visible; } <!-- Prevents drop-shadow clipping -->
clip: rect()Legacy Viewport Clipping

A deprecated CSS clipping property formerly used by browser engines to restrict SVG viewport visibility bounds, now superseded by modern clip-path.

clip: rect(0, 100px, 100px, 0);
zoomAndPanzoomAndPan="magnify | disable"

An SVG document-level presentation attribute specifying whether the browser should permit user-initiated interactive panning and zooming controls.

<svg zoomAndPan="disable" ... >

Key Coordinate Systems Takeaways

Mastering SVG coordinate architecture means recognizing the two distinct worlds inside every vector graphic: the host webpage viewport, governed by CSS box model pixels, and the infinite internal user space, governed by mathematical viewBox coordinates. With uniform preserveAspectRatio alignment, precise userSpaceOnUse vs objectBoundingBox decisions, and getScreenCTM() matrix transformations, developers build razor-sharp, distortion-free vector interfaces across all devices.

Frequently Asked Questions

What is the difference between an SVG viewport and viewBox?

The viewport is the physical or CSS layout rectangle allocated to the SVG on the webpage (defined by width and height in HTML/CSS). The viewBox is the internal camera or canvas coordinate system (min-x, min-y, width, height) in which vector paths are drawn. The browser maps the internal viewBox onto the external viewport using preserveAspectRatio rules.

How does userSpaceOnUse differ from objectBoundingBox?

userSpaceOnUse resolves coordinates in the current user coordinate space using absolute units (pixels), keeping gradients, patterns, and masks consistent across different elements. objectBoundingBox treats coordinates as relative fractions (0.0 to 1.0) of the bounding box of the target element, causing visual effects to stretch proportionally if the element changes shape.

How do preserveAspectRatio="meet" and "slice" behave when scaling?

Both preserve uniform aspect ratios without distorting geometry. "meet" scales the viewBox until the entire viewBox fits inside the viewport, potentially creating empty letterbox bars on the sides. "slice" scales the viewBox until it completely covers the viewport, slicing off whatever vector content extends outside the viewport bounds.

How do you translate browser screen coordinates (clientX, clientY) into SVG user coordinates?

Create a DOMPoint representing the mouse coordinates, obtain the element's inverse Screen Current Transformation Matrix via svg.getScreenCTM().inverse(), and apply point.matrixTransform(inverseMatrix). This calculates the exact user space coordinate regardless of viewport scaling, CSS translations, or zoom levels.

Why do unitless numbers in SVG default to CSS pixels?

Under the W3C SVG 2 and CSS specifications, one user coordinate unit equals one reference CSS pixel (1/96 of an inch). Omitting units (e.g. width="24") allows mathematical operations, coordinate transforms, and viewBox mappings to function without unit conversion overhead.

What causes SVG icons to scale disproportionately or warp?

SVG warping occurs when an explicit width and height with different aspect ratios are applied to an SVG that either lacks a viewBox attribute or has preserveAspectRatio="none". Adding a square viewBox (e.g. 0 0 24 24) and omitting preserveAspectRatio="none" prevents non-uniform distortion.