top of page

How to Custom Code an RSS Feed Into Your Web Page Step by Step

Aug 25
9 min read

A good RSS feed is like a quiet delivery service for the web. New posts, podcast episodes, product updates, press releases, or documentation changes can appear on your page without anyone copying and pasting them by hand.


RSS, short for Really Simple Syndication, is an XML format that lets websites publish a list of recent content. Each entry usually includes a title, link, publication date, description, and sometimes an image or author. Feed readers use RSS to help people follow sites, but your website can use it too.


Adding an RSS feed to a web page can help you:


  • Keep a page fresh with recent articles or updates

  • Pull news from one of your own blogs into another part of your site

  • Show podcast episodes, changelog notes, or event posts

  • Reduce manual content updates

  • Give visitors a quick path to your newest material


The fun part is that you do not need a large framework to start. With plain HTML, CSS, and JavaScript, you can build a simple feed display and then improve it from there.


Wide-angle view of a tablet showing a simple feed list beside a notebook on a wooden workbench
RSS feeds turn changing content into a reusable source for your page.

Know what you are building before you write code


An RSS feed is usually found at a URL that ends in something like `/feed`, `/rss`, `.xml`, or `/feed.xml`. WordPress sites often publish feeds automatically. Many blogs, podcast platforms, news sites, documentation tools, and CMS platforms do the same.


A basic RSS item often looks like this:


```xml

<item>

<title>New Guide to Spring Gardening</title>

<link>https://example.com/spring-gardening</link>

<pubDate>Mon, 12 May 2025 10:00:00 GMT</pubDate>

<description>A short summary of the article.</description>

</item>

```


Your web page will do three things:


  1. Request the RSS feed from its URL

  2. Parse the XML response

  3. Turn each feed item into HTML


That sounds technical, but the first version is straightforward.


There is one catch to know early: some RSS feeds cannot be loaded directly in a browser because of CORS rules. CORS, or Cross-Origin Resource Sharing, controls whether one website can request files from another domain. If the feed allows browser access, client-side JavaScript works well. If it blocks access, you will need a small server-side helper, which we will cover later.


Step 1. Choose the RSS feed you want to display


Start with a feed you are allowed to use. If it is your own site, this is simple. If it belongs to another publisher, check their terms and avoid copying full articles unless they clearly allow it.


Open the feed URL in your browser. You may see raw XML, or your browser may show a styled feed preview. Either is fine.


Look for these fields:


  • `title`

  • `link`

  • `pubDate`

  • `description`


Some feeds use Atom instead of RSS. Atom is similar, but its tags differ. For this tutorial, we will start with RSS. Once you understand the pattern, you can adapt the code for Atom feeds too.


A good test feed should have several recent items and valid XML. If the feed does not load in your browser at all, fix that before writing any page code.


Step 2. Add a feed container to your HTML


Create a place on your page where the feed will appear. Keep the HTML simple and accessible.


```html

<section class="rss-widget" aria-labelledby="rss-heading">

<h2 id="rss-heading">Latest Updates</h2>


<p id="rss-status" class="rss-status">Loading updates...</p>


<ul id="rss-feed" class="rss-list"></ul>

</section>

```


This gives your script two key targets:


  • `rss-status`

    A short message for loading or errors


  • `rss-feed`

    The list where feed items will go


The section can sit on a homepage, sidebar, resource page, dashboard, or landing page. You can also create more than one widget if you want to show multiple feeds.


Close-up view of handwritten XML tags and a small laptop screen with a web preview
Start by identifying the parts of the feed you want to show.

Step 3. Style the feed with CSS


The feed should look like part of your site, not a pasted block of technical output. Here is a clean starter style.


```css

.rss-widget {

max-width: 720px;

margin: 2rem auto;

padding: 1.5rem;

border: 1px solid #ddd;

border-radius: 12px;

background: #fff;

}


.rss-widget h2 {

margin-top: 0;

font-size: 1.5rem;

}


.rss-status {

color: #666;

}


.rss-list {

list-style: none;

margin: 0;

padding: 0;

}


.rss-item {

padding: 1rem 0;

border-top: 1px solid #eee;

}


.rss-item:first-child {

border-top: 0;

}


.rss-item a {

font-weight: 700;

color: #1a5fb4;

text-decoration: none;

}


.rss-item a:hover,

.rss-item a:focus {

text-decoration: underline;

}


.rss-date {

display: block;

margin-top: 0.25rem;

color: #666;

font-size: 0.9rem;

}


.rss-description {

margin: 0.5rem 0 0;

color: #333;

line-height: 1.5;

}

```


This CSS gives each item a clear title, readable date, and short description. You can adjust colors, spacing, and borders to match your site.


