Why add image hover effects?
A hover effect is a change that happens when someone moves their mouse over an element. On images, a subtle effect makes a gallery or a set of product cards feel responsive, and it tells visitors "this picture is clickable".
The original version of this tutorial built the classic effect from that era: a semi-transparent black layer, or overlay, that faded in over the image with a search icon on top. It needed an extra element, a fixed-size container and a separate icon image.
Today we have a much more flexible tool: CSS filters. With a single line of CSS you can turn an image black and white, brighten it, blur it or tint it, then bring it back to normal on hover. Overlays still have their place, especially for captions, so we'll cover the modern way to do those too.
Hover over each image below, or press Tab to move to it with the keyboard:
Meet CSS filters
The filter property applies visual effects to an element, much like the filters in a photo app. You give it one or more filter functions, each with a value in brackets:
img {
filter: grayscale(100%);
}
Filters work on anything, not just photos: images, icons, videos, even text and whole sections. Here's the same picture with each of the main filters applied:
The filter functions
| Function | What it does | No change at |
|---|---|---|
grayscale() | Removes colour; 100% is fully black and white | 0% |
sepia() | Gives an old-photo brown tint | 0% |
blur() | Softens the image by the given radius | 0 |
brightness() | Darkens below 100%, brightens above it | 100% |
contrast() | Flattens below 100%, adds punch above it | 100% |
saturate() | Mutes colours below 100%, makes them more vivid above it | 100% |
hue-rotate() | Shifts every colour around the colour wheel by an angle | 0deg |
invert() | Reverses colours, like a photo negative | 0% |
opacity() | Makes the element see-through | 100% |
drop-shadow() | Adds a shadow that follows the image's actual shape | none |
Tip: drop-shadow() is different from box-shadow. A box shadow is always a rectangle, but a drop shadow hugs the visible shape, which is perfect for icons and images with transparent backgrounds.
Combining filters
You can apply several filters at once by listing them with spaces in between. They're applied in order, from left to right:
.vintage {
filter: sepia(60%) contrast(110%) brightness(90%);
}
.dramatic {
filter: grayscale(100%) contrast(140%);
}
Key rule: a new filter value replaces the old one completely, it doesn't add to it. If an image has filter: sepia(60%) and a hover rule sets filter: blur(2px), the sepia disappears on hover. To keep both, list both in the hover rule.
Hover effects with filters
Now for the fun part. Combine a filter with the :hover pseudo-class, which matches while the mouse is over an element, and a transition, which animates the change smoothly.
Greyscale to colour
A popular effect for team photos and logo walls: images start in black and white, and burst into colour on hover.
.gallery img {
filter: grayscale(100%);
transition: filter 0.4s ease;
}
.gallery a:hover img,
.gallery a:focus-visible img {
filter: grayscale(0%);
}
Notice the hover rule targets the link (a), not the image. That way the same rule can use :focus-visible, so keyboard users get the effect when they tab to the link.
A gentle brighten
For a subtler touch, lift the brightness and colour slightly:
.card img {
transition: filter 0.4s ease;
}
.card a:hover img,
.card a:focus-visible img {
filter: brightness(115%) saturate(130%);
}
Tip: list the exact property in your transition, as in transition: filter 0.4s ease, rather than transition: all as the original tutorial did. It's clearer, and it stops unrelated properties from animating by accident.
Adding a zoom
A slow zoom makes an image feel like it's moving towards you. The trick is to scale the image inside a container that hides anything spilling over its edges:
.zoom {
display: block;
overflow: hidden;
border-radius: 10px;
}
.zoom img {
display: block;
width: 100%;
transition: scale 0.4s ease;
}
.zoom:hover img,
.zoom:focus-visible img {
scale: 1.1;
}
overflow: hiddenon the container crops the enlarged image, so it grows within its frame instead of over the page.scale: 1.1enlarges the image to 110% of its size. You can also writetransform: scale(1.1).display: blockon the image removes the small gap browsers leave under images by default.
When an overlay still helps: captions
Filters are great for changing the image itself, but sometimes you want to show information on hover, such as a title or a "View project" label. That's where an overlay is still the right tool, and it's much simpler than it used to be.
<a class="tile" href="/projects/green-hills/">
<img src="green-hills.jpg" alt="">
<span class="tile__caption">Green Hills</span>
</a>
.tile {
position: relative;
display: block;
overflow: hidden;
border-radius: 10px;
}
.tile img {
display: block;
width: 100%;
}
.tile__caption {
position: absolute;
inset: 0;
display: grid;
place-items: center;
background: rgb(17 24 39 / 0.7);
color: #ffffff;
font-weight: 600;
opacity: 0;
transition: opacity 0.3s ease;
}
.tile:hover .tile__caption,
.tile:focus-visible .tile__caption {
opacity: 1;
}
What's different from the old version?
| Old approach | Modern approach |
|---|---|
Fixed width: 195px and height: 151px | Container sizes itself to the image, so it works on any screen |
| Image set as an inline background style | A real <img> element, so it can have alt text and load efficiently |
A <div> inside a link, and a separate search icon image | A simple <span> caption with real text |
top: 60px to roughly centre the icon | display: grid and place-items: center centre it perfectly, at any size |
Five prefixed transition lines | One standard transition line |
The overlay colour uses an alpha (transparency) value, rgb(17 24 39 / 0.7), so the image still shows through. That's why we fade the overlay with the opacity property instead of changing its background colour.
Combining a filter with a caption
For the best of both, blur and darken the image itself instead of laying a dark box over it. The caption text then sits on top:
.tile:hover img,
.tile:focus-visible img {
filter: blur(3px) brightness(65%);
scale: 1.05; /* hides the soft blurred edges */
}
Why scale it up? Blurring softens the image's edges, which would leave a faint pale border inside the frame. Scaling up by 5% pushes those soft edges outside the container, where overflow: hidden crops them away.
Accessibility and touch screens
Phones and tablets can't hover
Touch screens have no mouse pointer, so hover effects either don't happen or flash briefly on tap. That's fine for decorative filters, but captions that only appear on hover would be hidden from phone users entirely.
The hover media query detects whether the device can hover. Use it to show captions all the time on touch screens:
@media (hover: none) {
.tile__caption {
opacity: 1;
}
}
Key rule: never hide important information behind a hover effect alone. If visitors need it, make sure it's visible on touch screens and when using the keyboard.
Include keyboard focus
Every example in this post pairs :hover with :focus-visible. That gives people who navigate with the keyboard the same effect as mouse users. Make sure the link also has a visible focus outline, so they can see where they are.
Write good link text
A link that contains only an image needs a text alternative, or screen readers (software that reads pages aloud) have nothing to announce. Either give the image descriptive alt text, or include a caption inside the link as we did above. If the caption already says what the link is, the image can use an empty alt="" so the name isn't read twice.
Respect reduced motion
Zooms and fades can be uncomfortable for some people. Switch the movement off for visitors who've turned on "reduce motion" in their device settings:
@media (prefers-reduced-motion: reduce) {
.zoom img,
.tile img,
.tile__caption {
transition: none;
}
}
Good to know: filters can be demanding for older devices, especially blur() on large images. Keep blur amounts small and use them on a handful of images rather than a huge gallery.
Wrapping up
CSS filters let you restyle any image with a single line: black and white, vintage, bright, blurred or tinted. Add a transition and a hover rule to animate them, a scale for a zoom, and an overlay when you need to show a caption. Pair every :hover with :focus-visible and plan for touch screens, and your hover effects will work for everyone.