CSS tip to add a caption or title to an image on your website. Easy to follow example. Test it out and play with the settings to create your own look.
Adding a Caption to an Image with CSS
By Linda Chadbourne | March 17th, 2008 |

Want an easy way to add a caption to an image like this?

HTML
<div class="imagecaption">
<img src="your-image-here.jpg">
<alt="Stacked" width="150" height"100" /><p>Orange Pyramid</p> </div>
CSS
.imagecaption {
width: 200px;
border: 1px solid #999999;
padding: .5em;
}
p {
font: small Verdana, Arial, Helvetica, sans-serif;
text-align: center;
}



Linda Chadbourne has been a web designer since 1998. A large portion of her day also involves graphic and logo design for 

July 17th, 2008 at 4:43 am
This isn’t really valid code, is it?
That should be a single line:
Oh, and I’ve noticed that leaving out the px in height and width sometimes screwes up things.
July 17th, 2008 at 8:24 am
Hmmm… why is it not valid code? And what should be in one line?
Units are very important, you should never leave them out … never. Unless of course you have a value of 0. Then 0px or 0em or 0% it’s all the same. It’s still 0.