Getting Started with Astro 5: The Ultimate Guide
Discover how Astro 5 revolutionizes static site generation with Content Layer, Server Islands, and superior performance.
Listen to Article
PlayingClick play to listen to audio narration

Table of Contents
Astro 5 introduces groundbreaking features designed to make web development faster, simpler, and more flexible. Whether you are building a personal blog, a documentation portal, or an e-commerce platform, Astro deliver exceptional performance by default.
Why Choose Astro 5?
Astroβs signature feature is its Islands Architecture, which renders HTML on the server and isolates interactive components so only necessary JavaScript is delivered to the browser.
Key Features of Astro 5:
- Content Layer: Fetch content from any source (local markdown, CMS, API) using unified loaders.
- Server Islands: Combine static rendering with dynamic user-tailored components seamless server-side execution.
- Actions: Type-safe server actions built directly into the framework.
---
// Example Astro Component
const title = "Hello from Astro 5!";
---
<main>
<h1>{title}</h1>
<p>Zero JavaScript delivered by default!</p>
</main>
Setting Up Your First Project
Getting started takes less than two minutes:
npm create astro@latest
Follow the interactive prompts to choose a starter template, configure TypeScript, and install dependencies.
Conclusion
Astro 5 sets a new standard for modern web architecture. By combining zero-JS defaults with modern framework flexibility, it gives developers the best of both worlds.
Prerequisites
- Node.js β₯ 18.17.1 (v22 recommended)
- A package manager: npm, pnpm, or yarn
- Basic knowledge of HTML and JavaScript
Creating Your First Project
# Create a new Astro project
npm create astro@latest my-site
# Change into the new directory
cd my-site
# Start the development server
npm run dev
The development server starts at http://localhost:4321 by default.
Project Structure
my-site/
βββ public/ # Static assets (images, fonts, robots.txt)
βββ src/
β βββ components/ # Reusable .astro components
β βββ layouts/ # Page layouts (shell, header, footer)
β βββ pages/ # File-based routing β every file is a URL
β βββ content/ # Content collections (Markdown/MDX files)
βββ astro.config.mjs # Astro configuration
βββ package.json
Understanding Islands Architecture
Astro renders everything to HTML at build time. JavaScript is only sent for components that opt in with a client: directive:
---
import StaticCard from './StaticCard.astro'; // No JS
import LiveChart from './LiveChart.jsx'; // JS only when needed
---
<StaticCard /> <!-- Pure HTML -->
<LiveChart client:visible /> <!-- Hydrates when scrolled into view -->
<LiveChart client:load /> <!-- Hydrates immediately on page load -->
<LiveChart client:idle /> <!-- Hydrates when browser is idle -->
Content Collections with Content Layer
Astro 5 introduces the Content Layer API for type-safe content with any data source:
// src/content.config.ts
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
loader: glob({ base: './src/content/blog', pattern: '**/*.{md,mdx}' }),
schema: z.object({
title: z.string(),
pubDate: z.coerce.date(),
description: z.string().optional(),
tags: z.array(z.string()).default([]),
}),
});
export const collections = { blog };
Access collection entries in your pages:
---
import { getCollection } from 'astro:content';
const posts = await getCollection('blog');
---
<ul>
{posts.map(post => (
<li><a href={`/blog/${post.id}`}>{post.data.title}</a></li>
))}
</ul>
Server Islands (Astro 5)
Server Islands allow individual components to render server-side on demand β even on an otherwise static page:
---
import UserGreeting from '../components/UserGreeting.astro';
---
<p>Welcome to Syntaxis.</p>
<!-- This section renders dynamically per request -->
<UserGreeting server:defer>
<span slot="fallback">Loading...</span>
</UserGreeting>
Use Server Islands for: personalised content, real-time data, session-aware widgets.
Deploying
Astro outputs static files to dist/ by default. Deploy to any static host:
npm run build # Outputs static site to dist/
npx astro preview # Preview the production build locally
Supported deployment targets include Vercel, Netlify, Cloudflare Pages, and AWS S3 + CloudFront with zero additional configuration.
Written by Editorial Team
Tech contributor covering software architecture, AI research, cloud infrastructure, and systems engineering practices.