Framework cheatsheet
Astro Cheatsheet
Build fast content sites with Astro: components, layouts, routing, content collections, islands, endpoints and deployment.
CLI
- Create a project — Scaffold a new Astro site interactively.
- Start the dev server — Run the site at http://localhost:4321 with hot reload.
- Build for production — Generate the site into dist. Static sites become plain HTML files.
- Preview the build — Serve the production build locally.
- Add an integration — Install and configure a framework or tool such as React, Tailwind or MDX.
- Type-check the project — Check .astro files and TypeScript for errors.
Components and layouts
- Component skeleton — An .astro file has JavaScript between the --- fences, which runs at build time, and a template below.
- Accept props — Read props from Astro.props, with types.
- Create a layout — A layout wraps pages and renders their content with <slot />.
- Use a layout in a page — Wrap page content in your layout component.
- Optimize images — The Image component resizes, converts and lazy-loads images and sets width and height.
- Style a component — Styles in a <style> tag apply only to that component.
Routing and content
- Create pages from files — Files in src/pages become routes. [slug] is a dynamic segment.
- Generate dynamic pages at build time — getStaticPaths lists the values for a dynamic route in a static site.
- Define a content collection — Describe a folder of Markdown files with a schema, so front matter is validated and typed.
- Query a collection — Fetch the entries of a collection, filtered and sorted.
- Render a Markdown entry — Render the Markdown body of a collection entry.
Islands, endpoints and deployment
- Add an interactive component — A client: directive hydrates a framework component. Without one, it renders as plain HTML with no JavaScript.
- Read environment variables — Public variables start with PUBLIC_. Others are available only on the server.
- Create an API endpoint — A .ts file in src/pages exports a function per HTTP method.
- Render on the server — Add an adapter to render pages on demand. Choose the one for your host.
- Render a page on demand — In a mostly static site, mark a page to render per request.
- Configure the site — Set the site URL, which is needed for the sitemap and absolute URLs.
Related cheatsheets
- Angular 22 cheatsheet — Angular CLI commands and standalone component, signals, template, routing, HTTP and forms snippets.
- Django 6 cheatsheet — Create projects, run migrations, test and deploy Django apps, plus the ORM queries you use every day.
- .NET and ASP.NET Core 10 cheatsheet — The dotnet CLI for creating, building, testing and publishing projects, plus common ASP.NET Core and EF Core code.
- Express 5 cheatsheet — Build HTTP servers and APIs with Express 5 on Node.js.
- FastAPI 0.115 cheatsheet — Install, run, test and deploy FastAPI apps from the command line.
- Flask 3 cheatsheet — Create, run, test and deploy Flask apps, with routes, templates, blueprints, sessions and database snippets.