🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Themes••By Komal Nakrani

Astro Portfolio Tutorial: Build a Portfolio Site Step by Step

Astro portfolio tutorial: model projects as a content collection, build a work grid and case study pages, optimize images, add a contact form, and deploy free.

#Astro#Portfolio#Content Collections#Tutorial

This Astro portfolio tutorial builds a complete portfolio site in five steps: create the project, store each project as a Markdown entry in a content collection, render a work grid and a case study page per project with getStaticPaths(), optimize screenshots with astro:assets, and deploy the static build to a free host. The result is a portfolio that ships almost no JavaScript, loads fast on any connection, and lets you add a new project by dropping in one Markdown file.

Everything below uses Astro 7 APIs: the Content Layer with the glob() loader, z from astro/zod, and the <Image /> component.

Key Takeaways

  • A portfolio is a list of projects plus one detail page per project. Model projects as a content collection and let Astro generate the pages.
  • Use the image() schema helper so cover images are validated and optimized at build time.
  • Case studies sell better than screenshots: write the problem, your role, the process and the result.
  • A contact form can post to a form backend, so the whole site stays static.
  • Deploy dist/ to Cloudflare Pages, Netlify, Vercel or GitHub Pages for free.

What a portfolio site needs

Before writing code, decide what a visitor should do. For most freelancers and designers, the answer is: look at two or three projects, believe you can do the job, and get in touch. Every page should push toward that.

Page Purpose
Home One-line positioning, three to six featured projects, a contact link
Work Every project as a filterable grid
Case study Problem, role, process, outcome, images
About Who you are, how you work, tools and clients
Contact A short form or an email address, plus availability

Keep the home page short. Hiring managers and clients skim, and a long scroll of every project you have ever touched dilutes the best work.

Step 1: create the Astro portfolio project

# Terminal
npm create astro@latest my-portfolio
cd my-portfolio
npx astro add sitemap
npm run dev

Pick the minimal template when the CLI asks, so you start with a clean src/pages/index.astro. Astro also ships an official portfolio example (npm create astro@latest -- --template portfolio) if you want a basic starting layout. Then set your production URL so the sitemap and canonical links work:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';

export default defineConfig({
  site: 'https://yourname.com',
  integrations: [sitemap()],
});

The folder layout you will end up with:

src/
  content/
    projects/
      brand-refresh/
        index.md
        cover.jpg
  content.config.ts
  layouts/Base.astro
  pages/
    index.astro
    work/index.astro
    work/[slug].astro
    about.astro
    contact.astro

Keeping each project in its own folder with its images next to the Markdown makes relative image paths simple.

Step 2: model projects as a content collection

The collection schema is the contract every project file must follow. If a project is missing a title or its cover image path is wrong, the build fails with a clear error instead of shipping a broken card.

// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

const projects = defineCollection({
  loader: glob({ pattern: '**/index.md', base: './src/content/projects' }),
  schema: ({ image }) =>
    z.object({
      title: z.string(),
      client: z.string(),
      year: z.number(),
      role: z.string(),
      summary: z.string().max(160),
      cover: image(),
      coverAlt: z.string(),
      tags: z.array(z.string()).default([]),
      featured: z.boolean().default(false),
      order: z.number().default(100),
    }),
});

export const collections = { projects };

A project entry then looks like this:

<!-- src/content/projects/brand-refresh/index.md -->
---
title: "Brand refresh for a coffee roaster"
client: "North Roast"
year: 2026
role: "Brand and web design"
summary: "A new identity and a faster site that doubled online wholesale enquiries."
cover: "./cover.jpg"
coverAlt: "North Roast packaging on a wooden counter"
tags: ["Branding", "Web design"]
featured: true
order: 1
---

## The problem
...

The glob() loader uses the folder name as the entry id, so this project’s URL becomes /work/brand-refresh/. Read the Content Collections guide for the full loader options.

Step 3: build the work grid

The work page reads every project, sorts by order and then year, and renders a card for each. A shared card component keeps the home page and work page consistent.

---
// src/components/ProjectCard.astro
import { Image } from 'astro:assets';
import type { CollectionEntry } from 'astro:content';

interface Props {
  project: CollectionEntry<'projects'>;
}
const { project } = Astro.props;
const { title, client, year, cover, coverAlt } = project.data;
---
<a href={`/work/${project.id}/`} class="card">
  <Image src={cover} alt={coverAlt} widths={[400, 800]} sizes="(min-width: 768px) 50vw, 100vw" />
  <h3>{title}</h3>
  <p>{client}, {year}</p>
</a>
---
// src/pages/work/index.astro
import { getCollection } from 'astro:content';
import Base from '../../layouts/Base.astro';
import ProjectCard from '../../components/ProjectCard.astro';

const projects = (await getCollection('projects')).sort(
  (a, b) => a.data.order - b.data.order || b.data.year - a.data.year,
);
---
<Base title="Work" description="Selected design and development projects.">
  <h1>Work</h1>
  <div class="grid">
    {projects.map((project) => <ProjectCard project={project} />)}
  </div>
</Base>

<style>
  .grid {
    display: grid;
    gap: 2rem;
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  }
</style>

On the home page, filter to featured projects and slice the first three or six. If you want tag filters on the work page, a few lines of plain JavaScript in a <script> tag that toggles hidden on cards is enough. You don’t need a framework island for that.

Step 4: generate a case study page per project

getStaticPaths() turns each collection entry into a route at build time, and render() turns the Markdown body into a component.

---
// src/pages/work/[slug].astro
import { getCollection, render } from 'astro:content';
import { Image } from 'astro:assets';
import Base from '../../layouts/Base.astro';

export async function getStaticPaths() {
  const projects = await getCollection('projects');
  return projects.map((project) => ({
    params: { slug: project.id },
    props: { project },
  }));
}

