Making Your RSS Feed Look Pretty in a Browser
by Ben Hammersley07/01/2005
As more and more non-techie websites offer syndication feeds, a growing number of non-technical readers are clicking on the links and filling their screens with confusing XML. The current method of subscribing to a feed--copying the URL from the link and pasting it into your newsreader application--isn't obvious to the new user. Filling their screens with markup or malformed text doesn't help endear your readers to your site's new feature.
But syndication content doesn't have to look like geeky markup or malformed text in your browser. You can make it look quite pretty, and give clues to what the feed is actually for.
How It Works
To make your RSS feed look pretty, you add a stylesheet to the feed. There are two types of stylesheets you could use here. The first, using XSL, is more complicated, but does give the potential for some powerful features; you could convert links within the feed into clickable links in the browser, for example.
The second, which we will explore here, uses CSS. CSS can't do anything but change the display of the feed, but it's much simpler, and most web designers know at least a little CSS.
In these examples, we will concentrate on skinning an RSS 2.0 feed. For RSS 1.0 and Atom feeds, the technique is exactly the same, but with different element names, as you will see.
To start off, we need to provide a pointer within the RSS feed to the stylesheet itself. Here I've called the stylesheet rss.css, and have it hosted at http://www.example.com.
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css"
href="http://www.example.com/rss.css" ?>
Add that line to your RSS feed's template, save it, and rebuild the page (or whatever your own system needs to do).
Creating the Stylesheet
Remember, the simplest possible RSS 2.0 feed is this:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css"
href="http://www.example.com/rss.css" ?>
<rss version="2.0">
<channel>
<title>The Simplest Feed</title>
<link>http://example.org/index.html</link>
<description>The Simplest Possible RSS 2.0 Feed</description>
<item>
<description>Simple Simple Simple</description>
</item>
</channel>
</rss>
First, we tell the browser to display all of the elements and define the typeface:
* {
display: block;
}
Then we give everything a nice margin. Notice how we're using the :root CSS
selector here, and not the rss element.
:root {
margin: 50px;
}
Now we want to put the feed's name in big letters in the middle of the screen.
channel > title {
font-size: x-large;
text-align: center;
}
Here's the cunning bit. We want to tell people that they are not looking at a real web page, just a rendition of a feed. Here we use the advanced features of CSS to place a message after the title. I've styled it as a big grey box with the writing in the middle:
channel > title:after {
display: block;
padding: 50px;
content: "This is an RSS feed, designed to be read in an RSS application.";
background-color: grey;
color: white;
}
With the warning out of the way, we can display some of the information found in the RSS news items.
item {
margin: 25px 0 20px 0;
}
item > title {
font-size: medium;
margin-bottom: 20px;
}
item > link {
font-size: small;
margin-top: 6px;
margin-bottom: 6px;
}
item > description {
font-size: small;
}
item > pubDate {
font-size: small;
}
Of course, the feeds also contain a lot of other information. I don't want to display that stuff, so we use CSS to turn it off.
channel > link,
channel > copyright,
channel > lastBuildDate,
channel > generator,
channel > docs,
language,
lastBuildDate,
ttl,
guid,
category {
display: none;
}
Here's the complete code:
* {
display: block;
}
:root {
margin: 50px;
}
channel > title {
font-size: x-large;
text-align: center;
}
channel > title:after {
display: block;
padding: 50px;
content: "This is an RSS feed, designed to be read in an RSS application.";
background-color: grey;
color: white;
}
item {
margin: 25px 0 20px 0;
}
item > title {
font-size: medium;
margin-bottom: 20px;
}
item > link {
font-size: small;
margin-top: 6px;
margin-bottom: 6px;
}
item > description {
font-size: small;
}
item > pubDate {
font-size: small;
}
channel > link,
channel > copyright,
channel > lastBuildDate,
channel > generator,
channel > docs,
language,
lastBuildDate,
ttl,
guid,
category {
display: none;
}
Final Thoughts
This technique is, of course, as hackable as CSS itself. Real CSS wizards can make RSS feeds look very beautiful indeed. The one downside to using CSS is that the links aren't clickable. Using XSLT instead of CSS would allow this. Indeed, XSLT would allow you to create a site made entirely out of RSS or Atom. But that is for another article.
![]() |
Essential Reading What Are Syndication Feeds
Table of Contents
Syndication feeds have become a standard tool on the Web. But when you enter the world of syndicated content, you're often faced with the question of what is the "proper" way to do syndication. This edoc, which covers Atom and the two flavors of RSS--2.0 and 1.0--succinctly explains what a syndication feed is, then gets down to the nitty-gritty of what makes up a feed, how you can find and subscribe to them, and which feed will work best for you. Read Online--Safari Search this book on Safari: |
Ben Hammersley is by day a mild-mannered author of Content Syndication with RSS, by night Crime Fighter. Ben Hammersley lives in Florence, Italy and at www.benhammersley.com.
Return to the O'Reilly Network
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 7 of 7.
-
Not working in Opera?
2006-08-08 22:32:41 Comp.Misc [Reply | View]
I guess :root doesn't work with Opera... Why?
-
RSS feeds
2006-02-17 10:21:47 horacion [Reply | View]
Hello,
I am new to RSSPublishing.
I recently came across a magazine showing how to do it.
I downloaded RSSPublisher from www.ykoon.nl and followed the steps to create the feed, headlines and publish it.
I went ok, or so I think.
But my problem is that now I would like to promote the RSS URL by listing it with different syndication sites, BUT i do not know the exact RSS URL.
I never received any email indicating that the feed was published, nor showing me the exact RSS URL
How do I do to know it?
Where do I find the RSS feed?
I already downloaded the corresponding RSSReader ... just for you to know.
What should the structure of the RSS URL be? meaning ... I am familiar with http://www. but how the RSS feed looks like?
Thank you in advance for your cooperation.
Horacio
-
Why use the :root CSS selector?
2005-07-09 10:07:52 mjross99 [Reply | View]
:root {
margin: 50px;
}
Why use the :root CSS selector, and not the rss element? The latter works fine. Any advantage to the :root CSS selector?
-
Making RSS pretty
2005-07-03 17:00:04 seanburke [Reply | View]
More along these lines:
http://interglacial.com/~sburke/stuff/pretty_rss.html
-
RSS 1.0?
2005-07-02 21:10:27 Chirael [Reply | View]
This doesn't seem to work with RSS 1.0 files. Should it, or is this a RSS 2.0 only thing?
-
User barrier
2005-07-02 20:51:00 Chirael [Reply | View]
Yeah, you're totally right about non-techie users clicking on the XML or RSS button and going "Um, what the hell is this?"
In fact, I posted in my blog recently asking people to check out a feed recently and someone responded with, "When I click on the link, I just get a bunch of code."
This is really pretty user unfriendly IMO and will be a barrier to widespread adoption of RSS for non-techies.
I'd like to make the XML/RSS button be a link to a page that explains RSS and has the actual links to the syndication feed files.
However, I'm afraid that others users who have things like bookmarklets will see the XML/RSS button and just hit subscribe, and their aggregators will be confused because there is no direct link to the RSS file, just to the page explaining syndication, which itself has links to the feed files.
I don't think there's a good answer, but I think the better user experience is to have the RSS/XML button link to a page explaining what syndication is for non-techies, which then has links to the actual feed files.
Just dumping people to a page full of code (data, really) is a poor user experience, even if you do make it slightly prettier (and someone who doesn't know what the data is isn't going to know what an "RSS Application" is, so that doesn't really help them).
-
User barrier
2005-07-04 04:08:40 bazzargh [Reply | View]
Take a look at the BBC's feeds, which do exactly that.
they take pains to explain to the user what they've clicked on without being overly intrusive if you know what you did. Nice job.







