Getting Started with Astro: A Modern Web Framework for Content-Rich Sites

September 24, 2025

Picture this: you’re building a blog or documentation site, and you want it to be blazingly fast. You’ve tried traditional frameworks like React or Vue, but they’re shipping too much JavaScript to the browser. Your Lighthouse scores are suffering, and users are bouncing because of slow load times.

If this sounds familiar, you’re not alone. Many developers face this exact problem when building content-rich websites. The solution? Astro - a modern web framework that’s revolutionizing how we think about web performance.

What Makes Astro Different?

Astro introduces a revolutionary approach called the “Islands Architecture”. Instead of shipping entire applications to the browser, Astro sends mostly static HTML and CSS, with interactive “islands” of JavaScript only where needed.

Think of it like this: if your website is a city, traditional frameworks ship the entire city infrastructure to every visitor. Astro, on the other hand, sends just the map and adds interactive features (like traffic lights or elevators) only where they’re actually needed.

This approach delivers several key benefits:

  • Lightning-fast performance: Minimal JavaScript means faster load times
  • Better SEO: Server-side rendering with static HTML
  • Framework flexibility: Use React, Vue, Svelte, or vanilla JavaScript
  • Developer experience: Modern tooling with excellent TypeScript support

Getting Started with Astro

Let’s dive into setting up your first Astro project. The process is straightforward and well-documented.

Installation

Astro provides a convenient CLI tool that guides you through project creation:

$ yarn create astro

This command will:

  1. Ask for your project name
  2. Let you choose a template (blog, portfolio, docs, etc.)
  3. Configure TypeScript support
  4. Set up your preferred UI framework (React, Vue, Svelte, or none)

For a quick start, you can also create a project with specific options:

$ yarn create astro my-astro-site --template blog --typescript strict

Project Structure

Once created, your Astro project will have this structure:

my-astro-site/
├── src/
│   ├── components/     # Reusable UI components
│   ├── layouts/        # Page layouts
│   ├── pages/          # File-based routing
│   └── styles/         # Global styles
├── public/             # Static assets
├── astro.config.mjs    # Astro configuration
└── package.json

The beauty of Astro lies in its simplicity. The src/pages/ directory uses file-based routing, so src/pages/about.astro automatically becomes /about.

Your First Astro Component

Astro components use a unique syntax that combines HTML, CSS, and JavaScript in a single file:

---
// Component script (runs at build time)
const name = "Fernando";
const currentYear = new Date().getFullYear();
---

<div class="welcome">
  <h1>Welcome to Astro, {name}!</h1>
  <p>Built in {currentYear}</p>
</div>

<style>
  .welcome {
    padding: 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
  }
  
  h1 {
    margin: 0 0 1rem 0;
    font-size: 2rem;
  }
</style>

Notice the --- delimiters? That’s the frontmatter section where you write JavaScript that runs at build time. This is where Astro’s magic happens - your JavaScript executes on the server, not in the browser.

Adding Interactivity

When you need client-side interactivity, Astro provides several options:

1. Client Directives

Add interactivity to any component with client directives:

---
import Counter from '../components/Counter.jsx';
---

<Counter client:load />

The client:load directive tells Astro to hydrate this component immediately when the page loads. Other options include:

  • client:idle - Hydrate when the browser is idle
  • client:visible - Hydrate when the component enters the viewport
  • client:media - Hydrate based on media queries

2. Multiple Framework Support

One of Astro’s standout features is its ability to use multiple frameworks in the same project:

---
import ReactComponent from '../components/ReactComponent.jsx';
import VueComponent from '../components/VueComponent.vue';
import SvelteComponent from '../components/SvelteComponent.svelte';
---

<div>
  <ReactComponent client:load />
  <VueComponent client:idle />
  <SvelteComponent client:visible />
</div>

This flexibility is perfect for teams transitioning between frameworks or using the best tool for each specific component.