const { project } = Astro.props;
const { Content } = await render(project);
const { title, summary, client, year, role, cover, coverAlt } = project.data;
---
<Base title={`${title} | Case study`} description={summary}>
  <article>
    <h1>{title}</h1>
    <dl>
      <dt>Client</dt><dd>{client}</dd>
      <dt>Year</dt><dd>{year}</dd>
      <dt>Role</dt><dd>{role}</dd>
    </dl>
    <Image src={cover} alt={coverAlt} widths={[800, 1600]} sizes="100vw" loading="eager" />
    <Content />
    <a href="/contact/">Start a project</a>
  </article>
</Base>

The cover is the largest element above the fold, so loading="eager" helps your Largest Contentful Paint. Images further down the case study can stay lazy, which is the <Image /> default.

Write case studies that win work

A case study page is a sales page in disguise. Use the same four headings in every project so readers know where to look:

  1. The problem: what the client needed and why it mattered.
  2. My role: what you did yourself, and who else was involved.
  3. The process: two or three key decisions, with sketches or before-and-after images.
  4. The result: a measurable outcome if you have one, or a client quote you have permission to use.

Short is fine. Three hundred words and five good images beat two thousand words of process notes.

Step 5: optimize portfolio images

Portfolios are image-heavy, so this is where most sites get slow. Astro’s <Image /> component converts images to WebP by default, generates the srcset from widths, and writes width and height attributes so the layout doesn’t shift while images load.

A few rules that keep a portfolio fast:

  • Export source images at about 2x the largest display size, then let Astro resize them. Don’t upload 6,000-pixel camera files.
  • Always pass sizes when you pass widths, or the browser may pick a larger file than it needs.
  • Use <Picture /> with formats={['avif', 'webp']} for big hero shots where AVIF’s smaller files pay off.
  • For video reels, use a <video> tag with preload="none" and a poster image instead of autoplaying a large file.

The Astro images guide covers every option, and the comparison in Image vs Picture vs img helps you choose.

Add an about page and a contact form

The about page should answer “can I trust this person with my project.” Include a real photo, a paragraph on how you work, the tools you use, and logos or names of past clients if you are allowed to share them.

For contact, a static form that posts to a form backend keeps hosting free:

---
// src/pages/contact.astro
import Base from '../layouts/Base.astro';
---
<Base title="Contact" description="Tell me about your project.">
  <h1>Start a project</h1>
  <form action="https://formspree.io/f/your-form-id" method="POST">
    <label>Name <input name="name" required /></label>
    <label>Email <input type="email" name="email" required /></label>
    <label>Budget
      <select name="budget">
        <option>Under $5k</option>
        <option>$5k to $15k</option>
        <option>Over $15k</option>
      </select>
    </label>
    <label>Project details <textarea name="message" rows="6" required></textarea></label>
    <button type="submit">Send</button>
  </form>
</Base>

A budget field filters enquiries before you reply. If you’d rather keep form handling in your own code, Astro Actions can validate the submission on the server, though that needs an adapter. See contact forms on a static Astro site for the trade-offs between backends.

SEO for an Astro portfolio

Search traffic to a portfolio usually comes from your name, your specialty plus city (“brand designer Leeds”), and individual case studies. Cover the basics:

  • A unique <title> and meta description per page, passed through your Base layout.
  • Person JSON-LD on the home or about page with your name, job title and social profiles in sameAs.
  • Descriptive case study URLs (/work/coffee-roaster-rebrand/ beats /work/project-3/).
  • Meaningful alt text on every image. Astro’s <Image /> requires the alt prop, so you can’t forget it.

The Astro SEO guide has a full checklist and a reusable meta tags component.

Deploy the portfolio

Run npm run build, and Astro writes static HTML, CSS and images to dist/. Connect the repository to Cloudflare Pages, Netlify or Vercel, set the build command to npm run build and the output directory to dist, and every push redeploys the site. Add your custom domain in the host’s dashboard. The static deploy docs list the exact settings per host.

Start from a theme instead

If you’d rather customize than build from zero, there are good free and paid starting points:

  • Astro’s portfolio example: minimal and official, a good base if you want to learn the structure.
  • Astrofy: a free community template that combines portfolio, blog and CV pages.
  • AstroWind: a free general-purpose template with plenty of landing sections you can rearrange into a portfolio.
  • Komal portfolio themes: the Portfolio & Agency category has more than 1,000 Astro themes. Akin is built on Content Collections for visual work, Alex Baena suits freelancers with services and work pages, and Cast & Render is a reel-first studio portfolio with a project brief page. Each is $19 to $39 one-time with the full source.

For a curated list, see the best Astro portfolio themes.

FAQ

Is Astro good for a portfolio website?

Yes. A portfolio is mostly static content and images, which is exactly what Astro is built for. It ships no JavaScript unless you add an island, optimizes images at build time, and deploys as plain files to free hosts, so the site is fast and cheap to run.

How long does it take to build a portfolio with Astro?

Following this tutorial, a basic portfolio with a work grid, case study pages and a contact form takes an afternoon if you already have your project images and text. Writing good case studies usually takes longer than the code.

Do I need to know React to build an Astro portfolio?

No. Astro components use HTML, CSS and a small amount of JavaScript in the frontmatter. You can add React, Vue or Svelte components later for interactive pieces, but a portfolio rarely needs them.

How do I add a new project to my Astro portfolio?

Create a new folder in src/content/projects/ with an index.md file and its images, fill in the frontmatter fields from the schema, and push. The work grid and case study page update on the next build.

Where can I host an Astro portfolio for free?

Cloudflare Pages, Netlify, Vercel and GitHub Pages all host static Astro sites for free on their starter plans. You only pay for a custom domain.