HTML-CSS: Image rotate on hover

HTML-CSS : Exercise-14 with Solution

Using HTML, CSS create a rotate effect for the image on hover.

  • Use the scale, rotate and transition properties when hovering over the parent element (a <figure>) to animate the image.
  • Use overflow: hidden on the parent element to hide the excess from the image transformation.

HTML Code:

<!--License: https://bit.ly/3GjrtVF-->
<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Using HTML, CSS create a rotate effect for the image on hover</title>
<figure class="hover-rotate">
  <img src="https://www.w3resource.com/html-css-exercise/html-css-practical-exercises/flower-2.jpeg" height="100" width="100"/></figure>

CSS Code:

.hover-rotate {
  overflow: hidden;
  margin: 8px;
  min-width: 240px;
  max-width: 320px;
  width: 100%;

.hover-rotate img {
  transition: all 0.3s;
  box-sizing: border-box;
  max-width: 100%;

.hover-rotate:hover img {
  transform: scale(1.3) rotate(5deg);

HTML-CSS Editor:

See the Pen html-css-practical-exercises by w3resource (@w3resource) on CodePen.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

HTML-CSS: Tips of the Day

How can I show dots ("...") in a span with hidden overflow?

For this you can use text-overflow: ellipsis; property. Write like this

span {
    display: inline-block;
    width: 180px;
    white-space: nowrap;
    overflow: hidden !important;
    text-overflow: ellipsis;
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book</span>

Ref: https://bit.ly/2RqEbdh