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.

<style>
  .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;
  }
</style>

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

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(
  linear,
  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 is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

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

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

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

We will never send any spam emails. Promise 🫶🏻