Step 4. Fetch and parse the RSS feed with JavaScript


Now add the JavaScript. This version uses the browser’s built-in `fetch()` method and `DOMParser`.


```html

<script>

const feedUrl = "https://example.com/feed.xml";

const itemLimit = 5;


const feedList = document.getElementById("rss-feed");

const statusMessage = document.getElementById("rss-status");


async function loadRssFeed() {

try {

const response = await fetch(feedUrl);


if (!response.ok) {

throw new Error("The feed could not be loaded.");

}


const xmlText = await response.text();

const parser = new DOMParser();

const xml = parser.parseFromString(xmlText, "application/xml");


const parseError = xml.querySelector("parsererror");

if (parseError) {

throw new Error("The feed contains invalid XML.");

}


const items = Array.from(xml.querySelectorAll("item")).slice(0, itemLimit);


if (items.length === 0) {

statusMessage.textContent = "No feed items found.";

return;

}


statusMessage.textContent = "";

feedList.innerHTML = "";


items.forEach((item) => {

const title = item.querySelector("title")?.textContent || "Untitled";

const link = item.querySelector("link")?.textContent || "#";

const pubDate = item.querySelector("pubDate")?.textContent || "";

const description = item.querySelector("description")?.textContent || "";


const listItem = document.createElement("li");

listItem.className = "rss-item";


const anchor = document.createElement("a");

anchor.href = link;

anchor.textContent = title;

anchor.target = "_blank";

anchor.rel = "noopener noreferrer";


const date = document.createElement("time");

date.className = "rss-date";


if (pubDate) {

const formattedDate = new Date(pubDate).toLocaleDateString("en-US", {

month: "short",

day: "numeric",

year: "numeric"

});


date.textContent = formattedDate;

date.dateTime = new Date(pubDate).toISOString();

}


const summary = document.createElement("p");

summary.className = "rss-description";

summary.textContent = stripHtml(description).slice(0, 180);


listItem.appendChild(anchor);


if (pubDate) {

listItem.appendChild(date);

}


if (description) {

listItem.appendChild(summary);

}


feedList.appendChild(listItem);

});

} catch (error) {

statusMessage.textContent = "Sorry, the feed is unavailable right now.";

console.error(error);

}

}


function stripHtml(html) {

const temporaryElement = document.createElement("div");

temporaryElement.innerHTML = html;

return temporaryElement.textContent || temporaryElement.innerText || "";

}


loadRssFeed();

</script>

```


Replace `https://example.com/feed.xml` with your real RSS feed URL.


This is the core of how to custom code an RSS feed into a page. The script loads the feed, finds the first few `item` entries, and creates safe HTML elements for each one.


Step 5. Keep the code safer and cleaner


RSS descriptions often contain HTML. They can include links, images, paragraphs, or encoded characters. Avoid dropping raw feed content directly into your page with `innerHTML`, especially when the feed comes from another site.


The example above uses `textContent` for the title and description after stripping HTML. That keeps the first version safer and easier to control.


If you want to show images or full HTML descriptions later, add a sanitizing library or process the feed on your server before it reaches the browser.


A few good habits:


  • Limit the number of items

    Five to eight entries usually feels useful without overwhelming the page.


  • Open external links safely

    Use `rel="noopener noreferrer"` when links open in a new tab.


  • Show a helpful fallback

    If the feed fails, display a friendly message instead of a blank area.


  • Cache when possible

    For busy pages, repeated direct feed requests can slow things down. A server-side cache can help.


Eye-level view of a chalkboard showing a simple flow from RSS XML to HTML cards
Mapping the flow makes the code easier to understand.

Step 6. Handle feeds that fail because of CORS


If your browser console shows an error mentioning CORS, your JavaScript is probably fine. The feed server is blocking direct browser requests from your domain.


You have three common options.


Use a feed from the same domain

Add server-side code

Use a trusted feed API

Best when you control the source website

Best for custom sites and more control

Best when you want less maintenance


A small server-side helper fetches the feed from your server instead of the visitor’s browser. Your page then requests your own endpoint.


Here is a simple PHP example for a site that supports PHP:


```php

<?php

header("Content-Type: application/xml; charset=UTF-8");


$allowedFeeds = [

"updates" => "https://example.com/feed.xml"

];


$key = $_GET["feed"] ?? "updates";


if (!array_key_exists($key, $allowedFeeds)) {

http_response_code(400);

echo "Invalid feed.";

exit;

}


$feedUrl = $allowedFeeds[$key];

$feedContent = file_get_contents($feedUrl);


if ($feedContent === false) {

http_response_code(502);

echo "Feed unavailable.";

exit;

}


echo $feedContent;

```


