Guide
How to build your site with Astro
Astro is a tool for building websites that are mostly content: marketing sites, blogs and shops. Its makers describe it as a framework for content-driven websites. It sends very little code to the visitor's browser, which is a large part of why Astro sites load quickly. This guide explains enough to run one, change it and put it online.

What you need on your computer
- Node.js. This is the program that runs Astro on your computer. Astro needs version 22 or newer, and it does not support the odd-numbered versions such as 23. The README in your template gives the exact version.
- Your project folder. If you bought one of our Astro templates, you get access to it on GitHub and download a copy.
- A terminal, or an AI agent that can use one. The commands below are typed into a terminal. If you use Claude Code, you can ask it to run them for you.
The four commands
| Command | What it does |
|---|---|
| npm install | Downloads everything the site needs. You run it once, and again if the project's requirements change. |
| npm run dev | Starts a preview of the site on your own computer. It prints a web address to open, and the page updates as you make changes. |
| npm run build | Produces the finished site in a folder called dist. This is what goes online. |
| npm run preview | Shows you the finished site from dist on your computer, so you can check it before it goes online. |

Where things live
src/pagesholds the pages. Each file becomes a page on your site, and the file's name becomes its address. A file calledabout.astrobecomes/about.src/componentsholds the pieces that pages are built from, such as the navigation, the footer and cards.src/layoutsholds the frame that wraps every page.src/stylesholds the design settings. In our templates the colours, type sizes and spacing are at the top ofglobal.css.publicholds files that are used as they are, such as images, fonts and the browser tab icon.astro.config.mjsholds the project's settings.

Where the content comes from
An Astro site can keep its content in files inside the project, or fetch it from a content system such as Sanity. Our Astro templates do both. They work straight away using sample content stored in the project, and you can connect Sanity later so that content is edited in a dashboard and not in code. See the Sanity guide.
One thing to understand early: a standard Astro site is built ahead of time. When content changes, the site has to be built again before visitors see the change. Hosting services can do that automatically.
How to put it online
The usual way is through a hosting service such as Vercel or Netlify.
- Put your project on GitHub.
- Sign in to the host and import the project from GitHub.
- Confirm the settings. Vercel recognises Astro on its own. On Netlify the build command is
npm run buildand the publish folder isdist. - Add your settings, described next.
- Deploy.
After that, each time you send a change to the main branch on GitHub, the host rebuilds the site and puts it live. Changes on other branches get their own preview address, so you can look before it goes live.

Settings that live outside the code
Some values should not be written into the code, such as your site address or the ID of your Sanity project. These are called environment variables. On your computer they go in a file named .env. On the host you type them into its settings page.

Two things catch people out:
- In Astro, only variables whose names start with
PUBLIC_can be read in the visitor's browser. Anything secret must not start withPUBLIC_. - On Vercel, a changed variable only applies to new deployments. Deploy again after changing one.


