Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is Astro?

Learn what Astro is, how it ships zero JavaScript by default, what islands and content-first design mean, and when to choose it for a site.

Astro is a web framework for building fast, content-focused websites: blogs, documentation, marketing pages, portfolios and stores. Its central idea is simple: render your pages to HTML ahead of time and send as little JavaScript to the browser as possible. Pages that only need to show text, images and links should not pay the cost of a full client-side application.

In this lesson you will learn what makes Astro different from other frameworks, the vocabulary you will see throughout this course, and how to decide whether Astro is the right tool for your next project.

The real Astro toolchain cannot run on this site, so the Astro code you see is read-only. Every lesson pairs it with small runnable JavaScript stand-ins that demonstrate the underlying ideas (rendering strings, routing tables, scheduling). They are labelled as stand-ins so you always know what is real and what is a model.

The problem Astro solves

Many popular frameworks start from the assumption that a page is an application. The browser downloads a JavaScript bundle, runs it, builds the page in memory and attaches event handlers. That is a good model for a dashboard, but it is wasteful for an article that never changes after it loads. The reader pays for the bundle in download time, parsing time and battery.

Astro flips the default. A page is HTML first. Components are rendered on the server (at build time or on request), the result is plain HTML and CSS, and the JavaScript for a component is only sent if you explicitly ask for it.

Key ideas

Astro in four ideas

HTML first Pages render to static HTML
Islands Interactive parts hydrate alone
Any UI library React, Vue, Svelte and more
Content focused Markdown and collections built in
1 / 2
  • Zero JavaScript by default. A component written for Astro renders to HTML. No runtime ships with it.
  • Islands architecture. Interactive pieces (a search box, an image carousel) are isolated "islands" in a sea of static HTML. Each island loads and starts independently. You will meet this in Islands architecture.
  • Bring your own UI framework. You can write interactive components in React, Preact, Vue, Svelte, Solid or Alpine and mix them on one page.
  • Content collections. Markdown, MDX, JSON and other data can be loaded, validated against a schema and queried with type safety. See Content collections.
  • Server rendering when you need it. Static output is the default, but adapters let you render on demand, add API endpoints and run middleware.

What an Astro page looks like

An .astro file has two parts: a script section between two lines of three dashes (the frontmatter fence) and a template below it that looks like HTML with JavaScript expressions in curly braces.

ASTRO
---
const title = "My first Astro page";
const fruits = ["apple", "pear", "plum"];
---
<html lang="en">
  <head>
    <title>{title}</title>
  </head>
  <body>
    <h1>{title}</h1>
    <ul>
      {fruits.map((fruit) => <li>{fruit}</li>)}
    </ul>
  </body>
</html>

The code in the fence runs on the server only, once per page build. It never reaches the browser. What the visitor receives is just the final HTML: a heading and three list items. That is the whole trick, and you will see it again and again.

Seeing the "HTML first" idea in code

The following program is a stand-in. It renders the same page twice as strings: once the Astro way (HTML, no script) and once as a client-rendered shell that needs a script to produce the content. Compare what the browser must download and run.

Node.js Stand-in: HTML first versus client rendered

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Notice that the shell page contains the fruit names inside a script string only. A search engine or a slow phone must execute JavaScript before anyone sees them. The static page already contains the content.

How a build turns files into a site

When you run astro build, Astro walks your project, renders every page and writes a folder of static files. The next stand-in imitates that step with a tiny in-memory "project".

Node.js Stand-in: a tiny static site build

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The real build also processes images, CSS and any scripts, but the principle is the same: source files in, a folder of ready-to-serve files out. You can upload that folder to any static host.

When Astro is a good choice

Choose Astro when:

  • Most of your pages are content: articles, docs, landing pages, product pages.
  • Performance and search ranking matter a lot.
  • You want to reuse components written in several UI frameworks or move gradually from one framework to another.
  • You prefer writing mostly HTML and CSS with a little JavaScript.

Consider something else when the whole product is one highly interactive application (an editor, a chat client, a trading screen) where almost every pixel changes in response to the user. Astro can host such an app as one large island, but a framework built around client-side state will feel more natural.

Common misunderstandings

  • "Astro is only for static sites." It starts static, but with an adapter you get server rendering, endpoints and sessions. See the later chapter on SSR.
  • "I have to learn a new UI framework." The .astro syntax is close to HTML and JSX, and you can keep using React or Vue for interactive pieces.
  • "No JavaScript means no interactivity." You can add plain <script> tags and islands. The default is zero, not never.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Astro send to the browser by default for a page with no interactive components?

    Astro renders components to HTML ahead of time and ships no JavaScript unless you opt in.
  2. 2. Where does the code inside the frontmatter fence of an .astro file run?

    The fence code runs while the page is rendered. The visitor only receives the resulting HTML.
  3. 3. What is an island in Astro?

    Islands are interactive UI components surrounded by static HTML. Each one hydrates on its own.
  4. 4. Which project is the weakest fit for Astro?

    Nearly everything in a drawing editor is interactive client-side state, so a content-first framework gives little advantage.

Summary

  • Astro builds fast, content-focused sites by rendering to HTML and shipping zero JavaScript by default.
  • Interactivity is opt-in through islands, which can use React, Vue, Svelte and other frameworks.
  • An .astro file has a frontmatter fence for server code and an HTML-like template.
  • astro build turns source files into a folder of static files; adapters add server rendering later.
  • Pick Astro for content, docs and marketing sites; pick an app-style framework for highly interactive tools.

Next: Creating an Astro Project