Skip to main content

Image Hover Overlay

You can use CSS to create overlay effects that appear when the user hovers over an image. The overlay is placed on top of the image using absolute positioning inside a relative container. Different transitions control how the overlay appears — it can fade in, or slide in from any direction.

Fade in text

This example fades in a dark overlay with white text over the image on hover. The overlay uses opacity with a transition to create a smooth fade effect.

Prompt
Create an image hover overlay that fades in text. Show an avatar image inside a container with position relative. On hover, a dark semi-transparent overlay with white centered text "Hello World" fades in over the image using opacity transition.
Output: complete HTML page

Fade in a box

This example fades the image to a lower opacity and shows a colored box with text in the center on hover.

Prompt
Create an image hover overlay that fades in a box. Show an avatar image inside a container with position relative. On hover, a white text box appears centered over the image, displaying "John Doe" inside a styled box with a background color, using opacity transition.
Output: complete HTML page

Slide in from top

This example slides a dark overlay down from the top of the image on hover, using a height transition.

Prompt
Create an image hover overlay that slides in from the top. Show an avatar image inside a container. On hover, a dark semi-transparent overlay slides down from the top of the image with white centered text "Hello World", using height transition.
Output: complete HTML page

Slide in from bottom

This example slides a dark overlay up from the bottom of the image on hover.

Prompt
Create an image hover overlay that slides in from the bottom. Show an avatar image inside a container. On hover, a dark semi-transparent overlay slides up from the bottom of the image with white centered text "Hello World", using height transition.
Output: complete HTML page

Slide in from left

This example slides a dark overlay in from the left side of the image on hover, using a width transition.

Prompt
Create an image hover overlay that slides in from the left. Show an avatar image inside a container. On hover, a dark semi-transparent overlay slides in from the left side of the image with white centered text "Hello World", using width transition.
Output: complete HTML page

Slide in from right

This example slides a dark overlay in from the right side of the image on hover.

Prompt
Create an image hover overlay that slides in from the right. Show an avatar image inside a container. On hover, a dark semi-transparent overlay slides in from the right side of the image with white centered text "Hello World", using width transition.
Output: complete HTML page

Flip an Image

You can flip an image horizontally when the user hovers over it. This uses the CSS transform property with scaleX(-1) to mirror the image.

Example

Move your mouse over the image to flip it horizontally.

Prompt
Create a page with an image that flips horizontally on hover. Use the CSS transform scaleX(-1) on the img:hover state to mirror the image when the mouse is over it.
Output: complete HTML page

Responsive Image Gallery

CSS can be used to create responsive image galleries. This example uses media queries to rearrange the images on different screen sizes. Resize the browser window to see the effect.

Tip: Read more about Responsive Web Design in the CSS RWD Tutorial.

Example

This gallery shows four images side by side on large screens, two per row on medium screens, and one per row on small screens.

Prompt
Create a responsive image gallery with four images in a row. Each gallery item has a linked image and a description below it. Use media queries so that at 768px or less the layout changes to two images per row, and at 480px or less it stacks to one image per row.
Output: complete HTML page