Skip to content
Related Articles

Related Articles

Improve Article

How to rotate an HTML div element 90 degrees using JavaScript ?

  • Last Updated : 16 Oct, 2019

An element can be rotated 90 degrees by using the transform property. This property is used to move, rotate, scale and others to perform various kinds of transformation to elements.
The rotate() transformation function can be used as the value to rotate the element. It takes one parameter which defines the rotation angle. The rotation angle consists of two parts, the value of the rotation followed by the unit of rotation. The unit can be defined in degrees (deg), gradient (grad), radians (rad) and turns.

To rotate by 90 degrees any of the units can be used with their corresponding values. 90 degrees would equal to 100 gradient or 0.25 turns.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Applying this property to the required element would rotate it by 90 degrees.


// Using CSS
transform: rotate(90deg);

// Using JavaScript = 'rotate(90deg)';

Example: The example uses a rectangle and one side of a border to explain the rotation.

<!DOCTYPE html>
        How to rotate an HTML div element
        90 degrees using JavaScript ?
        .box {
            height: 250px;
            width: 150px;
            border-right: 5px solid;
            background-color: lightgreen;
    <h1 style="color: green">
        How to rotate an HTML div
        element in 90 degrees?
        Click on the button below to rotate
        the element by 90 degress.
    <div class="box"></div>
    <button onclick="rotateElem()">
        Rotate by 90 degrees
    <script type="text/javascript">
        function rotateElem() {
                       = 'rotate(90deg)';


  • Before clicking the button:
  • After clicking the button:

My Personal Notes arrow_drop_up
Recommended Articles
Page :