CSS Image Hover Effects
This example demonstrates how to create image hover effects using CSS transitions, transforms, filters, overlays, and shadows. Each effect changes the appearance of an image when the mouse pointer moves over it.
Zoom Effect
The image gradually enlarges using the scale() transform function.
Grayscale to Color
The image changes from grayscale to its original colors when hovered.
Blur Effect
The blur() filter creates a soft, blurred appearance.
Brightness Effect
The brightness() filter increases the image's brightness.
Opacity Effect
The image becomes partially transparent when hovered.
Rotate Effect
The image enlarges slightly and rotates using CSS transforms.
Slide Effect
The image shifts horizontally while maintaining its container dimensions.
Sepia Effect
The sepia() filter gives the image a warm, vintage appearance.
Color Overlay
A semi-transparent colored overlay appears over the image.
Image Details
Text Overlay
A dark overlay and descriptive text fade into view when hovered.
Border Effect
A colored border appears inside the image container.
Inset Shadow Effect
An inset shadow creates a colored frame around the image.
Try It: Move your mouse over each image to compare the different hover effects. Resize the browser window to see the gallery automatically adjust its number of columns. Replace the placeholder images with your own photographs or graphics to customize the examples.
How Image Hover Effects Work
CSS image hover effects use the :hover pseudo-class to apply styles when the pointer moves over an image or its container.
The transition property controls how smoothly the image changes between its normal and hover states.
For example, the following CSS creates a zoom effect:
.effect-zoom:hover img {
transform: scale(1.15);
}
The scale() function enlarges the image to 115% of its original displayed size.
The image container uses overflow: hidden to prevent the enlarged image from extending beyond its boundaries.
Using CSS Image Filters
The filter property applies visual effects directly to an image.
Common filter functions include grayscale(), blur(), brightness(), and sepia().
The following CSS changes an image to grayscale:
filter: grayscale(100%);
Setting grayscale(0%) restores the image's original colors.
Multiple filter functions can be combined to create additional visual effects.
Creating Image Overlays
Image overlays add a semi-transparent layer over an image when hovered.
The ::after pseudo-element can create an overlay without requiring an additional HTML element.
The following CSS creates a colored overlay:
.effect-overlay::after {
content: "";
position: absolute;
inset: 0;
background-color: rgba(20, 108, 148, 0.55);
opacity: 0;
transition: opacity 0.4s ease;
}
.effect-overlay:hover::after {
opacity: 1;
}
The opacity property controls the overlay's visibility.
The transition property creates a smooth fade between the hidden and visible states.
Text overlays can be added using positioned HTML elements inside the image container.
Responsive Image Effects
The example uses CSS Grid to arrange the image effects into responsive columns.
The auto-fit keyword automatically adjusts the number of columns according to the available space.
The minmax() function defines flexible column widths.
A media query at 600 pixels or less reduces the image height, spacing, and page margins.
This allows the examples to remain organized and readable on smaller screens.
Image Hover Effect Accessibility
Hover effects should enhance an image's appearance without hiding essential information.
Touchscreen devices may not provide a conventional hover interaction, so important content should remain available without hovering.
Each example includes a visible caption describing its effect.
Use meaningful alternative text for informative images and sufficient color contrast for overlay text.
The prefers-reduced-motion media query removes movement and transitions for visitors who request reduced motion.
When an image is used as an interactive link, provide a visible keyboard focus indicator and ensure that any important hover content is also accessible through keyboard focus.
Customizing Image Hover Effects
You can change the intensity of each effect by modifying the CSS property values.
For example, increase or decrease the value in scale() to control the zoom level.
Adjust the blur() value to create a stronger or softer blur effect.
Modify the transition duration to control how quickly the effect appears.
You can also change the overlay colors, border widths, shadows, and image dimensions to match your website's design.
To add another example, duplicate an existing figure element and update its image source, effect class, heading, and description.
For production websites, replace the placeholder image URLs with optimized images stored in your website's img directory.