Photo by Jurvetson
I've tried a few different methods to display captions beneath images, and the best solution I have found so far is to use CSS. This allows me to align images (and their relevant captions) to the left, right or center of the post with ease.
So in this post, I will explain how I achieve stylized captions beneath my images in Blogger posts using only CSS and HTML tags.
Some examples of images with captions
Left Image Right Image

This is achieved by wrapping both the images and the captions in <span> tags which have a "class" depending on their alignment (left, right or center aligned).
Center aligned image (Photo by Montrasio International)
How these captions work
This image demonstrates the code I use to make the captions appear beneath each image:
In the body of my posts, the code for the images and captions will appear like this:
<span class="left-caption">This example would produce an image and caption which is aligned to the left of the text in my post.
<img src="http://url-of-image.com/image.jpg" />
<p>Caption of this image</p>
</span>
To align an image to the right, I would replace "left-caption" with "right-caption", or to center the image I would use "center-caption".
The CSS code used to produce these images and captions
If you would like to use captions which are styled like those I use in my posts, you will need to use the following styling code:
.right-caption { float: right; margin: 0 0 1em 1.5em; padding: 0.5em; text-align: center; }
.center-caption { margin: 0 0 1em 0; padding: 0; text-align: center; }
.left-caption img, .right-caption img, .center-caption img { margin: 0 auto; display: block; }
.left-caption p, .right-caption p, .center-caption p { background: #eee; margin: 0; line-height: 1.6em; padding: 0.5em; border-bottom: 1px solid #ccc; border-top: 1px solid #ccc; font-size: 0.9em; color: #333; }
How to use these captions in your Blogger posts
Once you have added this style code to your blog's template, you can display captions beneath the images in your posts.
To achieve this, you will need to wrap both your image and your caption in span tags according to the alignment you prefer. Here are the three different formats you could use:
To align these to the left
<span class="left-caption">
<img src="http://image-host.com/yourimage.jpg" />
<p>Your Caption Here</p>
</span>
To align these to the right:
<span class="right-caption">
<img src="http://image-host.com/yourimage.jpg" />
<p>Your Caption Here</p>
</span>
To align these to the center of the page:
<span class="center-caption">
<img src="http://image-host.com/yourimage.jpg" />
<p>Your Caption Here</p>
</span>
Note that the captions are also wrapped in paragraph tags, like this:
<p>Your Caption Here</p>This ensures the caption is properly styled, as the CSS code contains the styles for paragraphs which appear within this span class.
If you upload your image using Blogger's image upload function, you must make sure that you choose "None" in the layout choices.
It may be easier for you to use the HTML editor to create posts with image captions as this will allow you to see all of the code you are using.
Other methods of adding captions to your posts
As I explained at the beginning of this post, there are many different methods you could use to display captions beneath your images. The method I explained here is the one which works best for me, though you may prefer to use a different technique.
Here are some links to other articles which offer alternative methods to display captions beneath your post images:
- JavaScript Image Captions from 1976 Design
This method automatically inserts a caption based on the title of the image. - Captions for Images in Blog Posts by Blogger Tips and Tricks
This is a much simpler method, using only HTML code in the body of the post. - Image Captions with CSS and JavaScript by Ask The CSS Guy
Similar to 1976 Design's post, this article uses a combination of styling code and scripting to add a partially transparent caption over the bottom section of the image.
I hope this tutorial has been useful in explaining how you could add captions to your post images in Blogger. If you have any questions or would like to suggest further uses for this, feel free to leave your comments and suggestions below.




18 Comments:
Hi Amanda,
I like your site - very informative. I have been trying to find a way to stop the display errors in Safari with my image captions (I use divs)
http://growlingdoggames.blogspot.com
I also previewed this page in Safari and there seems to be a problem with the Left aligned image and caption in your post above. Is there some trick to getting things to display in Safari? My stuff seems to be ok in IE/Firefox.
Cheers
Julian
Ok, well I found that by putting the caption text before the image (using your method here) it seems to solve the problem. End result is you have caption over the image but it still looks cool (and seems to work in Safari).
Ciao
For Julian,
Thank you for letting me know about this problem in Safari. Unfortunately I don't have access to this browser for testing, so I always appreciate it when readers can tell me if there are problems with this.
I'm glad to know that the captions above images works well for you.
Thanks and best wishes,
Amanda
Amanda,
For cross browser testing when you don't have access to a 100 browsers and platforms is http://www.browsershots.org - that is what we use over @ askTheAdmin!
Hope that helps you out a little.
Warm Geeky Regards,
"TheAdmiN"
Hi Amanda,
I've used your Stylized Caption for my blog and it works fine in Firefox. But when I use IE, my caption which I've aligned center, has moved to the left of the caption. Is there any way to correct this?
I was having problems with the left-caption. The image would float left fine, but the caption would always be beside the image. I came up with an easy solution; perhaps this will help others too!
I added a little bit of code to the span tag:
style="width: 200px"
Just change the width to the size of your image and you'll be fine!
The center one worked great though, for some reason... Anyways, thanks again for your hard work Amanda!
I'm in the middle of a total re-design of my blogs before I re-launch with my own domain names and I was fiddling around with the captions CSS again using Amanda's original post as a reference.
Andrew I tried your width style trick and it worked like a charm mate - thanks for that! You're a legend!
This is fantastic; thanks.
Just curious: is it possible to make the captions word wrap within the length of the image instead of it pushing the border if it's too wordy?
In other words: How do you do multiple line captions?
thanks
hi, if I upload the image in Blogger, what URL do I use in the css code when Blogger doesn't give you one? thanks
Can you please clarify something else for me, do I actually need to upload the image in blogger or should the css work on its own if i am hosting the image somewhere? I get the captions but no picture if i just host the image. if i upload it to blogger as well, the image appears but i get all that html code it puts in which just seem to overide the css code. like if i use the center-caption tag the image stays to the left. Thanks
sorry for multiple posts, could this be a problem. in the layout html every time i save that first bunch of css, instead of going before that tag where I put it puts in ]]> after the css as well. it just does it automatically?
Hello?
In Blogger it works beautifully as long as I upload the picture with "none" clicked in the photo upload choices as recommended. This gives me the image always on the left side of the post though.
What if I want the picture on the right side of the post? If I upload it to be on the right, the caption floats to the left of it, not under it.
I would appreciate any help!
Hi Amanda,
Can you show me or point me to your post if available, how to make make link navigate to the right sites for logo pictures on my blog. For example the Canon learning center logo on my blog (http://digitalphotographyland.blogspot.com/)
What code do I need to add in my template's html???
Any help is really appreciate. Thanks.
My email: giahu@rocketmail.com
Works perfectly in Safari, Chrome, and Firefox. Isn't working in IE. In IE browsers it is moving all the images to the center of the page. Is there a work around to get it to work perfectly for IE?
it can be used
thanks!
Post a Comment