CSS: Image Rollover

By Xah Lee. Date: . Last updated: .

This page shows how to do image rollover with CSS.

Here is a image rollover. Hover your mouse over it.

Code

<div id="irollover"></div>
#irollover {
 width: 128px;
 height: 128px;
 background: url("i/tile_A.png");
}

#irollover:hover {
 background: url("i/tile_B.png");
}

The trick is using the :hover CSS: Pseudo-Class Selectors

Image Rollover

CSS, Background Image

CSS, border, margin, box model