Quick start
This guide will walk you through creating your first Astro project, understanding its structure, and deploying it to the web.Create a new project
1
Run create-astro
Open your terminal and run the installation command:
2
Follow the setup wizard
The
create-astro wizard will guide you through setup. For this tutorial, choose:3
Navigate to your project
Understand the project structure
Look inside your new Astro project and you’ll see the following folders and files:src/pages/
src/pages/
This is where your website pages live. Astro looks for
.astro, .md, or .mdx files here and automatically creates routes based on the file structure.src/pages/index.astro→yoursite.com/src/pages/about.astro→yoursite.com/aboutsrc/pages/blog/first-post.md→yoursite.com/blog/first-post
src/components/
src/components/
This is where you’ll put reusable components. There’s nothing special about this directory, but it’s a common convention for organizing your Astro, React, Vue, Svelte, or other UI framework components.
src/layouts/
src/layouts/
Another common directory for layout components that wrap your page content. This is also just a convention.
public/
public/
Static assets like images, fonts, and files that don’t need to be processed. These are served as-is and can be referenced directly.
astro.config.mjs
astro.config.mjs
Your Astro configuration file. This is where you configure integrations, build options, server options, and more.
package.json
package.json
Your project’s dependencies and scripts. Astro provides these scripts by default:
dev: Start the development serverbuild: Build for productionpreview: Preview your production build locally
tsconfig.json
tsconfig.json
TypeScript configuration. Even if you’re not using TypeScript, this file helps editors provide better IntelliSense.
Start the dev server
Astro comes with a built-in development server that has everything you need for project development.1
Start the server
Run the dev command:You should see a confirmation message in your terminal:
2
Open your browser
Navigate to
http://localhost:4321 in your browser to see your site.The dev server features hot module replacement (HMR), so changes you make to your files will automatically update in the browser without needing to refresh.
Make your first changes
Let’s customize your homepage:1
Open the index page
Open
src/pages/index.astro in your text editor. You’ll see something like this:src/pages/index.astro
2
Add some content
Update your page with custom content:Save the file and check your browser - you should see the changes instantly!
src/pages/index.astro
3
Add styles
Astro makes it easy to style your components with scoped CSS:
src/pages/index.astro
Create a layout component
To avoid repeating the same HTML structure on every page, let’s create a reusable layout:1
Create a layouts directory
2
Create a layout component
Create The
src/layouts/Layout.astro:src/layouts/Layout.astro
<slot /> element is where child content will be injected.3
Use the layout
Update
src/pages/index.astro to use your new layout:src/pages/index.astro
Add another page
Let’s add an about page to demonstrate routing:src/pages/about.astro
http://localhost:4321/about to see your new page!
Add navigation
Create a navigation component to link between pages:1
Create a components directory
2
Create a navigation component
src/components/Navigation.astro
3
Add it to your layout
src/layouts/Layout.astro
Build for production
When you’re ready to deploy your site, create a production build:1
Build your site
dist/ folder.2
Preview the build locally
Test your production build before deploying:This will start a local server to preview your built site at
http://localhost:4321.By default, Astro builds a static site (Static Site Generation or SSG). All pages are pre-rendered to HTML at build time for maximum performance.
Deploy your site
Astro’s static output can be deployed to any static hosting provider:Netlify
Deploy with zero configuration using Netlify Drop or the Netlify CLI
Vercel
Import your Git repository for automatic deployments on every push
Cloudflare Pages
Connect your repository for instant deployments
GitHub Pages
Deploy directly from your GitHub repository with Actions
Example: Deploy to Netlify
1
Create a Netlify account
Sign up at netlify.com
2
Connect your repository
Import your project from GitHub, GitLab, or Bitbucket
3
Configure build settings
Netlify should auto-detect these settings:
- Build command:
npm run build - Publish directory:
dist
4
Deploy
Click “Deploy site” and Netlify will build and deploy your site automatically!
Next steps
Congratulations! You’ve created your first Astro site. Here’s what to explore next:Add integrations
Enhance your site with React, Tailwind CSS, and more
Content collections
Learn to manage content with type safety
Islands architecture
Master Astro’s approach to partial hydration
API reference
Dive deep into Astro’s configuration and APIs