Image Hover Effects in CSS: Zoom, Overlays and Card Hovers | HorizonX
← The Journal

CSS

Image Hover Effects in CSS: Zoom, Overlays and Card Hovers

Five image and card hover effects in CSS: zoom, overlay, grayscale, clip-path reveal and lift, with one switch for hover and focus and a table for touch.

HorizonX

HorizonX

November 29, 2026 · 9 min read

Image Hover Effects in CSS: Zoom, Overlays and Card Hovers

Most image and card hover effects in CSS use five techniques: scale the image inside a clipped frame, fade in an overlay, change a filter, reveal a layer with clip-path, or lift the whole card. Animate transform, opacity and filter, run the same effect on keyboard focus, and never put essential content behind hover.

This guide builds a card that supports all five, wires hover and focus to a single switch, and ends with a table for choosing between them. It covers images and cards only. For hover effects on text, such as underlines, letter staggers, captions and tooltips, see the hover text effects guide. Ready-made image and card effects are grouped in the HorizonX hover effects collection.

Start with markup that works without hover

A card is usually one link with an image and some text. Put the real link on the heading, then stretch it over the whole card with a pseudo-element, the pattern from Inclusive Components: Cards that "stretches the link's layout over the whole card, making it clickable like a button". The CSS cards guide covers that pattern, the grid and secondary links in detail; this is the minimum the effects below need.

<article class="card">
  <div class="card-media">
    <img src="trail.jpg" alt="A wooden path crossing a marsh at dawn" width="800" height="600">
  </div>
  <div class="card-body">
    <h3><a class="card-link" href="/guides/marsh-trail">Marsh trail for beginners</a></h3>
    <p>A flat two-hour loop with three viewpoints.</p>
  </div>
</article>
.card {
  position: relative;
  border-radius: 0.75rem;
  background-color: #ffffff;
}

.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

@supports selector(:has(a)) {
  .card:has(.card-link:focus-visible) {
    outline: 3px solid #192c46;
    outline-offset: 3px;
  }

  .card-link:focus-visible {
    outline: none;
  }
}

The screen reader user hears one link with a meaningful name, and the pointer user can click anywhere. Here the focus ring moves to the card with :has() rather than to the pseudo-element, because the effects below need a card-level state anyway; browsers without :has() keep the link's own ring.

One switch for hover and focus

Hover effects should also run when the card has keyboard focus, and they should not stick after a tap on a phone. Instead of writing every effect twice, set one custom property in both situations and let each effect read it:

@media (hover: hover) and (pointer: fine) {
  .card:hover {
    --active: 1;
  }
}

.card:has(:focus-visible) {
  --active: 1;
}

The hover media feature checks the primary input only, so a phone reports none even though a tap can still trigger :hover. Adding pointer: fine keeps the effects for mouse and trackpad users. The focus rule uses :has(:focus-visible) rather than :focus-within, because some browsers also focus a link when it is clicked or tapped, and :focus-within would leave the effect stuck on after a tap. Every effect below defaults to var(--active, 0), so on touch the card simply shows its resting state, and in a browser without :has() keyboard users get the focus ring of the link without the effect.

Five image and card hover effects

1. Zoom inside a fixed frame

.card-media {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 0.75rem 0.75rem 0 0;
}

.card-media img {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  transform: scale(calc(1 + 0.06 * var(--active, 0)));
  transition: transform 450ms ease-out;
}

aspect-ratio and object-fit: cover keep every card the same shape whatever the photo's proportions, and overflow: hidden on the frame crops the zoom. The example uses 6 percent; every extra percent crops more of the photo's edges, so check that the subject stays in view.

2. Gradient overlay

.card-media::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgb(25 44 70 / 0.65), transparent 60%);
  opacity: var(--active, 0);
  transition: opacity 250ms ease-out;
}

Fading a pre-drawn gradient with opacity is cheaper than animating the gradient itself. Keep the overlay decorative. If it carries text, that text is invisible on touch screens and has to follow the rules for content on hover covered below.

3. Grayscale to color

.card-media img {
  filter: grayscale(calc(1 - var(--active, 0)));
  transition: transform 450ms ease-out, filter 300ms ease-out;
}

This rule extends effect 1, so it repeats the transform transition. filter changes how the image is painted, not the layout, which keeps it reasonable for a handful of cards. Use it for mood, not meaning: touch users only ever see the gray version.

4. Reveal a second image with clip-path

Product grids often swap to a second photo on hover. Stack the second image over the first and uncover it from the left:

