Open In App

CSS rotate() Function

Last Updated : 30 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The rotate() function is an inbuilt CSS function used to rotate an element based on a specified angle. This angle can be set in terms of degrees, gradians, radians, or turns. The positive and negative angles rotate the elements in a clockwise and counterclockwise direction, respectively.

Syntax:

rotate( angle )

Parameters: This function accepts single parameter angle which represents the angle of rotations. The positive and negative angles rotate the elements in clockwise and counter-clockwise respectively. 

Below examples illustrates the rotate() function in CSS: 

Example 1: In this example, we center content and rotate an image by 45 degrees using CSS transform: rotate(45deg);, displaying the “GeeksforGeeks” logo with a green heading and centered alignment.

html
<!DOCTYPE html>
<html>

<head>
    <title>CSS rotate() function</title>
    <style>
        body {
            text-align: center;
        }

        h1 {
            color: green;
        }

        .rotate_image {
            transform: rotate(45deg);
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h2>CSS rotate() function</h2>
    <br><br>

    <img class="rotate_image" 
         src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"
        alt="GeeksforGeeks logo">
</body>

</html>

Output: 

Example 2: In this example we centers content, displays “GeeksforGeeks” in green, and rotates “Welcome to GeeksforGeeks” by 30 degrees using CSS transform: rotate(30deg);.

html
<!DOCTYPE html>
<html>

<head>
    <title>CSS rotate() function</title>
    <style>
        body {
            text-align: center;
        }

        h1 {
            color: green;
        }

        .GFG {
            font-size: 35px;
            font-weight: bold;
            color: green;
            transform: rotate(30deg);
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h2>CSS rotate() function</h2>
    <br><br>

    <div class="GFG">Welcome to GeeksforGeeks</div>
</body>

</html>

Output:  

Supported Browsers: The browsers supported by rotate() function are listed below:



Next Article

Similar Reads