Welcome to HowToShipIt — practical how-to guides for developers: code, AI tools, and servers, explained step by step.

Astro 7: The Complete Guide to the Astro Framework (2026)

If your site is mostly content — a blog, docs, a marketing site, a portfolio — you are probably shipping far more JavaScript than the page needs. The Astro framework is built on the opposite idea: render everything to plain HTML on the server, ship zero JavaScript by default, and add interactivity only where you explicitly ask for it. This guide walks you through Astro 7, the current major release of the Astro framework, from your first project to content collections, islands, routing, and deployment — with copy-paste code at every step.

What is the Astro framework?

Astro describes itself, in its own documentation, as “the web framework for building content-driven websites”. Where React, Next.js, SvelteKit, and Nuxt were built to render whole applications in the browser, Astro starts from a different assumption: most of a real page is content, not application state, so the framework’s default output is plain, static HTML with no JavaScript shipped at all — unless you deliberately ask for some.

Three ideas define how it works:

  • Content-driven. Astro is designed around showcasing content. Blogs, documentation, marketing pages, and portfolios are its home turf.
  • Server-first. Pages render on the server (at build time, by default) and the browser receives finished HTML. Client-side rendering is an opt-in you add per component, not the default you have to fight.
  • UI-agnostic. Astro components are framework-free, but you can drop in React, Preact, Svelte, Vue, or Solid components on the same page — even several frameworks at once.

The practical result is a site that loads like a static page because, by default, that is exactly what it is. A blog post built with Astro ships no framework runtime to the browser.

Astro is also a safer bet than it was a year ago. In January 2026, The Astro Technology Company joined Cloudflare, and Astro remains open source and MIT-licensed, with the same team working on it full-time.

Last verified: 20 November 2026. Astro 7.4.13 is the current release; Astro 7.0 shipped on 22 June 2026.

What’s new in Astro 7

Astro 7, released on 22 June 2026, is a speed release. The component format, the islands architecture, and the routing model are all the same as Astro 6 — what changed is what sits underneath. If you learned Astro from a tutorial written before June 2026, this section keeps you out of trouble, because several of those tutorials are now subtly wrong.

  • Rust compiler for .astro files. The component compiler was rewritten in Rust, replacing the old Go-based compiler. It is mostly backwards compatible, but it is stricter: it no longer silently “corrects” your HTML by reordering elements or auto-closing tags. Unclosed tags and unterminated attributes are now errors, and whitespace between elements is collapsed following JSX conventions.
  • Sätteri: Markdown and MDX in Rust. Astro 7 replaces the default Markdown and MDX pipeline with Sätteri, a Rust-powered processor. GFM features, smart punctuation, heading IDs, container directives, math, and frontmatter are now built in instead of requiring separate remark or rehype plugins. If you depend on a specific remark or rehype plugin, install @astrojs/markdown-remark to keep the old unified pipeline.
  • Vite 8 and Rolldown. Astro 7 upgrades to Vite 8, whose headline change is Rolldown — a Rust-based bundler that replaces both esbuild and Rollup while supporting the same plugin API.
  • Queued rendering is stable. The queue-based rendering engine, experimental in Astro 6, is now the default — Astro reports it is roughly 2.4× faster than the old recursive renderer.
  • Builds are 15–61% faster. That is Astro’s own benchmark range, measured on real production sites on a MacBook Pro with an M4 Pro chip. Markdown-heavy sites see the biggest gains.
  • Route caching is stable, with experimental CDN cache providers for Netlify, Vercel, and Cloudflare.
  • Advanced Routing. A new src/fetch.ts entrypoint gives you full control over Astro’s request pipeline, using the standard fetch handler pattern from Cloudflare Workers, Deno, and Bun.
  • Astro DB is deprecated. The astro db, astro login, astro logout, astro link, and astro init CLI commands have been removed. If an old tutorial tells you to run one of them, it predates Astro 7.
  • Newer point releases keep landing. Astro 7.4 (October 2026) added an astro build --timings flag and raised the minimum supported Node.js version to 22.22.0.

Set up your first Astro project

You need Node.js 22.22 or newer — Astro 7.4 raised the minimum. Check yours first:

node --version
# v22.22.0 or newer

Then scaffold a project:

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

The dev server starts at http://localhost:4321. Three commands cover it: npm run dev for local development, npm run build to produce the production site in dist/, and npm run preview to serve that production build locally before you deploy it.

How .astro components work

An .astro file has two parts. A component script between --- fences runs on the server at build time (or per request, for on-demand pages), and the HTML-like template below it is what the browser receives. There is no client-side runtime for an .astro component — it renders to HTML and stops.

---
// This runs on the server. Fetch data, import components,
// do anything Node can do — none of it reaches the browser.
import Layout from '../layouts/Layout.astro';
import { getCollection } from 'astro:content';

const posts = await getCollection('blog');
const featured = posts.filter((post) => post.data.featured);
---

<Layout title="Latest posts">
  <ul>
    {featured.map((post) => (
      <li><a href={`/blog/${post.id}/`}>{post.data.title}</a></li>
    ))}
  </ul>
