Astro · web framework

On this page 7

Astro is an open-source web framework for building content-driven websites that renders pages to static HTML by default and sends JavaScript to the browser only for components that need interactivity. In the field of web applications, it is best known for popularizing the islands architecture, in which small interactive regions sit inside otherwise static pages.

Astro is UI-agnostic: a single project can use components written in React, Vue.js, Svelte, Solid or Preact alongside its own .astro component format. It supports static site generation, server-side rendering through adapters for many hosting platforms, and a hybrid of both, which makes it a common choice for documentation, blogs, marketing sites and e-commerce storefronts.

How Astro renders pages

Astro treats the server as the default place to render, whether that happens at build time or on each request. An .astro file has a component script between code fences, which runs only on the server, and an HTML-like template below it. The script can fetch data, read files or query a database, and none of that code reaches the browser.

The output of a page is plain HTML and CSS, with zero client-side JavaScript unless a developer explicitly asks for it. Astro scopes component styles automatically, bundles assets with Vite and uses file-based routing, so a file at src/pages/blog/index.astro becomes the /blog/ route. This zero-JavaScript baseline explains why Astro sites often score well on Core Web Vitals without special tuning.

The table below shows the main rendering modes and when each fits.

ModeWhen HTML is producedBest fit
Static (prerendered)Once, at build timeBlogs, documentation, marketing pages
On-demand (server)On every request via an adapterPersonalized or frequently changing pages
Mixed per routeStatic by default, selected routes on demandMostly static sites with a few dynamic pages
Server islandsPage cached, one component rendered laterStatic pages with personalized fragments
Astro rendering modes

Islands architecture and client directives

An island in Astro is a framework component that is hydrated independently of the rest of the page. A React carousel or a Svelte search box is rendered to HTML on the server and, only when marked with a client directive, receives its JavaScript in the browser. Each island loads and hydrates on its own, so a slow widget does not delay the rest of the page.

Directives give fine control over when hydration happens, which is the main lever for performance. The table compares them.

DirectiveHydration timingTypical use
client:loadImmediately on page loadCritical controls above the fold
client:idleWhen the main thread becomes idleSecondary widgets
client:visibleWhen the component enters the viewportComments, carousels, footers
client:mediaWhen a CSS media query matchesMobile-only menus
client:onlyClient rendering with no server HTMLComponents that need browser APIs
Client directives that control hydration

Islands do not share a component tree, so passing state between islands requires a small shared store, custom events or a library such as nanostores. Props passed to an island must also be serializable, because they travel from the server to the browser inside the HTML.

Astro compared with other web frameworks

Astro sits between classic static site generators and full single-page application frameworks. Its closest neighbors in practice are Next.js, Nuxt and SvelteKit, which also render on the server but treat the page as one hydrated application by default. The comparison below reflects default behavior, since every framework can be configured toward the others.

FrameworkDefault client JavaScriptUI libraryPrimary strength
AstroNone unless islands are markedAny supported libraryContent-heavy sites
Next.jsReact runtime for the appReact onlyLarge React applications
NuxtVue runtime for the appVue.js onlyFull-stack Vue applications
SvelteKitSmall compiled Svelte runtimeSvelte onlyLightweight interactive apps
Default behavior compared with related frameworks

The key difference is the unit of hydration. Next.js with React Server Components reduces shipped code but still hydrates a shared React tree, whereas Astro hydrates isolated islands with no common runtime between them. For an application where nearly every element is interactive, that isolation brings little benefit.

Content collections and the build pipeline

Astro includes content collections, a typed system for Markdown, MDX, JSON or YAML content. A schema defined with the Zod validation library checks every entry’s front matter at build time, so a missing date or misspelled field fails the build instead of the live page. Content loaders can also pull entries from a headless CMS or an API into the same typed interface.

The build pipeline relies on Vite for bundling and hot module replacement during development. Image handling optimizes formats and sizes at build time, and integrations add framework renderers, sitemaps, Tailwind CSS or adapters for platforms such as Node.js servers and edge runtimes. View transitions between pages can be enabled with a built-in router component that uses the browser’s View Transitions API where available.

When Astro is the wrong choice

Astro is optimized for sites where content matters more than interaction, and its trade-offs appear when that balance flips. Highly interactive dashboards, collaborative editors or apps with complex client-side routing gain little from islands and may become harder to structure than in a single framework.

Project typeFitReason
Documentation or blogStrong fitMostly static content with few widgets
Marketing site with formsStrong fitSmall islands for forms and menus
Storefront with dynamic cartGood fitStatic catalog plus cart island or server island
Real-time dashboardWeak fitNearly all content is interactive
Offline-first appWeak fitHeavy client state and routing
Choosing whether Astro fits a project
  • Mixing many UI libraries on one page increases total JavaScript, because each library ships its own runtime.
  • Overusing `client:load` cancels the performance advantage that islands provide.
  • Server-only code in the component script cannot react to browser events after the page loads.

The idea in brief

Astro is a tool for building websites that load fast because they send very little code. It prepares most of each page in advance, so the browser receives ready-made text and images.

Only the parts that must react to clicks, such as a search box or a photo slider, get extra code. Think of a printed newspaper with a few small touchscreens glued into it: most of the page is simple paper, and only the screens need power.

A practical scenario

A software company rebuilt its product documentation, about 600 pages, which had been a React single-page application. Readers on slow mobile connections waited several seconds for the full application bundle before any text appeared, even though almost every page was static text.

The team moved the pages into an Astro content collection with a schema for titles, versions and categories. Only two components stayed interactive: the search dialog, hydrated with client:idle, and a code sample tab switcher, hydrated with client:visible. Most pages now ship no JavaScript at all, the text renders as soon as the HTML arrives, and broken front matter is caught during the build. The documentation became noticeably faster on mobile devices while the writers kept working in Markdown.