.card-media .alt-view {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% * (1 - var(--active, 0))) 0 0);
  transition: clip-path 450ms ease-out;
}

Give the second image alt="" if it only repeats the first, and do not rely on it for information, since touch users never see it. Two clip-path inset() shapes can be interpolated, so the reveal animates instead of jumping.

5. Lift the card and dim its neighbors

.card {
  transform: translateY(calc(-4px * var(--active, 0)));
  transition: transform 250ms ease-out, opacity 250ms ease-out;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 18px 40px -16px rgb(25 44 70 / 0.45);
  opacity: var(--active, 0);
  transition: opacity 250ms ease-out;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .card-grid:has(.card:hover) .card:not(:hover) {
    opacity: 0.75;
  }
}

The cards guide shows a plain lift; this version adds neighbor dimming. The shadow is drawn once and faded with opacity, so the browser does not repaint a changing box-shadow on every frame. The neighbor dimming uses :has(), Baseline widely available since June 2026; browsers without it skip the rule. Keep the dim mild, because it lowers the contrast of the text on every other card while the pointer is on one. This is also why the card itself has no overflow: hidden: only the image frame clips, so the shadow can spread outside the card.

Three cards where the middle one is raised with its image zoomed and the others faded, above a toggle linked to mouse, keyboard and touch input

Reduced motion and content on hover

Movement is the part to remove. Fades and color changes can stay:

@media (prefers-reduced-motion: reduce) {
  .card,
  .card-media img {
    transform: none;
    transition-property: opacity, filter;
  }

  .card-media .alt-view {
    transition: none;
  }
}

That meets the intent of WCAG 2.3.3 Animation from Interactions: "Motion animation triggered by interaction can be disabled". The second image still appears on hover, but at once instead of sliding in.

If the hover reveals extra content, such as a description or a set of actions over the image, WCAG 1.4.13 Content on Hover or Focus applies: the content must be dismissible without moving the pointer or focus, hoverable so the pointer can move onto it, and persistent until the user moves away. The simplest way to pass is to avoid the situation: show the description and actions all the time and let the hover change only the image.

Choosing an effect

Effect Properties Visible on touch Keyboard Best for
Zoom in frame transform Resting state only Yes, via :has(:focus-visible) Photo grids, article cards
Gradient overlay opacity No Yes Making a light image read as active
Grayscale to color filter Gray only Yes Portfolio and team grids where mood matters
Second image reveal clip-path No Yes Product cards with an alternate view
Lift and dim transform, opacity No Yes, lift only Dense grids where the pointer target needs emphasis

The column that matters most is "Visible on touch". On any site with phone visitors, everything in a "No" row has to be optional for the page to make sense.

A card resting on a phone screen beside the same card hovered on a desktop screen, showing that the card is complete without the hover state

FAQ

How do you make an image zoom on hover in CSS?

Put the image in a frame with overflow: hidden and a fixed aspect-ratio, size it with object-fit: cover, and animate transform: scale() on hover. A small scale such as 1.06 keeps most of the photo in view, since every extra percent crops more of the edges. Run the same zoom on keyboard focus, limit the hover version to devices with a fine pointer so it does not stick after a tap, and drop the zoom under prefers-reduced-motion.

How do you add a hover effect to a card?

Make the whole card one link by stretching the heading's link over it with a pseudo-element, then change the card on hover and on keyboard focus. A common effect is a small lift with translateY() plus a shadow faded in with opacity, which avoids repainting a changing box-shadow on every frame. Keep the text and actions visible at rest, because touch users never see the hover state. The CSS cards guide covers the stretched link pattern in detail.

How do I add a hover effect in HTML?

Write the effect in CSS and attach it to your HTML with a class. Give the element a class such as card, style its resting state, then add a .card:hover rule and a transition so the change animates. Animate cheap properties like transform, opacity and filter. Run the same effect on keyboard focus with :has(:focus-visible), and wrap the hover rule in @media (hover: hover) and (pointer: fine) so it does not stick on touch screens.

Image and card hover effects on HorizonX

When a CSS snippet is not enough, these HorizonX components go further, and you can tune them in the browser and export HTML, Svelte or React:

  • Hover Curtain: a thumbnail follows the pointer over a list of links, revealed by a sliding mask. It listens to mouse events only, so keyboard users get working links without the preview, and it hides the preview entirely under reduced motion. Treat it as decoration on top of a list that already works.
  • Luminous Card: a card that lights from the inside on hover. It lights on keyboard focus too, and on devices without hover it ships in its lit state instead of hiding the effect.

More image and card effects are collected in the hover effects collection.