{"id":356179,"date":"2021-11-08T11:00:53","date_gmt":"2021-11-08T19:00:53","guid":{"rendered":"https:\/\/css-tricks.com\/?page_id=356179"},"modified":"2021-11-10T16:23:49","modified_gmt":"2021-11-11T00:23:49","slug":"rotate","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/r\/rotate\/","title":{"rendered":"rotate"},"content":{"rendered":"\n
The While CSS already has another way to rotate elements using the \u2026the CSS The angle values are expressed in degrees, gradians, radians, or turns.<\/p>\n\n\n\n Most times, you\u2019ll likely find yourself using a degree unit (e.g. The rotate<\/code> property in CSS turns an element around one or more axes. Think of it like poking one or more pins into an element and spinning the element around those points in clockwise and counter-clockwise directions measured in degree, gradian, radian, and turn values.<\/p>\n\n\n\n
.element {\n rotate: 45deg;\n}<\/code><\/pre>\n\n\n\n\n\n\n\n
rotate()<\/code><\/a> function in the
transform<\/code> property, like this:<\/p>\n\n\n\n
.element {\n transform: rotate(45deg);\n}<\/code><\/pre>\n\n\n\n
rotate<\/code> property does it independently of the
transform<\/code><\/a> property altogether, plus the added benefit of being able to rotate along the Z-axis, something not currently possible with
transform: rotate()<\/code>.<\/p>\n\n\n
Syntax<\/h3>\n\n\n
rotate: none | <angle> | [ x | y | z | <number>{3} ] && <angle>;<\/code><\/pre>\n\n\n\n
\/* Keyword values *\/\nrotate: none;\n\n\/* Angle values *\/\nrotate: 45deg;\nrotate: 0.35turn;\nrotate: 1.27rad;\nrotate: -50grad;\n\n\/* x, y, or z-axis name plus angle *\/\nrotate: x 45deg;\nrotate: y 0.35turn;\nrotate: z 1.27rad;\n\n\/* Vector plus angle values *\/\nrotate: 1 0.5 1 45deg;\n\n\/* Global values *\/\nrotate: inherit;\nrotate: initial;\nrotate: revert;\nrotate: unset;<\/code><\/pre>\n\n\n\n
none<\/code><\/li>
Values<\/h3>\n\n\n
none<\/code>:<\/strong> Default value. No rotation is applied to the element.<\/li>
<angle><\/code>:<\/strong> An
<angle><\/code> value is used to specify a numeric value (expressed with
deg<\/code>,
grad<\/code>,
rad<\/code> or
turn<\/code> units) for how much to rotate the element around the Z axis. This value works exactly like the
rotate()<\/code><\/a> function we use with the transform` property.<\/li>
<angle><\/code> value: <\/strong>This identifies which axis (X, Y or Z)) to rotate around along with a numeric value for how much to rotate the element around that axis<\/li>
<angle><\/code> used to specify the angle to rotate the element through. Equivalent to a
rotate3d()<\/code> (3D rotation) function.<\/li><\/ul>\n\n\n
Units<\/h3>\n\n\n
45deg<\/code>) as a
rotate<\/code> property value. But as we\u2019ve seen, there are four total types of units that the property accepts. They\u2019re less common that, say, pixels, ems, rems, and percentages, so let\u2019s break them down to understand what they are and how they work.<\/p>\n\n\n\n
deg<\/code>:<\/strong> One degree is 1\/360 of a full circle.<\/li>
grad<\/code>:<\/strong> One gradian is 1\/400 of a full circle.<\/li>
rad<\/code>:<\/strong> A radian is the length of a circle\u2019s diameter around the shape\u2019s arc. One radian is
180deg<\/code>, or 1\/2 of a full circle. One full circle is 2\u03c0 radians, which is equal to
6.2832rad<\/code> or
360deg<\/code>.<\/li>
turn<\/code>:<\/strong> One turn is one full circle. So, halfway around a circle is equal to
.5turn<\/code>, or
180deg<\/code>.<\/li><\/ul>\n\n\n\n
rotate<\/code> property accepts any of these units, as they are different way of expressing the same idea: an angle around a circle. And they are equally supported by all major browsers<\/a>.<\/p>\n\n\n\n