Getting Started with Astro: A Modern Static Site Generator

Getting Started with Astro: A Modern Static Site Generator

Learn how to build fast, modern websites with Astro's unique approach to static site generation and component islands.

Ali Mozhdekanlou
January 15, 2024
Updated: January 20, 2024
Astro JavaScript Static Sites Web Development

Getting Started with Astro

Astro is a modern static site generator that’s changing how we think about web performance. Unlike traditional frameworks, Astro ships zero JavaScript by default, only adding interactivity where you need it.

What Makes Astro Special?

Astro’s “component islands” architecture allows you to use any framework (React, Vue, Svelte) while keeping your site fast and lightweight. The framework only hydrates components that actually need interactivity.

Key Features

  • Zero JavaScript by default - Only ships what you need
  • Framework agnostic - Use React, Vue, Svelte, or plain HTML
  • Built-in optimizations - Image optimization, CSS bundling, and more
  • Developer experience - TypeScript support, hot module replacement

Getting Started

npm create astro@latest
cd my-astro-site
npm install
npm run dev

Building Your First Component

Astro components use a unique .astro syntax that combines HTML, CSS, and JavaScript:

---
// Component script (runs at build time)
const name = "World";
---

<div class="greeting">
  <h1>Hello {name}!</h1>
</div>

<style>
  .greeting {
    color: blue;
  }
</style>

Conclusion

Astro represents a new paradigm in web development, prioritizing performance without sacrificing developer experience. Whether you’re building a blog, documentation site, or complex web application, Astro provides the tools you need to create fast, modern websites.

Start your Astro journey today and experience the future of web development!