Publish in Javascript el 21/05/2025 13:21
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.
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
SVG supports six basic types of transformations:
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.
Scales the object on the X and Y axes. If sy is not specified, sy = sx is assumed.
Rotates the element clockwise. A pivot point (cx, cy) can be specified.
Tilts the object horizontally along the X axis. It affects the X coordinates according to its Y position.
Tilts the object vertically along the Y axis. It affects the Y coordinates according to its X position.
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.
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:
If you want to rotate around the center of the object, it is important to use rotate(angle, cx, cy).
Frontend Developer & Designer @ artdraw
In today’s web development landscape, Scalable Vector Graphics (SVG) play a crucial role in creat...
Today I want to share with you a handy web tool I created for converting SVG images to PNG format...
Customizing SVG Elements: A Deep Dive into Our New Color Editor ToolAs a web developer and educat...
Boolean Operations Between SVG Shapes Using Clipper.js: A Technical ApproachIntroductionBoolean o...
Inside the Gradient Generator Tool of ArtDraw: How It WorksHi everyone, I"m the developer behind ...
As someone passionate about design and front-end development, I’ve always been fascinated by how ...