Then your JavaScript can use your local endpoint:


```js

const feedUrl = "/rss-proxy.php?feed=updates";

```


The allowlist matters. Do not create an open proxy that fetches any URL a visitor provides. That can create security and abuse problems.


Step 7. Test the feed on real pages


Once the feed appears, test it like any other site feature.


Check these items:


  • The feed loads on desktop and mobile screens

  • Titles link to the right pages

  • Dates display correctly in US format

  • Long titles wrap neatly

  • Empty descriptions do not create awkward gaps

  • The error message appears if the feed URL is wrong

  • The browser console has no unexpected errors


Also test what happens when the feed updates. Publish a test post if you control the source, or wait until the source adds a new item. Your widget should show the newest content without code changes.


Troubleshoot common RSS feed problems


Even simple RSS widgets can run into small issues. Most are easy to trace.


The page says the feed is unavailable


Check the feed URL first. Open it in the browser and confirm it loads.


If it loads in the browser but not on your page, check the console for CORS errors. If you see one, use a server-side proxy or another approved feed source.


The feed loads but no items appear


Your feed may use Atom instead of RSS. RSS uses `item`, while Atom often uses `entry`.


For Atom, you would look for entries like this:


```js

const items = Array.from(xml.querySelectorAll("entry"));

```


Atom links also work differently. The URL may be stored in an `href` attribute:


```js

const link = item.querySelector("link")?.getAttribute("href") || "#";

```


The descriptions look messy


Descriptions can contain HTML, encoded characters, image tags, or long text. Start by showing plain text only. Then trim the length.


```js

summary.textContent = stripHtml(description).slice(0, 120) + "...";

```


For a more polished version, trim by word count instead of character count so you do not cut words in half.


The dates say Invalid Date


RSS dates are not always formatted the same way. Most standard feeds work with JavaScript’s `Date` object, but some custom feeds use unusual formats.


Add a date check before displaying it:


```js

const dateObject = new Date(pubDate);


if (!isNaN(dateObject)) {

date.textContent = dateObject.toLocaleDateString("en-US");

}

```


The widget slows down the page


A browser request to an outside feed can be delayed by that feed’s server. If speed matters, fetch the RSS feed on your own server and cache the result for a short time.


This also gives you more control over formatting, sanitizing, and error handling.


How different websites use RSS feeds well


RSS is older than many web trends, but it still solves real problems. Here are practical ways different sites use it.


News and magazine sites often provide section-based feeds. A visitor might follow technology, local news, food, or sports without subscribing to every article from the publication.


Blogs and personal sites use RSS so readers can follow new posts in a feed reader. A site owner can also display recent posts from a blog on the homepage.


Podcast websites rely on RSS heavily. Podcast apps use feeds to find episode titles, audio files, show notes, and release dates.


Documentation sites use feeds for changelogs and release notes. This helps developers and users spot recent changes without searching through docs manually.


Schools, libraries, and community groups can use RSS for announcements, event updates, reading lists, or news from related organizations.


Ecommerce sites sometimes use feeds for new arrivals, product updates, or sale announcements. The feed display can point visitors to fresh items without rebuilding a section by hand.


These examples all share the same idea: a feed turns repeated updates into structured content that other pages and tools can reuse.


Overhead view of printed cards labeled news, podcast, changelog, and events arranged around an RSS symbol
RSS can support many types of changing content.

Ideas for improving your custom RSS widget


After your first version works, experiment. Small changes can make the feed more useful.


You could add:


  • Category labels when the feed includes categories

  • A thumbnail image if the feed provides media tags

  • A “View all updates” link below the list

  • A loading skeleton instead of plain loading text

  • Tabs for multiple feeds

  • A filter for topics or tags

  • Server-side caching for better speed

  • A manual refresh button


If you add images, check how the feed stores them. Some use `media:content`, some place images inside the description, and others use custom fields. Feed formats vary, so inspect the XML before writing the code.


A custom RSS feed display does not need to be perfect on day one. Start with titles, links, and dates. Then add summaries, images, styling, and caching as your needs grow.


A simple success checklist


Before you ship your RSS widget, confirm that it does the basics well:


  • It loads the correct feed

  • It shows a useful number of recent items

  • It handles errors politely

  • It does not inject unsafe HTML

  • It looks good on mobile

  • It does not depend on a feed you are not allowed to reuse

  • It still works when a feed item is missing a date or description


When these pieces are in place, your page has a living content block instead of a static list. That is the real value of RSS. It gives your site a simple, durable way to stay current.


Start with the sample code, swap in your feed URL, and test one change at a time. Once you see your own updates appear automatically, you will probably find more places where RSS can save time and make your site more useful.


 
 
 

Comments


bottom of page