Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

How do I add spacing to images in my RSS feed?

I'm pulling out my hair! I want to include images in my blog entries and have those images show up in the RSS feed too, but either I end up with no image showing up at all, or I end up with the text abutting the image, which looks terrible. What's the best practice with this, Dave?


Dave's Answer:

I read almost 200 different RSS feeds every day with NewsGator Online and know exactly what you mean. Even the best, biggest sites have similar problems because either they don't remember that RSS feeds are read in other programs or because they don't know enough CSS or HTML to tweak the layout.

For example, here's a nice example of how the otherwise splendid GigaOm blog has spacing problems with its RSS feed:

GigaOm RSS Image Spacing Problems

Clearly it would be more attractive if there were just a few additional pixels of blank space around the edge of the image, and that's easily accomplished either in HTML or, better, using Cascading Style Sheets.

You include an image in your blog posting through a tag like this:

<img src="some url" />

I strongly -- strongly -- recommend that you always specify alt text too, ideally describing exactly what the image is about. This helps both with people who can't or don't want to load images (think "ADA Compliant") and it also helps with search engine ranking too. My image above, for example, includes the following: alt="GigaOm RSS Image Spacing Problems".

If you want to have the text wrap around the graphic, you're probably also adding align="right" or align="left" depending on your desired layout and appearance. Add these two in, and your image inclusion's a bit more complex:

<img src="URL" alt="alt text" align="right" />

That's a typical way to get a graphic on the page and, if it's in the part of your blog entry that's included in your RSS feed, in the RSS feed too. But what if you want to add a bit of spacing?

There are two ways to add spacing to an image. Within the world of HTML, you can add horizontal and/or vertical spacing with the hspace and vspace attributes, respectively. The unit of measure is pixels and the value is applied to both sides, so specifying hspace="8" will add 8 pixels of blank space on both the left and right of the image.

The more sophisticated solution is to use CSS, however, because you have greater control. If you want to have that 8 pixels of space around all four sides, for example, use margin:8px;, but if you really only want the right and bottom edges to have the extra spacing, you can do that with margin-right: 8px; margin-bottom: 8px;. Note carefully my use of colons and semicolons.

Dropping CSS into an HTML tag is done with the style attribute, so here's our completed example image that includes an additional 8 pixels of space around it:

<img src="URL" alt="alt text" align="right" style="margin:8px;" />

You can do that, right? :-)

What about missing images?

the other problem, and one that I see in RSS feeds with alarming frequency, is that the image is completely missing when the feed is viewed. Sometimes this is just a transient server problem, but mostly it's due to a lack of specifying a fully qualified URL.

Your blog articles can include partial URLs like "/images/neatpic33.jpg" without an issue, they show up fine when people read your blog by visiting your site, but without a domain name specified, the RSS readers just don't know what to do and can't deliver the image where you want it.

The fix is easy: Always specify the http:// material in any blog image reference.

On the image inclusion above, just by way of example, here's the actual HTML code I am using:

<img src="http://www.askdavetaylor.com/0-blog-pics/gigaom-rss-image-error.png" alt="GigaOm RSS Image Spacing Problems" />

Rather a long URL, but I'm confident it'll work regardless of how this blog entry is referenced.

That's all there is to it. I hope you find this helps you tweak your RSS feed to meet your aesthetic desires!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

I am carefully noting your use of colons and semicolons and wanted to point out that there are two semicolons that aught to be colons. One in the "margin-right" style statement and one in the URL portion of "the fix is easy".

Posted by: Ben Zvan at October 19, 2006 12:46 PM

(sound of me slapping my forehead)

Doh! Thanks for the note, Ben. I've fixed it all up.

Posted by: Dave Taylor at October 19, 2006 1:19 PM

re. fully qualified URL for img src
Q: Are you aware of any restriction on the URL length for img src attribute?

Posted by: tl at February 20, 2008 10:05 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]