How do Transforms work in SVG?

Publish in Javascript el 21/05/2025 13:21

Types of Transformations in SVG: A Complete Technical Guide

The transform attribute in SVG (Scalable Vector Graphics) allows you to apply geometric transformations to graphic elements such as rectangles, circles, lines, groups (<g>), text, and more. These transformations are essential when you want to manipulate the position, size, orientation, or shape of elements without directly altering their coordinate or dimensional attributes.

In this technical article, we’ll explore the different types of transformations available in SVG, their syntax, effects, and how to combine them effectively.



What is transform in SVG?

The transform attribute modifies the local coordinate system of an SVG element. It does not alter the DOM or the element’s base attributes, but rather changes how it is visually rendered on screen.

General Syntax


Transformation Types

SVG supports six basic types of transformations:


translate(tx, ty)

Shifts the coordinate system along the X axis (tx) and the Y axis (ty).


If only one parameter is passed (translate(50)), ty is assumed to be 0.

Equivalent to: moving the object without changing its shape or size.


Play Code


scale(sx, sy)

Scales the object on the X and Y axes. If sy is not specified, sy = sx is assumed.


  • sx > 1: widens
  • sy > 1: stretches
  • sx < 1: shrinks in X
  • sy < 1: shrinks in Y
  • sx = -1 reflects the element
  • sy = -1: reflects the element


Play Code


rotate(angle [, cx, cy])

Rotates the element clockwise. A pivot point (cx, cy) can be specified.

  • Without center: rotates relative to the origin (0, 0)
  • With center: rotates relative to that point


Play Code


skewX(angle)

Tilts the object horizontally along the X axis. It affects the X coordinates according to its Y position.


skewY(angle)

Tilts the object vertically along the Y axis. It affects the Y coordinates according to its X position.


Play Code


matrix(a, b, c, d, e, f)

General affine transformation defined by a 2x3 matrix.

Represents the following linear transformation:

The coordinates (x, y) are transformed as follows:

This allows any combination of translation, rotation, scaling, and skew to be represented in a single operation.


Play Code

Compositing Transformations

SVG allows you to chain multiple transformations, which are applied from left to right, following the order in which they are written.


This order matters:

  • Move to the point (50, 50)
  • Then rotate around the origin (0,0) (already shifted)
  • Finally, scale in that new system

If you want to rotate around the center of the object, it is important to use rotate(angle, cx, cy).


Best Practice Recommendations

  • Use transform instead of recalculating attributes (x, y, etc.) if you want to modify the view without altering the underlying data.
  • Prefer rotate(angle, cx, cy) to avoid having to combine with translate().
  • Group elements with <g> to apply collective transformations.
  • Only use matrix() when a complex composite transformation is required or for interoperability with other tools.


— Hely Rojas

Frontend Developer & Designer @ artdraw

También te puede interesar

Handling Clicks, MouseOver, and MouseLeave on SVG elements with Javascript
Handling Clicks, MouseOver, and MouseLeave on SVG elements with Javascript

In today’s web development landscape, Scalable Vector Graphics (SVG) play a crucial role in creat...

How to Export SVG as PNG or JPEG with JavaScript
How to Export SVG as PNG or JPEG with JavaScript

Today I want to share with you a handy web tool I created for converting SVG images to PNG format...

Edit and Change SVG Colors with Javascript
Edit and Change SVG Colors with Javascript

Customizing SVG Elements: A Deep Dive into Our New Color Editor ToolAs a web developer and educat...

Boolean Operations in SVG Using Javascript
Boolean Operations in SVG Using Javascript

Boolean Operations Between SVG Shapes Using Clipper.js: A Technical ApproachIntroductionBoolean o...

Javascript CSS Gradient Generator
Javascript CSS Gradient Generator

Inside the Gradient Generator Tool of ArtDraw: How It WorksHi everyone, I"m the developer behind ...

Color Palette Generator in Javascript
Color Palette Generator in Javascript

As someone passionate about design and front-end development, I’ve always been fascinated by how ...