Astro Tutorial
Learn Astro step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
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.
- Creating an Astro Project Install Astro with create astro, understand the src, public and dist folders, start the dev server and learn what each starter file does.
- Anatomy of an Astro Component Learn the .astro file format: the frontmatter fence, template expressions, conditionals, loops, fragments, HTML attributes and comments.
- The Astro CLI and Configuration Learn the Astro CLI commands, how astro.config.mjs works with defineConfig, key options like site, base and output, plus env vars and TypeScript setup.
Pages, Layouts and Routing
- File-Based Routing in Astro See how files in src/pages become URLs in Astro, how index files, nested folders and file types map to routes, and how links and route priority work.
- Layouts and Slots in Astro Build reusable Astro layouts with the slot element, named slots, props for titles and SEO tags, nested layouts and Markdown frontmatter layouts.
- Dynamic Routes and getStaticPaths Generate many pages from one file with dynamic routes. Learn [param] and [...rest] syntax, getStaticPaths, props, nested params and on-demand routes.
- Pagination in Astro Split long lists into pages with Astro's paginate() helper. Learn the page prop, previous and next links, page sizes, filtered lists and SEO tips.
- Redirects, 404 Pages and Middleware Handle moved URLs with Astro redirects, build a custom 404 page, redirect from code with Astro.redirect and run logic on every request with middleware.
Components and Islands
- Props and Slots in Astro Components Pass data into Astro components with props, type them with TypeScript, set defaults, spread attributes, use class:list and combine props with slots.
- Client-Side Scripts in Astro Add browser JavaScript to Astro pages with script tags, learn how Astro bundles and deduplicates them, pass data with define:vars and use custom elements.
- Islands Architecture in Astro Understand Astro islands and partial hydration: static HTML around interactive components, framework components, hydration cost and server islands.
- Client Directives: load, idle, visible, media, only Control when Astro islands hydrate with client:load, client:idle, client:visible, client:media and client:only, and learn how to choose the right one.
- Sharing State Between Islands Islands hydrate separately, so they cannot share React context. Learn Nano Stores, atoms, maps, persistent state and custom events to connect islands.
Content Collections and Markdown
- Markdown Pages and Frontmatter Write pages in Markdown with Astro: frontmatter, the layout field, GitHub-flavored extras, heading IDs, syntax highlighting with Shiki and MDX components.
- Content Collections and Loaders Organize content with Astro content collections: define collections in content.config.ts, validate frontmatter with Zod schemas and load files, JSON or APIs.
- Querying Content Collections Query Astro content collections with getCollection, getEntry and getEntries. Filter drafts, sort by date, group by tag and build pages from entries.
- Rendering Entries, MDX and Markdown Plugins Render collection entries with render(), build a table of contents from headings, map MDX components and extend Markdown with remark and rehype plugins.
Styling and Assets
- Scoped Styles and Global CSS in Astro Style Astro components with scoped CSS, escape to global styles with is:global, pass values with define:vars and build class names with class:list.
- Tailwind CSS and Sass in Astro Add Tailwind CSS 4 and Sass to an Astro project, organise design tokens, avoid purge mistakes and decide when utilities beat scoped styles.
- Images in Astro: Image, Picture and getImage Optimise images in Astro with the Image and Picture components, remote image rules, responsive widths, formats, getImage and layout shift prevention.
- Fonts, Icons and Static Assets in Astro Load web fonts without layout jumps, use SVG icons as components, understand the public folder, hashed asset names and the build output in Astro.
Integrations with Frameworks
- Adding Integrations to an Astro Project Use astro add to install integrations, read what they change in astro.config, find official ones and write a small custom integration with hooks.
- Using React, Vue and Svelte Components in Astro Render React, Vue, Svelte, Solid and Preact components inside Astro pages, choose client directives, pass props and slots, and mix frameworks safely.
SSR, Adapters and Endpoints
- Astro Output Modes, Prerendering and Adapters Understand Astro's static and server output, opt pages in or out of prerendering, pick an adapter (Node, Vercel, Netlify, Cloudflare) and use server islands.
- API Endpoints and Server Routes in Astro Build Astro endpoints that return JSON, handle POST requests, read params and headers, generate static files at build time and return correct status codes.
- Astro Middleware, Cookies and Authentication Write Astro middleware with defineMiddleware and sequence, share data through locals, set secure cookies and protect routes with a session check.
- Astro Actions: Type-Safe Forms and Server Functions Define type-safe server functions with Astro Actions, validate input with Zod, handle HTML forms without JavaScript and call actions from islands.
Performance and Deployment
- Astro Performance and Core Web Vitals Keep Astro sites fast: measure LCP, CLS and INP, control JavaScript with islands, optimise images, fonts and third-party scripts, and set a budget.
- Astro View Transitions and Client-Side Navigation Add animated page transitions to Astro with ClientRouter, name and persist elements, run scripts after swaps and respect reduced-motion preferences.
- Prefetching and Caching Strategies in Astro Make navigation feel instant with Astro prefetch strategies (hover, tap, viewport, load), set HTTP cache headers, and combine CDN caching with SSR.
- Deploying an Astro Site: Static Hosts, Node and Docker Deploy Astro to static hosts, GitHub Pages and Node or Docker servers. Learn site and base settings, build commands, environment variables and CI checks.
Projects and Practice
- Project: Build a Blog with Content Collections Build a complete Astro blog: a typed content collection, post and tag pages, reading time, RSS feed, sitemap and SEO tags, with runnable stand-ins.
- Project: A Portfolio Site with Interactive Islands Build a fast Astro portfolio: project cards, a filter island, a no-flash theme toggle, a contact form with an action and optimised images.
- Project: A Documentation Site with Sidebar and Search Build a documentation site in Astro: collection-driven sidebar, table of contents from headings, previous/next links, MDX and static search with Pagefind.
- Project: A Small Store with SSR, Cart and Checkout Build a small Astro store: static product pages, a cart island with Nano Stores, server endpoints, middleware, server islands and a safe checkout flow.
- Astro Practice: Common Mistakes, Debugging and Exercises Review the most common Astro mistakes (islands, hydration, paths, SSR, images), learn a debugging routine and practise with exercises and a final checklist.