Digital Inspiration

about    faq    contact

Add Text Captions To Your Web Images with CSS; Drive More Traffic

html image captionsWebsites like BBC or The New York Times always display images and pictures inside a box that is aligned either to the right or left of the web page. (see screenshot on the right)

You’ll also notice a 1-2 sentence long text caption just below the photograph containing brief description of the image, copyright information, etc.

There are two advantages of adding image captions in web pages:

1. Stylish and Read Friendly - Your visitors can easily get the context of the image from the small caption without having to read the full story.

2. SEO Friendly - Since captions describe the image in text and are located in close proximity to the image, they could be very effective in getting your images rank well on image search engines.

How to Add Text Captions and Align Images on Web Pages ?

With simple CSS and HTML, you can quickly add text captions to images very similar to BBC or Wikipedia:

Before we get into the code, here’s a snapshot of the end product. The Google logo is aligned to the right of the browser, is enclosed inside a box with borders that also contains a text caption.

 css images and text captions 

Here’s the HTML+CSS code for the above implementation:

Step 1: Add the following CSS code to an external CSS file or to your blog template under the <HEAD> section.

<style type="text/css">
.picture { background-color: #F9F9F9;
border: 1px solid #CCCCCC; padding: 3px;
font: 11px/1.4em Arial, sans-serif; }
.picture img { border: 1px solid #CCCCCC;
vertical-align:middle; margin-bottom: 3px; }
.right { margin: 0.5em 0pt 0.5em 0.8em; float:right; }
.left { margin: 0.5em 0.8em 0.5em 0; float:left; }
</style>

Step 2: Now insert the following HTML code anywhere in the web page. The process is exactly the same as inserting regular images but we have just enclosed that inside a <DIV> tag.

<div class="picture left" style="width:278px;"> <img src="google.gif" width="276" height="120" alt="Google Logo" /> <br />Image Caption goes here. </div>

In the above example, we add the file google.gif left aligned and the image has dimensions 276×120.

Replace left with right if you want to right align the image box. You’ll also need to modify the style:width of the <DIV> tag such it is equal to image width + 2.

You can also fiddle with the CSS to change the font name, size, border colors, background, margins, etc.

Also read - "Useful HTML Tricks for Bloggers"

Email This   Print Article   Save as PDF   Subscribe   Translate 

Published on February 19, 2008 under Internet, Web Design
Tags: , , , ,

Recommended Google Software:

You may also like to read ..

 · Add Text To Photographs; Online Image Editor
 · CSS Text Painting of George W. Bush - No Images, Only HTML
 · The Best Companion Tools for YouTube and other Web Videos
 · Add Humorous Captions and Graphics to Any Photo on Any Website
 · Adobe Photoshop Express Is Live At photoshop.com/express

Reader Comments

#1 Ayush Saran 02.19.08

If you add a display:block to

.picture img { border: 1px solid #CCCCCC;
vertical-align:middle; margin-bottom: 3px; }

you will not need the tag in the div, and your layout wont break if you forget it.

#2 Ayush Saran 02.19.08

im referring to eliminating the <br /> tag

#3 Vinayak 02.20.08

Thanks for the simple and great hack!

#4 Gadgets 03.04.08

There must be plugin available for wordpress for simplifying that task.

#5 SaTiSh MeDoS 03.10.08

Lucid explanation.Thank You

#6 Jeannie S 04.11.08

Hey, thanks. I was wondering how to implement something like this gracefully into my regular php pages.

#7 adam 05.05.08

Amit, I was begging my brother, who is professional programmer to help me with including pictures into my ‘beginners’ blog to look better and more controllable, but he didn’t want to loose time with me. He just said: ‘leave it, far too complicated for you.’ You explained exactly the same in just a a few sentences…Thank you again!
p.s.
I am going to email him this link to show to him, how very easy it could be explanation, if a person really knows the subject.

Add a Comment

If you have a question that is not related to the above discussion, please post your question in the message board for quick answers. All comments are moderated.



 

Joing the Facebook Group

Visit Help Central

 

© 2008 Digital Inspiration - Technology, à la Carte | Mobile Edition | Videos | Terms

The articles are copyrighted to Amit Agarwal and can only be reproduced given the author's permission.

My Google  Netvibes  My Yahoo!  Windows Live  Bloglines  Newsgator  

Skip to top of the page ^^