Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Rotate div to -20 degrees angle with CSS
The CSS transform property with rotate() function allows you to rotate an element by a specified angle. To rotate a div to -20 degrees, you apply a negative rotation value which rotates the element clockwise.
Syntax
selector {
transform: rotate(angle);
}
Example
The following example demonstrates how to rotate a div to -20 degrees angle −
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: pink;
border: 1px solid black;
margin: 20px;
padding: 20px;
display: flex;
align-items: center;
justify-content: center;
font-family: Arial, sans-serif;
}
.normal {
background-color: lightblue;
}
.rotated {
transform: rotate(-20deg);
}
</style>
</head>
<body>
<div class="normal">
Normal div (0 degrees)
</div>
<div class="rotated">
Rotated div (-20 degrees)
</div>
</body>
</html>
Two rectangular boxes appear: a light blue normal div and a pink div rotated 20 degrees clockwise. The rotated div appears tilted to the right with its content also rotated.
Key Points
- Negative values rotate clockwise, positive values rotate counterclockwise
- Angle units can be specified in degrees (deg), radians (rad), or turns
- Transform origin is the center of the element by default
-
Modern browsers support the standard
transformproperty without vendor prefixes
Conclusion
Using transform: rotate(-20deg) is the standard way to rotate elements. The negative value creates a clockwise rotation, making it perfect for achieving tilted or angled visual effects in your layout.
Advertisements
