How to Rotate Container Background Image using CSS ?

The CSS background-image property is used to add an image to the background of an element. In this article, the task is to rotate the image which is used in the background.

Approach: The CSS transform property is used to apply two-dimensional or three-dimensional transformation to a element. This property can be used to rotate, scale, move or even skew an element.

Syntax:

.class_name { transform: value } 

Example: We can use the CSS transform property to fix this issue and make rotations as given below:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <!-- Bootstrap CDN -->
    <link rel="stylesheet"
          href=
  
    <!-- CSS -->
    <style>
        .background-image {
            background-image: url('Geeksforgeeks_image.jpg');
            background-repeat: no-repeat;
            height: 300px;
        }
          
        .rotated-background-image {
            background-image: url('Geeksforgeeks_image.jpg');
            background-repeat: no-repeat;
            height: 100%;
            margin-top: 250px;
            transform: rotate(90deg);
            /* All browsers support */
            -moz-transform: rotate(90deg);
            -webkit-transform: rotate(90deg);
            -o-transform: rotate(90deg);
            -ms-transform: rotate(90deg);
        }
          
        .custom {
            height: 100px;
            padding-top: 10px;
        }
    </style>
</head>
  
<body>
    <!-- Normal image which is not rotated -->
    <div class="container custom">
        <div class="background-image">
        </div>
    </div>
    <!-- Rotated image -->
    <div class="container">
        <div class="rotated-background-image">
        </div>
    </div>
  </body>
  
</html>

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.