Fade Overlay

A semi-transparent black ::before overlay fades in on hover, dimming the image but leaving it visible.

Fade Overlay demo

Hover or focus the image to see the effect.

HTML

<div class="hover-effect fade-overlay">
  <img src="image.jpg" alt="description">
</div>

CSS

.hover-effect.fade-overlay{
  position: relative;
}
.hover-effect.fade-overlay::before{
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.45s ease;
}
.hover-effect.fade-overlay:hover::before,
.hover-effect.fade-overlay:focus-visible::before{
  opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  .hover-effect.fade-overlay::before{
    transition: none;
  }
  .hover-effect.fade-overlay:hover::before,
  .hover-effect.fade-overlay:focus-visible::before{
    opacity: 1;
  }
}

Select the code and copy with Ctrl+C or ⌘C.