Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Practical Astro
Lesson Plan
  1. Content Systems
    1. Introduction
    2. An import alias
    3. Using Markdown
    4. Markdown extended
    5. Markdown component
    6. Markdown component in frameworks
    7. Content collections made easy
    8. Basic blogs
    9. Blogs made easy
    10. Prev/Next navigation
    11. Pagination made easy
    12. Better tag pages
    13. Paginated tag pages
    14. Markdown layouts
    15. Partials
    16. JS over JSON Data
    17. Dynamic 404 pages
    18. Putting everything together
    19. Other useful systems
  2. Image Systems
    1. Introduction
    2. Images are complicated because of this
    3. Astro's Image component
    4. Astro's Picture component
    5. Improvements over Astro's Image and Picture Components
    6. Images in Markdown and MDX
    7. Images in framework components
    8. Background images
    9. Art Direction with Astro
    10. Videos without layout shifts
    11. GIF Replacements and background video
    12. SVGs and icons
    13. SVG backgrounds
    14. Adding noise to images
    15. Asset caching on GitHub Actions
    16. Putting everything together
    17. Other useful systems

Basic blogs

2m:41s

Let’s begin by creating a basic scaffold for a blog, so you can compare the difference between a basic blog and the blog format I’m going to show you.

Basic blog anatomy

All blogs need the following 5 properties:

  1. title
  2. a permalink (usually with the slug attribute)
  3. description
  4. tags
  5. a published date

The most basic blogs will put all these properties in the frontmatter.

my-awesome-post.md
---
title: 'My awesome post'
slug: my-awesome-post
description: 'Description for my awesome post'
tags: ['tag 1', 'tag 2']
pubDate: '2026-02-24'
---

But slug is not necessary in this case because the file name contains the same information. So we can omit it.

my-awesome-post.md
---
title: 'My awesome post'
description: 'Description for my awesome post'
tags: ['tag 1', 'tag 2']
pubDate: '2026-02-24'
---

This is the anatomy of a basic blog.

Static rendering

Blogs should be hosted on static pages because they contain content that doesn’t get changed. They don’t need to be placed behind a server. By using static pages, you also get the benefits of using a CDN.

In the same line of thought, most content on a page can be static. So set the output for Astro to static.

astro.config.mjs
export default defineConfig({
// ...
output: 'static',
})

Basic blog scaffold

You can choose where you want your blog to be, but most people will put it under pages/blog. We’ll do that too.

We’ll create a [slug].astro file that will output the static pages. This [slug] is a placeholder value which we have to populate with getStaticPaths. We will also set slug to the id of each entry from the blog collection.

src/pages/blog/[slug].astro
---
export const prerender = false // optional if output is static
// Creates these static pages
export async function getStaticPaths() {
const posts = await getCollection('blog')
return posts.map((post, index) => {
return {
params: { slug: post.id }, // Sets the [slug] param.
props: { post }, // Gives you post in Astro.props
}
})
}
---

Astro will then create one page for every post found in the blog collection. Each of these pages will live at /blog/[slug].

The content from the page can be retrieved by using the props we returned in getStaticPaths. Since this post is an entry from a content collection, we can use render to get the contents within.

src/pages/blog/[slug].astro
---
import { render } from 'astro:content'
export getStaticPaths() { /* ... */}
// Content on the [slug] page
const { post } = Astro.props
const { Content } = await render(post)
---
<article>
<h1>{post.data.title}</h1>
<Content />
</article>

This is a scaffold you need for the most basic blogs.

Code snippets to copy paste

Here’s everything you need to create basic blog pages.

src/pages/blog/[slug].astro
---
import { getCollection, render } from 'astro:content'
export const prerender = false // optional if output is static
export async function getStaticPaths() {
const files = await getCollection('blog')
return files.map((post, index) => {
return {
params: { slug: post.id },
props: { post },
}
})
}
const { post } = Astro.props
const { Content } = await render(post)
---
<article>
<h1>{post.data.title}</h1>
<Content />
</article>