</Layout>

A few rules make the syntax click:

  • Expressions go in curly braces. Anything inside {} in the template is JavaScript — variables, .map() calls, ternaries, logical && for conditional rendering.
  • Props arrive on Astro.props. Destructure them in the frontmatter, and add a Props interface for free type checking: const { title, description } = Astro.props;
  • <slot /> is where children go. A layout renders the content passed between its opening and closing tags wherever you put a <slot />.
  • Styles are scoped by default. A <style> block inside an .astro file only applies to that component. Add is:global when you genuinely want a rule to escape.

Islands architecture: JavaScript only where you ask for it

The term “component island” was coined by Etsy’s frontend architect Katie Sylor-Miller in 2019 and expanded by Preact creator Jason Miller in 2020. Astro was the first mainstream framework to build selective hydration in as the default — the technique is also called partial hydration.

By default, Astro renders every UI component — including React, Vue, and Svelte components — to plain HTML and strips out all client-side JavaScript. Turning one into an interactive island takes a single client:* directive:

---
import SearchBox from '../components/SearchBox.tsx';
import CommentThread from '../components/CommentThread.tsx';
import NewsletterSignup from '../components/NewsletterSignup.tsx';
---

<!-- Interactive immediately: above the fold, needed at once -->
<SearchBox client:load />

<!-- Hydrates when the browser goes idle -->
<NewsletterSignup client:idle />

<!-- JavaScript isn't even downloaded until this scrolls into view -->
<CommentThread client:visible />

There are five directives:

Directive When it hydrates Best for
client:load Immediately on page load Navigation, search, cart — anything above the fold
client:idle When the browser fires requestIdleCallback Visible but non-urgent widgets
client:visible When the component enters the viewport (IntersectionObserver) Below-the-fold islands: comments, carousels, maps
client:media When a CSS media query matches Viewport-conditional UI: mobile drawer, desktop sidebar
client:only="react" Immediately, and skips server rendering entirely Components that touch window or localStorage

Two details catch beginners out. First, directives only work on framework components — an .astro component never hydrates, so give it a plain <script> tag if it needs behaviour.

There is also a second kind of island. A server island renders its dynamic content on the server, separately from the rest of the page, so a slow personalised component never blocks the static shell around it:

---
import Avatar from "../components/Avatar.astro";
---

<!-- Renders in parallel; the page shows a fallback until it's ready -->
<Avatar server:defer />

Server islands are the right tool for a logged-in user’s avatar or a personalised greeting on an otherwise static page. The outer page stays aggressively cacheable while the dynamic piece renders on demand.

Content collections: your blog’s typed database

If you are building a blog or docs site, content collections are the feature that will save you the most debugging time. A collection is a set of related files with a schema that validates every entry at build time, so a typo in frontmatter becomes a build error instead of a broken page in production.

Collections live in one file, src/content.config.ts, and are defined with defineCollection():

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

const blog = defineCollection({
  loader: glob({ base: './src/content/blog', pattern: '**/*.{md,mdx}' }),
  schema: z.object({
    title: z.string(),
    description: z.string(),
    pubDate: z.coerce.date(),
    updatedDate: z.coerce.date().optional(),
    draft: z.boolean().default(false),
    tags: z.array(z.string()).default([]),
  }),
});

export const collections = { blog };

Astro ships two built-in loaders: glob() for directories of Markdown, MDX, JSON, YAML, or TOML files, and file() for a single file holding an array of entries (each object needs a unique id). Community loaders cover headless CMSs and databases, and you can write a custom loader for anything else.

Querying is one function call, with full TypeScript autocompletion on the frontmatter you just validated:

---
import { getCollection } from 'astro:content';

