Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

How to Add an RSS Feed to an Astro Blog

An RSS feed lets readers follow your blog in a feed reader. Install @astrojs/rss, add one small file, add one tag to your layout, and your feed is live.

Tested on Astro 7.4

Cover image for How to Add an RSS Feed to an Astro Blog
In this guide
  1. Step 1: Install the package
  2. Step 2: Tell Astro your web address
  3. Step 3: Make the feed file
  4. Step 4: Help apps find your feed
  5. Step 5: Build and check the feed
  6. Make it better
  7. Where to go next
  8. Frequently asked questions

An RSS feed is a list of your newest posts that reader apps can follow. In Astro you add one with the official @astrojs/rss package and one small file. Astro turns that file into rss.xml when it builds your site. One extra tag in your layout helps apps find it.

Step 1: Install the package

In your project folder:

npm install @astrojs/rss

Step 2: Tell Astro your web address

A feed needs full links, like https://yoursite.com/blog/hello-world/. So Astro needs to know your address. Open astro.config.mjs and add site:

// @ts-check
import { defineConfig } from 'astro/config';

export default defineConfig({
  site: 'https://example.com',
});

Use your real address. Keep anything else that was already in the file.

Step 3: Make the feed file

Create src/pages/rss.xml.js:

import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';

export async function GET(context) {
  const posts = await getCollection('posts');
  return rss({
    title: 'My Blog',
    description: 'New posts from my Astro site',
    site: context.site,
    items: posts.map((post) => ({
      title: post.data.title,
      pubDate: post.data.date,
      link: `/blog/${post.id}/`,
    })),
  });
}

Here’s what’s going on:

  • The file name rss.xml.js makes a page at /rss.xml. The .js part goes away.
  • getCollection('posts') gets every post.
  • title and description describe your whole blog. Change them.
  • items is one entry per post. Each one has a title, a date, and a link.
  • post.id is the post’s file name without .md. So hello-world.md links to /blog/hello-world/.

If your posts live at a different address, change the link line to match.

Step 4: Help apps find your feed

Open your layout. Inside <head>, add this tag:

<link
  rel="alternate"
  type="application/rss+xml"
  title="My Blog"
  href={new URL('rss.xml', Astro.site)}
/>

Now when someone pastes your home page into a reader app, the app finds the feed by itself.

Step 5: Build and check the feed

npm run build
Terminal
$ npm run build
19:28:59   ├─ /rss.xml (+17ms)
19:28:59 [build] Complete!

Those are the last two lines of our build. The feed is a page like any other.

Open dist/rss.xml. It starts like this:

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>My Blog</title>
<description>New posts from my Astro site</description><link>https://example.com/</link>
<item><title>A walk by the river</title><link>https://example.com/blog/a-walk-by-the-river/</link>

We added line breaks so it fits. In the real file it’s one long line. That’s normal.

You can also run npm run dev and open localhost:4321/rss.xml. Some browsers show the code. Some offer to download it. Both mean it works.

We ran this on a fresh Astro 7.4 project with five posts. The feed had all five, each with a full link and a date. The tag showed up in the head of every page.

Building with Claude? Paste this guide into Claude Code and ask it to do it for you.

Make it better

  • Add a summary. If your posts have a description field, add description: post.data.description, to each item. Reader apps show it under the title.
  • Newest first. Most reader apps sort by date on their own. If you want the file in order too, sort posts by date before the map.
  • Check it. Paste your live feed address into the W3C Feed Validator after you publish.

Where to go next

Frequently asked questions

What is an RSS feed for?

It's a list of your newest posts in a format apps can read. People add your feed to a reader app, like Feedly, and see new posts without visiting your site.

Why do I get "Invalid URL" when I build?

Your site address is missing. Add site with your full web address to astro.config.mjs. The feed needs it to make full links.

Does the Astro blog template already have a feed?

Yes. If you started from the blog template, open src/pages/rss.xml.js. It's already there.

Stuck on a step?

Check the common errors guide, look up a word in the glossary, or ask the friendly people in the official Astro and EmDash Discords. How to ask so people can help.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astronursery.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add a Contact Form to an Astro Site (No Server Needed)

    A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

    Tutorials, 7 minute read, November 8, 2026

Try "blog", "deploy" or "EmDash".