Building a Blog with Astro

Let’s create a practical example - a simple blog setup:

1. Create a Blog Layout

---
// src/layouts/BlogLayout.astro
export interface Props {
  title: string;
  description?: string;
}

const { title, description = "My Astro Blog" } = Astro.props;
---

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{title}</title>
    <meta name="description" content={description} />
  </head>
  <body>
    <header>
      <nav>
        <a href="/">Home</a>
        <a href="/blog">Blog</a>
        <a href="/about">About</a>
      </nav>
    </header>
    
    <main>
      <slot />
    </main>
    
    <footer>
      <p>&copy; 2024 My Astro Blog</p>
    </footer>
  </body>
</html>

2. Create Blog Posts

---
// src/pages/blog/first-post.astro
import BlogLayout from '../../layouts/BlogLayout.astro';
---

<BlogLayout title="My First Astro Post" description="Learning Astro step by step">
  <article>
    <h1>My First Astro Post</h1>
    <p>This is my first blog post built with Astro!</p>
    
    <p>Astro makes it incredibly easy to create fast, content-rich websites.</p>
  </article>
</BlogLayout>

3. Add Content Collections

For a more sophisticated blog, use Astro’s content collections:

// src/content/config.ts
import { defineCollection, z } from 'astro:content';

const blog = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    description: z.string(),
    date: z.date(),
    tags: z.array(z.string()).optional(),
  }),
});

export const collections = { blog };

Then create your posts as markdown files:

---
title: "Getting Started with Astro"
description: "Learn the basics of Astro framework"
date: 2024-12-19
tags: ["astro", "tutorial"]
---

# Getting Started with Astro

Astro is a modern web framework...

Development and Deployment

Local Development

Start the development server:

$ yarn dev

Astro provides:

  • Hot Module Replacement (HMR) for instant updates
  • TypeScript support out of the box
  • Built-in dev tools for debugging

Building for Production

$ yarn build

This creates an optimized dist/ folder with:

  • Minified HTML, CSS, and JavaScript
  • Optimized images and assets
  • Static files ready for deployment

Deployment Options

Astro works with virtually any hosting platform:

  • Netlify: Zero-config deployment
  • Vercel: Excellent integration with Astro
  • GitHub Pages: Perfect for open source projects
  • Cloudflare Pages: Global edge deployment

For Netlify deployment, simply connect your repository and add this configuration:

# netlify.toml
[build]
  command = "yarn build"
  publish = "dist"

Why Choose Astro?

After working with Astro on several projects, I’ve found it particularly compelling for:

Content-heavy websites: Blogs, documentation sites, and marketing pages benefit enormously from Astro’s performance-first approach.

Multi-framework teams: If your team uses different frameworks, Astro allows everyone to contribute using their preferred tools.

SEO-critical projects: The combination of static generation and minimal JavaScript makes Astro ideal for projects where search engine visibility matters.

Performance budgets: When every millisecond counts, Astro’s islands architecture delivers measurable improvements.

Next Steps

Ready to dive deeper into Astro? Here’s what I recommend:

  1. Explore the official tutorial: The Astro tutorial provides hands-on experience building a complete blog
  2. Try different integrations: Experiment with React, Vue, or Svelte components
  3. Learn about content collections: For dynamic content management
  4. Explore view transitions: Add smooth page transitions to your site
  5. Check out the ecosystem: Browse Astro integrations for CMS, analytics, and more

Astro represents a significant shift in how we think about web performance. By prioritizing static content and adding interactivity only where needed, it delivers the speed users expect while maintaining the developer experience we want.

The framework is still evolving rapidly, with version 5 recently released, bringing even more performance improvements and developer experience enhancements. If you’re building content-rich websites and haven’t tried Astro yet, I highly recommend giving it a shot.

References


Profile picture

Written by Fernando Nogueira a Brazilian software engineer who lives and works remotely from Spain.