CSS Image Captions with Gradients and Transparent Backgrounds

CSS Image Captions

You can add a semi-transparent white on black caption to your images using simple CSS. The opacity of the caption background can be changed by modifying the alpha parameter in background-color’s rgba attribute.

  .image {
    width: 600px;
  .image .black {
    position: relative;
    left: 0;
    bottom: 60px;
    width: 100%;
    padding: 10px 20px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.6);
    filter: progid:DXImageTransform.Microsoft.gradient
          (startcolorstr=#7F000000,endcolorstr=#7F000000) 9;

  .image .black a {
    color: white;
    font-size: 18px;
    text-decoration: none;
    outline: none;
    font-family: georgia;

  .image .black .follow {
    margin-top: 5px;
    position: absolute;
    right: 10px;
    top: 30px;
    font-size: 12px;
    font-family: verdana;

<div class="image">
  <img src="img.png" />
  <div class="black">
    <a href="#"> Image Caption </a>
    <a href="#" class="follow"> Image Credit &rarr; </a>

Instead of transparent backgrounds, you can even have fading gradients that transition from black to white much like the lower thirds in videos. Add this snippet to the CSS.

background: -webkit-gradient(
  left bottom,
  left top,
  color-stop(1, rgba(0, 0, 0, 0)),
  /* Top */ color-stop(0, rgba(0, 0, 0, 1)) /* Bottom */

/* Gecko */
background: -moz-linear-gradient(center bottom, rgba(0, 0, 0, 1) 0%, /* Bottom */ rgba(0, 0, 0, 0) 100% /* Top */);
Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory


Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.