Back to blog
Apr 11, 2025
3 min read

๐Ÿš€ Building with Astro: A Developer's Quickstart Guide

A quick guide to setting up Astro, exploring project structure, and using layoutsโ€”plus handy resources to boost your workflow.

Astro Project Guide

Astro is cool. I am using it to build this website. Kickstart your Astro journey with this curated guide featuring project setup instructions, helpful resources, and best practices for structuring layouts and components. Whether youโ€™re creating a blog, portfolio, or complex frontend app, this guide offers everything you need to build fast, modern websites using Astro.

๐Ÿš€ Shoutouts & Resources

  • Huge thanks to Mark Horn for creating the awesome Astro Sphere project!
  • ๐Ÿ› ๏ธ Neovim config for AstroJS: Check out this Medium article for a smooth dev experience.
  • ๐Ÿ“บ Learn Astro from scratch via this Frontend Masters course.

โš™๏ธ Getting Started

Quick commands to launch an Astro project:

npm create astro       # Create a new Astro project
npm run dev            # Start the development server
gh repo clone learnwithjason/astro-frontend-masters -- -b start  # Clone starter repo

โœ๏ธ Sample Blog Example

Want to see a real-world Astro blog? Check out:


๐Ÿ—‚๏ธ Project Structure

Astro encourages a clean, opinionated project layout. Hereโ€™s what your project tree might look like:

โ”œโ”€โ”€ README.md              # Project documentation
โ”œโ”€โ”€ astro.config.mjs       # Astro configuration
โ”œโ”€โ”€ package.json           # Project metadata & scripts
โ”œโ”€โ”€ public/                # Static files (images, CSS, JS, fonts)
โ”œโ”€โ”€ src/                   # Source code
โ”‚   โ”œโ”€โ”€ components/        # Reusable UI components
โ”‚   โ”œโ”€โ”€ layouts/           # Page templates
โ”‚   โ”œโ”€โ”€ pages/             # Route-based pages
โ”‚   โ””โ”€โ”€ styles/            # CSS/Sass files
โ””โ”€โ”€ yarn.lock              # Lock file for dependencies (if using yarn)

๐Ÿงฉ Key Directories Explained

  • public/: Static files served as-is (great for favicons, images, etc).
  • src/components/: UI building blocks. Use .astro, React, Vue, etc.
  • src/layouts/: Page templates with shared structure like headers/footers.
  • src/pages/: File-based routing. index.astro โ†’ /, about.astro โ†’ /about
  • src/styles/: Style sheets (global or scoped).
  • astro.config.mjs & package.json: Project configuration & scripts.

๐Ÿงฑ Layouts in Astro

Layouts make your page structure consistent and maintainable. Store them in src/layouts/.

Example: Site Layout

---
// src/layouts/SiteLayout.astro
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
---
<html lang="en">
  <head>
    <Header />
  </head>
  <body>
    <slot /> <!-- Page content injected here -->
    <Footer />
  </body>
</html>

Using the Layout in a Page

---
// src/pages/index.astro
import SiteLayout from '../layouts/SiteLayout.astro';
---
<SiteLayout>
  <p>Welcome to my Astro site!</p>
</SiteLayout>

๐Ÿ”ง Advanced: Named Slots for Layouts

Want to pass content into specific layout sections? Use named slots!

Layout with Named Slots

---
// src/layouts/MyLayout.astro
---
<slot name="header" />
<main>
  <slot /> <!-- Default content -->
</main>
<footer>
  <slot name="footer" />
</footer>

Using Named Slots in a Page

---
// src/pages/index.astro
import MyLayout from '../layouts/MyLayout.astro';
---
<MyLayout>
  <div slot="header">Header content</div>
  <div>Main content goes here</div>
  <div slot="footer">Footer content</div>
</MyLayout>

Happy building with Astro! ๐Ÿš€