TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← Back to library

Caption Reveal

A caption is revealed on top of an image on hover.

Live Demo

Hover over the element or press Tab to focus.

Source Code

Copy the HTML, CSS or JavaScript you need for your project.

HTML
<a href="#" class="tb-tip-image tb-tip-image--reveal" aria-label="View project details"><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MjAiIGhlaWdodD0iMzIwIiB2aWV3Qm94PSIwIDAgNTIwIDMyMCI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJnIiB4Mj0iMSIgeTI9IjEiPjxzdG9wIHN0b3AtY29sb3I9IiM3Q0M0QzYiLz48c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiM0NzY2OEIiLz48L2xpbmVhckdyYWRpZW50PjwvZGVmcz48cmVjdCB3aWR0aD0iNTIwIiBoZWlnaHQ9IjMyMCIgZmlsbD0idXJsKCNnKSIvPjxjaXJjbGUgY3g9IjM3MCIgY3k9IjgzIiByPSI0MyIgZmlsbD0iI0ZGRTNBNSIvPjxwYXRoIGQ9Ik0wIDMwMEwxMzUgMTM3TDI0NSAyNjdMMzE4IDE4N0w1MjAgMzIwSDBaIiBmaWxsPSIjMjM0NTY1Ii8+PHBhdGggZD0iTTAgMzIwTDE1MCAyMTJMMjk1IDMyMFoiIGZpbGw9IiMzQzc3OEMiLz48L3N2Zz4=" alt="Illustrated mountain landscape"><span>VIEW PROJECT <b aria-hidden="true">↗</b></span></a>
CSS
 .tb-tip-image{display:block;position:relative;overflow:hidden;width:min(320px,100%);height:195px;border-radius:9px;color:#fff;text-decoration:none;font:700 14px system-ui}
.tb-tip-image img{width:100%;height:100%;object-fit:cover;display:block}
.tb-tip-image::after{content:"";position:absolute;inset:0;background:#142d56b8;opacity:0;transition:opacity .3s ease}
.tb-tip-image span{position:absolute;z-index:1;inset:0;display:flex;align-items:center;justify-content:center;gap:10px;opacity:0;transform:translateY(12px);transition:opacity .3s ease,transform .3s ease}
.tb-tip-image:hover::after,.tb-tip-image:focus-visible::after,.tb-tip-image:hover span,.tb-tip-image:focus-visible span{opacity:1}
.tb-tip-image:hover span,.tb-tip-image:focus-visible span{transform:translateY(0)}
.tb-tip-image:focus-visible{outline:3px solid #7360cd;outline-offset:4px}
@media(prefers-reduced-motion:reduce){.tb-tip-image::after,.tb-tip-image span{transition:none}}

How to Use

Insert the HTML and add the CSS to your stylesheet. Adjust colors and sizes and avoid class conflicts.

Use Case

Galleries, project cards and case studies.

Technical Notes

Keep controls usable on touch devices. Test keyboard focus and reduced-motion preferences.

Mobile:Verify focus and tap behavior on touch devices.

Browser:Uses modern CSS features.

Reduced Motion:Respects prefers-reduced-motion.