Mastro 👨‍🍳 Docs

Search results

Blog Community GitHub   Stoat Chat   Discord   Bluesky

No dependencies. No build step. Just HTML, CSS and JavaScript.

Mastro is a server framework and static site generator for people who care about their users and web standards. Build fast server-rendered websites, ship JavaScript for islands only.

Implemented in just ~900 lines of TypeScript, Mastro is a vanishingly thin layer: your server code runs directly on Node.js, your unobfuscated client code directly on the high-performance rendering engine that is a modern browser.

Get started Docs ☆ GitHub

As seen on the Internet!

The New Stack

TypeScript.fm

That HTML blog

Mastro's source code is extremely readable.
– Erik Onarheim
A library worth checking out!
– Jared White

Simple to start, powerful when you need it

Get started

Fast server-rendered HTML

Whether you do static site generation or use Mastro as a full-stack framework, your route handlers are always plain functions returning a web standard Response. You can compose the built-in HTML helpers, or use a different templating language.

You control precisely what code stays on the server, and what gets shipped to the browser. To keep your website fast, the default is the server.

import { readMarkdownFiles } from "@mastrojs/markdown";
import { html, htmlToResponse } from "@mastrojs/mastro";
import { Layout } from "../components/Layout.ts";

export const GET = async () => {
  const posts = await readMarkdownFiles("posts/*.md");
  return htmlToResponse(
    Layout({
      title: "My blog",
      children: posts.map((post) => html`
        <p>${post.meta.title}</p>
      `)
    })
  );
};
Copied!
import { html, type Html } from "@mastrojs/mastro";

interface Props {
  title: string;
  children: Html;
}

export const Layout = (props: Props) =>
  html`
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title>${props.title}</title>
      </head>
      <body>
        <h1>${props.title}</h1>
        ${props.children}
      </body>
    </html>
  `;
Copied!

Interactive user interfaces

To add client-side interactivity, either use plain JavaScript, or add a library. Popular examples include HTMX, Alpine, Datastar, Unpoly, ArrowJS, or Reactive Mastro. Even Preact and Vue.js work without a complex build tool like Vite.

Reactive Mastro lets you share templates and logic between the server and client islands. It also allows you to initialize state directly from your server-generated HTML – without duplicating the data as JSON.

Reactive Mastro

routes/index.server.ts
import { html, htmlToResponse } from "@mastrojs/mastro";
import { Layout } from "../components/Layout.ts";

export const GET = () =>
  htmlToResponse(
    Layout(html`
      <script type="module" src="/my-counter.client.js"></script>
      <my-counter>
        Count is <span data-bind="count">0</span>
        <button data-onclick="inc">Click me</button>
      </my-counter>
    `)
  );
Copied!
routes/my-counter.client.ts
import { ReactiveElement, signal } from "@mastrojs/reactive";

customElements.define("my-counter", class extends ReactiveElement {
  count = signal(parseInt(this.querySelector("span").textContent));
  inc () {
    this.count.set(c => c + 1);
  }
});
Copied!

Everything is a route

In Unix, everything is a file. In Mastro, everything is a route. Using web standard Request/Response handlers is such a great interface that Mastro decided to go all-in on it. Write a simple function to:

Even Mastro’s middleware is using the same fetch handler API.

Mastro example projects Source of this website

routes/subscribe.server.ts
import { html, htmlToResponse } from "@mastrojs/mastro";
import { Layout } from "../components/Layout.ts";

export const GET = () =>
  htmlToResponse(
    Layout(html`
      <form action="." method="POST">
        <label>
          E-Mail
          <input type="email" name="email">
        </label>
        <button>Subscribe</button>
      </form>
    `)
  );

export const POST = async (req: Request) => {
  const data = await req.formData();
  await db.subscriptions.insert({ email: data.get("email") });
  return Response.redirect(new URL("/thanks", req.url), 303);
};
Copied!
routes/api.server.ts
import { jsonResponse } from "@mastrojs/mastro";

export const POST = async (req: Request) => {
  const data = await req.json();
  const comment = await db.comments.insert(data);
  return jsonResponse(comment);
};
Copied!

Easy for beginners

Put your first website live without installing anything on your computer: The popular VS Code editor also runs in the browser.

Launch Mastro in your browser

Start with learning HTML and CSS. Then build a static blog and a to-do list app with JavaScript. Finally, serve a REST API.

Follow the guide

Powerful for experienced developers

I’ve seen things you wouldn’t believe. Megabytes of JavaScript on fire in the browser. I watched towers of complex abstractions collapse upon themselves. All those websites will be lost in time, like tears in rain. Time to let them die.

To adopt Mastro incrementally, start using its html templates in your existing codebase before switching, or migrate route by route.

Install Mastro Docs ☆ Mastro on GitHub

Fast for everyone

Great UX: websites built with Mastro are fast – even on low-end devices on 3G.

  • 100% Performance
  • 100% Accessibility
  • 100% SEO

Great DX: dev server starts instantly, and SSG is fast – e.g. for 500 markdown files:

Mastro 0.5s  🏁
11ty 0.7s
Astro 2.2s
Next.js 16.3s

A foundation to build upon

The minimal Mastro core package doesn’t come “batteries included”, but it’s built to be extended.

Extensions / plugins

Escape the frontend treadmill

Most JavaScript frameworks and complex build systems were designed to solve problems that no longer exist.

Why Mastro?

Join the community

We’re building an inclusive community, where people of all kinds of backgrounds and experience levels feel welcome and safe, and help each other. A place to ask questions and learn new things.

Want help or chat?

Talk to us on Bluesky, GH Discussions, or:

Discord Stoat

Star us on GitHub!

Every star and every share helps.

GitHub Report a bug


Stay updated 👨‍🍳

Follow us on Bluesky, or add our blog to your RSS reader (feed link).