const posts = await getCollection('blog', ({ data }) => !data.draft);
const sorted = posts.sort(
  (a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
);
---

To turn each entry into a page, pair the collection with a dynamic route and getStaticPaths():

---
// src/pages/blog/[...slug].astro
import { getCollection, render } from 'astro:content';

export async function getStaticPaths() {
  const posts = await getCollection('blog');
  return posts.map((post) => ({
    params: { slug: post.id },
    props: { post },
  }));
}

const { post } = Astro.props;
const { Content } = await render(post);
---

<h1>{post.data.title}</h1>
<Content />

One more thing worth knowing: Astro 6 added live collections for data that changes too often to rebuild for — stock levels, CMS previews, user-specific content. They fetch at request time, so they cannot render MDX or optimise images. Use build-time collections whenever you can.

Routing, pages, and view transitions

Routing is file-based: every file in src/pages/ becomes a URL route, so src/pages/about.astro is /about and src/pages/blog/[...slug].astro is a catch-all dynamic route driven by getStaticPaths().

For app-like navigation, add Astro’s <ClientRouter /> component to your shared layout’s <head>:

---
import { ClientRouter } from "astro:transitions";
---

<head>
  <ClientRouter />
</head>

That one line intercepts link clicks and gives you smooth page transitions (the default is a crossfade, with fade, slide, and none built in), with a graceful fallback in browsers without View Transition API support. Fine-tune it with transition:name, transition:animate, and transition:persist, or add data-astro-reload to any link that should force a full page load instead.

One naming trap for older tutorials: the component used to be called <ViewTransitions />. It was renamed to <ClientRouter /> in Astro 5, and the old name was removed in Astro 6.

Going dynamic: adapters and on-demand rendering

So far everything has been static, and a static Astro site needs no adapter: astro build writes HTML, CSS, and JavaScript to dist/, and any host that serves files can serve it. You only need an adapter when some code must run per request — on-demand pages, server islands, Actions, sessions, or endpoints that are not prerendered.

Astro maintains four official adapters, one per deploy target:

Adapter Package Best for
Node.js @astrojs/node Any Node.js server: VPS, container, PaaS
Cloudflare @astrojs/cloudflare Workers and Pages, KV, D1, R2 bindings
Netlify @astrojs/netlify Netlify Functions and Edge Functions
Vercel @astrojs/vercel Vercel serverless and edge functions

Install one with a single command — npx astro add node, cloudflare, netlify, or vercel — which updates astro.config.mjs for you. Then choose how much of your site renders on demand:

// astro.config.mjs — everything on demand by default
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';

export default defineConfig({
  output: 'server',
  adapter: node({ mode: 'standalone' }),
});

With output: 'server', every page renders per request unless it opts back into prerendering. The more common pattern for a mostly-static site is the reverse: keep the default static output and opt individual pages out with export const prerender = false. Either way, the adapter only changes what happens to the pages you mark dynamic.

Deploy your Astro site

For a static site, deployment is almost boring, and that is the point. Run npm run build, publish the dist/ folder, and you are done. Cloudflare Pages, Netlify, and Vercel all detect Astro automatically when you connect a Git repository: confirm the build command (npm run build) and the output directory (dist/), and every push deploys. Set Node.js to 22.x in your host’s settings if its default image is older — Astro 7 will not build on anything below 22.22. Two details to know first: GitHub Pages project sites need site and base set in astro.config.mjs, and if you added an adapter, deploy through that adapter’s host integration.

Astro vs Next.js: which one for your site?

This is the comparison every Astro guide gets asked for, and the honest answer is that the two frameworks barely overlap. Astro is a multi-page, server-first framework for content; Next.js is a full-stack React framework for applications. Pick by what the site has to do at request time:

Astro Next.js
Default output Static HTML, zero JavaScript React Server Components; client runtime ships with the page
Best for Blogs, docs, marketing sites, portfolios Dashboards, SaaS apps, anything with heavy client state
Content layer Built in: content collections with Zod schemas None built in — wire up your own Markdown/MDX pipeline
UI frameworks Any: React, Vue, Svelte, Solid, Preact — mixed on one page React only

Developers who run both in production tend to land on the same rule of thumb: if the site is mostly pages, build it on Astro; if the site is also an application — auth-gated content, dashboards, a CRM behind the marketing pages — build it on Next.js. Neither choice is wrong; they answer different questions. If almost nothing on your site has to happen at request time, Astro’s zero-JavaScript default is free performance you would otherwise have to engineer by hand. For the other side of the fence, see our Next.js middleware guide and React 19.3 guide.

6 mistakes beginners make with Astro

1. Putting client:load on everything. The moment every island hydrates on load, you have rebuilt the monolithic hydration waterfall Astro exists to avoid. Default to no directive, then add client:idle or client:visible and reserve client:load for above the fold.

2. Relying on the old compiler to fix your HTML. Astro 7’s Rust compiler treats your markup as-is. Unclosed tags and unterminated attributes are errors now, not things the compiler quietly patches.

3. Bringing remark/rehype plugins to Sätteri. Astro 7’s default Markdown pipeline is Rust, not unified — if your site depends on a remark or rehype plugin, install @astrojs/markdown-remark.

4. Forgetting the adapter. A page with export const prerender = false, a server island, or an Action needs an adapter, or the build stops with a “no adapter installed” error. A fully static site needs none — but the moment anything renders on demand, add one with npx astro add.

5. Fetching content with import.meta.glob(). It works, but you lose the whole point of collections: schema validation, type-safe frontmatter, and a query API.

6. Building on old Node. Astro 7.4 requires Node 22.22 or newer. If your CI image or host still defaults to Node 20, the build fails before it starts — pin 22.x in your host settings and in your CI config.

Should you learn Astro in 2026?

If you build content sites — blogs, docs, marketing pages, portfolios, programmatic SEO — yes, and the case is stronger now than it was a year ago. Two major releases in 2026 rebuilt the internals in Rust and made builds dramatically faster, the Astro framework is backed by Cloudflare while staying MIT-licensed and platform-agnostic, and the mental model is simpler: HTML first, JavaScript only where you ask for it, content validated by a schema at build time.

Start small: scaffold a project with npm create astro@latest, build one blog with a content collection, add a single client:visible island, and deploy the static output.

Further Reading & References

Leave a Comment