How to rotate an image on mouse hover, the code utilizes transition, transform, scale and rotate. Sourced under a permissive license.

How to rotate an image on mouse hover, the code utilizes transition, transform, scale and rotate

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<figure class="hover-rotate">
<img src="https://codesnippetsandtutorials.com/wp-content/uploads/2023/07/dynamic-wang-xO_qjW18oIw-unsplash-840x400.jpg"/>
</figure>
<style>
.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);
}
</style>
<figure class="hover-rotate"> <img src="https://codesnippetsandtutorials.com/wp-content/uploads/2023/07/dynamic-wang-xO_qjW18oIw-unsplash-840x400.jpg"/> </figure> <style> .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); } </style>
<figure class="hover-rotate">
  <img src="https://codesnippetsandtutorials.com/wp-content/uploads/2023/07/dynamic-wang-xO_qjW18oIw-unsplash-840x400.jpg"/>
</figure>

<style>
.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);
}
</style>

Tags: CSS, HTML, CSS, CSS code snippet, html code snippet, transition, transform, scale, rotate

Image: Unsplash license

CC BY 4.0 added intro and tags – 30 Seconds of Code