20

On my blog I use some CSS classes which are defined in my stylesheet, but in RSS readers those styles don't show up. I had been searching for class="whatever" and replacing with style="something: something;". But this means whenever I modify my CSS I need to modify my RSS-generating code too, and it doesn't work for a tag which belongs to multiple classes (i.e. class="snapshot accent"). Is there any way to point to my stylesheet from my feed?

2
  • Not programming related. Needs closed. Commented Jul 30, 2009 at 18:55
  • 9
    @Kelly html and xml coding certainly counts as "programming" on this site.
    – Kip
    Commented Jul 30, 2009 at 19:33

5 Answers 5

24

The popular RSS readers WILL NOT bother downloading a style sheet, even if you provide one and link to it using <?xml-stylesheet?>.

Many RSS readers simply strip all inline style attributes from your tags. From testing today, I discovered that Outlook 2007 seems to strip out all styles, for example, even if they are inline.

Good RSS readers allow a limited set of inline style attributes. See, for example, this article at Bloglines about what CSS they won't strip. From experimentation, Google Reader seems to pass through certain styles unharmed.

The philosophy of RSS is indeed that the reader is responsible for presentation. Many people think that RSS should be plain text and that CSS in RSS feeds is inappropriate. It's probably not appropriate to impose a different font on your RSS feeds. However, certain types of content (for example, images floated on the left, with captions positioned carefully) require a minimal amount of styling in order to maintain their semantic meaning.

3
  • 10
    I appreciate your point, but I really tire of finding "don't do it" answers to questions here. Use a comments for commentary, the real answer is found in one of the links below: mondaybynoon.com/2006/08/14/beginning-to-style-your-rss-feed petefreitag.com/item/208.cfm Also, just for context. I'm using the Micrososft WCF REST Starter Kit which returns help documentation in Atom format. Since that only works for Internet Explorer (nice) this, to me, is a legitimate question. Commented Aug 23, 2010 at 21:21
  • 4
    If a question deserves a "don't do it" answer, then a "don't do it" answer it shall be. Commented Nov 7, 2011 at 8:37
  • 1
    It's fine that readers strip the CSS out, but I think it's appropriate to have an RSS stylesheet for users viewing it in the browser. Chrome is especially ugly displaying RSS feeds, and it might throw off user who are not web savvy Commented Mar 19, 2013 at 18:35
8

The point of RSS is to be display agnostic. You should not be putting style attributes on your feed.

4
  • 1
    But this leaves some of the content looking broken to anyone viewing it in their aggregator.
    – Kip
    Commented Sep 23, 2008 at 2:45
  • Broken how? It should just be text and maybe images - how can this get broken?
    – Geoff
    Commented Sep 23, 2008 at 5:10
  • 5
    You might, for example, have an image with a caption below it which is meant to appear with float:right. Without styles, the text for the caption appears inline, losing semantic meaning. Commented Dec 20, 2008 at 5:13
  • @JoelSpolsky You can do this with tables and that works in the Firefox RSS reader at least.
    – Jay Brunet
    Commented Oct 15, 2013 at 0:20
3

I found this blog post that describes how to add style to your RSS feed.

4
  • Just because you can dosen't mean you should. Techniques like this can break RSS many readers.
    – Geoff
    Commented Sep 23, 2008 at 1:57
  • Actually most RSS readers just ignore linked style sheets, so this method doesn't work. Do you know of any RSS readers that are actually BROKEN by this method? Commented Dec 20, 2008 at 5:14
  • 1
    The original blog post was talking about people who wanted a style sheet to display their RSS if the user navigated directly to the XML file in a browser, so that naive users wouldn't click on the orange <RSS> thingy and get confused. Today all major browsers do something intelligent with RSS. Commented Dec 20, 2008 at 5:15
  • 1
    And five-and-a-half years after the comments above, Chrome has much bigger market share ... and still shows XML files as blank pages. Commented Jul 9, 2014 at 6:41
2

Because RSS is (supposed to be) XML, you can use XML stylesheets.

http://www.w3.org/TR/xml-stylesheet/

1
  • 2
    This will not be picked up by any popular RSS readers, as far as I can tell. Commented Dec 20, 2008 at 5:11
2

The purpose of an RSS feed is to allow the easy transmission of content to places outside your site. The whole idea is that the content within the feed is format-free, so that it can be read by any piece of software. The program that is reading the your feed is in charge of how to present it visually. For example, if you had a website that read RSS, you would want to parse the feed into HTML, and style it that way. However, if you were building a desktop application to read the feed, you would implement the formatting quite differently.

Not the answer you're looking for? Browse other questions tagged or ask your own question.