VOOZH about

URL: https://www.geeksforgeeks.org/html/how-to-rotate-image-in-html/

⇱ How to Rotate Image in HTML? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Rotate Image in HTML?

Last Updated : 8 Oct, 2024

Rotating and scaling images in HTML can enhance the visual presentation of your web content. By using CSS properties like transform, you can easily change the orientation and size of images. This will help you understand the process of rotating images using the rotate() function and scaling images with the scaleX() and scaleY() functions.

Rotating an Image with CSS

To rotate an image in HTML, you can use the transform: rotate() property. This property allows you to change the orientation of an image by a specified angle, measured in degrees, gradians, radians or turns.

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

Syntax:

transform: rotate(90deg);

Example: Implementation of the transform rotate property

Output:

👁 Screenshot-2023-12-20-102619

Scaling Images with CSS

In addition to rotating, you can also scale images along the x-axis and y-axis using the scaleX() and scaleY() functions.

1. scaleX() Function

The scaleX() function is an inbuilt function which is used to resize an element along the x-axis in a 2D plane. It scales the elements in a horizontal direction.

Syntax:

transform : scaleX( number ) 

// number is scalling factor

Example: Implementation of the transform scaleX( ) property

Output:

👁 Screenshot-2023-12-20-104154

2. scaleY() Function

The scaleY( ) function is an inbuilt function which is used to resize an element along the y-axis in a 2D plane. It scales the elements in a vertical direction.

Syntax:

transform: scaleY(scalingFactor);

Example: Implementation of the transform scale( ) property with an example.

Output:

👁 Screenshot-2023-12-20-103651

Comment