The transform attribute defines a list of transform definitions that are applied to an element and the element's children.
Note: As of SVG2, transform is a presentation attribute, meaning it can be used as a CSS property. However, be aware that there are some differences in syntax between the CSS property and the attribute. See the documentation for the CSS property transform for the specific syntax to use in that case.
Also, as a legacy from SVG 1.1, <linearGradient> and <radialGradient> support the gradientTransform attribute, and <pattern> supports the patternTransform attribute, both of which act exactly like the transform attribute.
The following transform functions can be used by the transform attribute <transform-list>
Warning: As per the spec, you should be able to also use CSS transform functions. However, the compatibility isn't guaranteed.
Matrix
The matrix(<a> <b> <c> <d> <e> <f>) transform function specifies a transformation in the form of a transformation matrix of six values. matrix(a,b,c,d,e,f) is equivalent to applying the transformation matrix:
which maps coordinates from a previous coordinate system into a new coordinate system by the following matrix equalities:
Example
<svgviewBox="0 0 200 200"xmlns="http://www.w3.org/2000/svg"><rectx="10"y="10"width="30"height="20"fill="green"/><!--
In the following example we are applying the matrix:
[a c e] [3 -1 30]
[b d f] => [1 3 40]
[0 0 1] [0 0 1]
which transform the rectangle as such:
top left corner: oldX=10 oldY=10
newX = a * oldX + c * oldY + e = 3 * 10 - 1 * 10 + 30 = 50
newY = b * oldX + d * oldY + f = 1 * 10 + 3 * 10 + 40 = 80
top right corner: oldX=40 oldY=10
newX = a * oldX + c * oldY + e = 3 * 40 - 1 * 10 + 30 = 140
newY = b * oldX + d * oldY + f = 1 * 40 + 3 * 10 + 40 = 110
bottom left corner: oldX=10 oldY=30
newX = a * oldX + c * oldY + e = 3 * 10 - 1 * 30 + 30 = 30
newY = b * oldX + d * oldY + f = 1 * 10 + 3 * 30 + 40 = 140
bottom right corner: oldX=40 oldY=30
newX = a * oldX + c * oldY + e = 3 * 40 - 1 * 30 + 30 = 120
newY = b * oldX + d * oldY + f = 1 * 40 + 3 * 30 + 40 = 170
--><rectx="10"y="10"width="30"height="20"fill="red"transform="matrix(3 1 -1 3 30 40)"/></svg>
Translate
The translate(<x> [<y>]) transform function moves the object by x and y. If y is not provided, it is assumed to be 0.
In other words:
xnew = xold + <x>
ynew = yold + <y>
Example
<svgviewBox="0 0 100 100"xmlns="http://www.w3.org/2000/svg"><!-- No translation --><rectx="5"y="5"width="40"height="40"fill="green"/><!-- Horizontal translation --><rectx="5"y="5"width="40"height="40"fill="blue"transform="translate(50)"/><!-- Vertical translation --><rectx="5"y="5"width="40"height="40"fill="red"transform="translate(0 50)"/><!-- Both horizontal and vertical translation --><rectx="5"y="5"width="40"height="40"fill="yellow"transform="translate(50 50)"/></svg>
Scale
The scale(<x> [<y>]) transform function specifies a scale operation by x and y. If y is not provided, it is assumed to be equal to x.
The rotate(<a> [<x> <y>]) transform function specifies a rotation by a degrees about a given point. If optional parameters x and y are not supplied, the rotation is about the origin of the current user coordinate system. If optional parameters x and y are supplied, the rotation is about the point (x, y).
Example
<svgviewBox="-12 -2 34 14"xmlns="http://www.w3.org/2000/svg"><rectx="0"y="0"width="10"height="10"/><!-- rotation is done around the point 0,0 --><rectx="0"y="0"width="10"height="10"fill="red"transform="rotate(100)"/><!-- rotation is done around the point 10,10 --><rectx="0"y="0"width="10"height="10"fill="green"transform="rotate(100, 10, 10)"/></svg>
SkewX
The skewX(<a>) transform function specifies a skew transformation along the x axis by a degrees.