Getting Started with Astro
A practical, no-fluff introduction to building your first site with Astro, from project setup to your first component.
Astro is a framework built around a simple idea: most websites don’t need to ship a full JavaScript application to the browser. This guide walks through setting up a project and building your first page and component.
Why Astro
Astro renders HTML on the server (or at build time) by default, and only sends JavaScript to the browser for the pieces that actually need interactivity. That means faster page loads without giving up components, TypeScript, or a modern developer experience.
Creating a new project
Run the official setup script from your terminal:
npm create astro@latest my-site
cd my-site
npm install
npm run dev
This scaffolds a project, installs dependencies, and starts a local dev server, usually at http://localhost:4321.
Understanding the file structure
A fresh Astro project looks roughly like this:
my-site/
├── src/
│ ├── components/
│ ├── layouts/
│ └── pages/
├── public/
└── astro.config.mjs
Anything in src/pages automatically becomes a route. A file at src/pages/about.astro is served at /about, with no router configuration required.
Your first component
Astro components use a .astro file with two sections: a fenced code block at the top (the “component script”) and markup below it.
---
const greeting = "Hello, Astro";
---
<h1>{greeting}</h1>
Anything inside the fenced block runs at build time, not in the browser. That’s what keeps the shipped JavaScript minimal.
Adding content collections
For anything content-heavy (blog posts, docs, products) Astro’s content collections give you typed, validated frontmatter. Define a schema once in src/content/config.ts, and Astro will warn you at build time if a Markdown file’s frontmatter doesn’t match it.
Deploying
Astro builds to static HTML by default, which means it can be hosted almost anywhere: Cloudflare Pages, Netlify, Vercel, or a plain file server. Run npm run build and deploy the generated dist/ folder.
Where to go next
From here, the natural next steps are adding Tailwind CSS for styling, wiring up a content collection for a blog, and exploring Astro’s island architecture for the handful of components that do need client-side interactivity.
Affiliate disclosure
Some links in this article are affiliate links. If you buy something through them, we may earn a commission at no extra cost to you. This never affects which products we choose to cover or how we rate them. Read our full affiliate disclosure.
Written by
David OseiSenior Developer & Tutorials Lead
David writes the programming tutorials on Fieldnote. He builds and ships web projects for a living, and writes the guide he wishes he'd had the first time he tried each tool.
Newsletter
Get new field notes in your inbox.
Related articles
Notion vs. Obsidian: Which Should You Use in 2026?
Both are excellent note-taking tools built on very different philosophies. Here's how to decide which one fits the way you actually work.
What the New Core Web Vitals Update Means for Publishers
Search engines have adjusted how page experience factors into rankings. Here's what actually changed, and what to prioritize.
10 AI Tools Worth Trying in 2026
From writing assistants to code generation, these are the AI tools that have earned a permanent spot in our workflow this year.