Forma, step by step
Everything you need to set up, customise and ship the Forma Tailwind CSS agency template.
Introduction
Forma is a design-led Astro template for agencies, creative studios and freelance portfolios — one of our best Astro templates for an agency landing page or a portfolio template, built with Astro 7, Tailwind CSS 4 and Magic UI, no React or other UI framework. It ships seventeen ready pages across five home variants, an Astro blog template for the Journal section, a validated contact form with a PHP handler, light and dark "Digital Violet" themes, and a fully static production build.
What is included
- Tailwind CSS 4, compiled at build time (no CDN script in the browser)
- Design tokens in one place:
--forma-*custom properties insrc/styles/tokens.css - Dark by default, with a light mode the visitor can switch to; their choice is remembered
- Three Magic UI pieces (bento grid, marquee, number ticker) and a set of small unstyled form primitives
- SEO: unique title, description and keywords per page, canonical URLs, Open Graph, sitemap via
@astrojs/sitemap - Astro static build: every page pre-rendered to plain HTML, CSS and JavaScript in
dist/
Getting started
Install the tools, run one command and the template builds, opens in your browser and rebuilds whenever you save a file.
Requirements
| Tool | Version | Needed for |
|---|---|---|
| Node.js | 18 or newer | Building the template |
| npm | 9 or newer | Installing packages |
| PHP | 8 or newer | Only the contact form (contact.php) |
Install and run
cd forma-astro
npm install
npm run devcd forma-astro
yarn
yarn devcd forma-astro
pnpm install
pnpm devnpm run dev starts the Astro dev server at http://localhost:4321 with live reload; every change you save in src/ shows up in the browser.
Commands
| Command | What it does |
|---|---|
npm run dev | Start the dev server with live reload |
npm run build | Type-check with astro check, then build the static site into dist/ |
npm run preview | Serve the finished dist/ folder locally |
npm run format | Format the project with Prettier (Astro + Tailwind class-sorting plugins) |
npm run format:check | Check formatting without writing, for CI |
src/ and public/ only. Everything in dist/ is generated and is replaced on every build.Folder structure
Everything you edit lives in src/; the build writes the finished site to dist/. Here is where each piece sits.
forma-astro/
├── src/
│ ├── pages/ ← seventeen routes (.astro), file name becomes the URL
│ │ ├── index.astro, home-classic.astro, home-corporate.astro
│ │ ├── home-creative.astro, home-video.astro
│ │ ├── about.astro, about-agency.astro, services.astro
│ │ ├── portfolio/index.astro, portfolio/[slug].astro
│ │ ├── blog/index.astro, blog/[...slug].astro, blog-sidebar.astro
│ │ ├── contact.astro, contact-maps.astro
│ │ └── privacy.astro, 404.astro
│ ├── components/
│ │ ├── ui/ ← small unstyled primitives: Button, Badge, TextField, SelectField …
│ │ ├── magicui/ ← bento-grid/, marquee/, number-ticker/ (one folder each, index.ts)
│ │ ├── common/ ← PageHero, SectionTitle, BlogCard, ProjectCard, Callout, RelatedPosts
│ │ ├── layout/ ← Navbar, NavLinks, ThemeToggle, MobileDrawer, Footer
│ │ └── sections/ ← one home-page section per file (StatsSection, …)
│ ├── features/ ← hero-visual/, portfolio-filter/, contact-form/ (plain .astro, no framework)
│ ├── content/ ← MDX collections: blog/, portfolio/
│ ├── data/ ← navigation.ts, home.ts (incl. testimonials), portfolio.ts, team.ts
│ ├── schemas/ ← one zod schema per form + fields.ts
│ ├── scripts/ ← form.ts (bindApiForm), portfolio-filter.ts, navbar.ts, theme.ts, …
│ ├── lib/ ← site.ts (brand/SEO text), http.ts (postJson), utils
│ └── styles/ ← global.css (imports) + tokens.css, base.css, layout.css
├── public/
│ ├── contact.php ← contact form handler
│ ├── favicon.svg
│ └── images/
├── dist/ ← generated, upload this
├── static-files/ ← documentation and preview pages (this file)
├── astro.config.mjs, tsconfig.json
└── package.jsonContent (MDX + data)
Blog posts and portfolio case studies are MDX files in src/content/blog/ and src/content/portfolio/. Everything else — navigation, home-page stats, the portfolio index, team bios — is typed data in src/data/*.ts, read by the Astro components. To change a headline, a stat, the menu or a case study, edit the file and rebuild.
Components
Shared UI lives in src/components/ in four folders: ui/ for small unstyled primitives with no copy of their own, magicui/ for the three installed Magic UI effects, common/ for Astro pieces shared across pages, and layout/ for the navbar, drawer, theme toggle and footer. Change a component once and every page updates.
| Component | Used for |
|---|---|
layout/Navbar.astro, MobileDrawer.astro | Fixed navigation with dropdown groups, and the mobile slide-in menu |
layout/ThemeToggle.astro | Dark / light switch, persisted to localStorage |
common/PageHero.astro | The hero block at the top of every non-home page |
common/ProjectCard.astro, BlogCard.astro | Portfolio and journal cards |
magicui/bento-grid/ | Services / features bento layout |
magicui/marquee/, number-ticker/ | Logo marquee and the animated stats row |
features/contact-form/ContactForm.astro | The contact form, validated and submitted by its own inline script |
features/portfolio-filter/ | Category filter on the Work index, wired by a vanilla script |
Pages and components
Every page shares the same shell. Copy an existing page in src/pages/ to start a new one; the file name becomes the route (my-page.astro builds dist/my-page/index.html).
| Page | File | What it is |
|---|---|---|
| Home — Agency / Classic / Corporate / Creative / Video | index.astro, home-classic.astro, home-corporate.astro, home-creative.astro, home-video.astro | Five hero and layout variants to start from |
| About — Studio / Agency | about.astro, about-agency.astro | Story, team and two layout takes |
| Services | services.astro | Brand identity, web design & build, product design, growth marketing |
| Work | portfolio/index.astro, portfolio/[slug].astro | Filterable case-study index and eight detail pages |
| Journal | blog/index.astro, blog/[...slug].astro, blog-sidebar.astro | MDX post grid, post detail and a sidebar layout variant |
| Contact — Form / Map | contact.astro, contact-maps.astro | The validated PHP-backed form, with and without a map |
| Privacy, 404 | privacy.astro, 404.astro | Legal page and the not-found page |
Adding a page to the menu
Add an entry to src/data/navigation.ts (NAV for the header, FOOTER_COLUMNS for the footer); layout/Navbar.astro and MobileDrawer.astro both read from the same array.
Design tokens
Every colour, shadow and radius comes from --forma-* custom properties at the top of src/styles/tokens.css. Tailwind's @theme inline block maps them to utility classes, so changing one value updates the whole template, including dark mode.
Colours — "Digital Violet"
--forma-primaryButtons, links, focus rings--forma-accentSecondary highlights--forma-page-bgDefault background--forma-surfaceCards, nav (scrolled)--forma-errorForm validation--forma-successSuccess messagesTypography
| Use | Font | Weights |
|---|---|---|
| Headings | Outfit | 500 / 600 / 700 |
| Body text, UI | Inter | 400 / 500 / 600 |
Headings follow one scale, set once in base.css: h1 60px (44px below 992px, 36px below 576px), h2 32px, h3 28px, h4 24px — never add a one-off text-[..px] to a heading.
Spacing and breakpoints
Spacing uses a fixed pixel scale (5, 10, 15, 20, 25, 30, 40, 50, 70, 100, 120) written as arbitrary Tailwind values (mb-[30px]), not the default mb-8 steps. Breakpoints follow Bootstrap's scale, defined in the @theme inline block: sm 576, md 768, lg 992, xl 1200, 2xl 1400.
Change the brand colour
/* src/styles/tokens.css */
:root {
--forma-primary: #7c5cff; /* change this */
--forma-primary-hover: color-mix(in srgb, var(--forma-primary), #fff 12%);
--forma-accent: #ff7ad1;
}
:root[data-theme='light'] {
--forma-primary: #6a3dff; /* and its light-mode value */
}README.md if Digital Violet is not the right fit for your brand.Dark mode
Dark mode is attribute based, and dark is the default. A tiny inline script in <head> (layout/ThemeToggle.astro's companion script) sets data-theme="light" on <html> before the page paints, so there is no flash, if the visitor has chosen light before. The toggle saves the choice in localStorage under the key theme.
You never write dark: variants: the colour variables change instead, and light mode is the override.
:root[data-theme='light'] {
--forma-page-bg: #f7f7fb;
--forma-surface: #ffffff;
--forma-heading-color: #0b0b14;
}Tailwind CSS
Tailwind 4 is compiled during the build (the @tailwindcss/vite plugin inside Astro), so no Tailwind script runs in the browser. global.css imports Tailwind, then tokens.css (the --forma-* variables and the @theme inline map), base.css (element defaults) and layout.css (what Tailwind cannot express).
There is no tailwind.config file in Tailwind 4: colours, shadows, radius, fonts, breakpoints and the marquee/float/pulse-glow keyframes all live in the @theme inline block of tokens.css. Tailwind scans src/ for class names automatically.
class="border-error") so Tailwind can see it. Do not build class names by joining pieces.Components
The template includes ready-made interface pieces, a mix of plain Astro components and Magic UI effects. No React, Vue or other UI framework ships to the browser.
Buttons and form fields
Use the Button, Badge, TextField, SelectField, TextareaField and FormStatus components from src/components/ui/; each wraps a shared FormField.astro for its label, error slot and ARIA wiring.
<TextField id="email" name="email" type="email" label="Email" />
<Button variant="primary">Send message</Button>Magic UI
| Component | Used for |
|---|---|
magicui/bento-grid | Services / features layout with uneven card spans |
magicui/marquee | Infinite-scrolling client-logo row |
magicui/number-ticker | The animated stats row (120+ projects, 46 clients …) |
Portfolio filter
The Work index filters eight case studies by category client-side (features/portfolio-filter/, wired by src/scripts/portfolio-filter.ts) without a page reload or a framework.
Contact form (PHP)
The form on contact.astro and contact-maps.astro (ContactForm.astro) is validated with Zod through bindApiForm (src/scripts/form.ts), then POSTed as JSON to public/contact.php, which validates everything again on the server and emails the message.
Set the recipient
// public/contact.php
const TO_EMAIL = 'studio@forma.example.com';
const FROM_EMAIL = 'no-reply@forma-agency.example.com';
const SITE_NAME = 'Forma';Fields and rules
| Field | Rule |
|---|---|
name | Required, 2+ characters |
email | Required, valid address |
company | Optional |
budget | Optional, one of four ranges (Under $10k … $75k+) |
message | Required, 10+ characters |
website | Hidden spam trap: a filled value is silently accepted and dropped |
How it replies
- A
fetchrequest gets JSON:{"ok": true, "message": "…"}, or a non-200 status withok: false. - Posts from another origin are refused with a same-origin check against
HTTP_ORIGIN. - Only
POSTis accepted; anything else gets a 405.
mail(). It does not work on a static-only host or with npm run dev — test it after deploying, or with any local PHP server pointed at dist/.SEO
Each page sets its own title, description and canonical URL; site-wide defaults (name, tagline, description, social handle) come from src/lib/site.ts.
| Source | Controls |
|---|---|
src/lib/site.ts | Site name, tagline, description, Twitter handle, contact email/phone/address |
| Each page's frontmatter | Page title, meta description, canonical path |
astro.config.mjs (site, base) | Canonical domain and the /themes/.../app/ base path used across the build |
@astrojs/sitemap | Generates sitemap-index.xml at build time |
public/robots.txt | Crawl rules and the sitemap URL |
Change the site address
Set site and base in astro.config.mjs, update public/robots.txt's sitemap URL to match, and search src/ for the old domain.
Build and deployment
Astro builds src/ into dist/ as a fully static (SSG) site — every route becomes a directory with its own index.html (for example dist/about/index.html), ready for any Apache or static host.
| Step | What happens |
|---|---|
| check | astro check type-checks the project before building |
| pages | Components are rendered into complete static HTML pages |
| css | Tailwind and the files imported by global.css are compiled into one hashed stylesheet per entry |
| js | The small vanilla scripts (ContactForm's submit handler, the portfolio filter) are bundled and run only on the pages that use them |
| public | contact.php, favicon.svg and images/ are copied as they are |
Deploy
Upload the contents of dist/ to your host. It is plain static HTML, CSS and JavaScript plus contact.php, so it works in the web root or in a sub folder that matches the base you configured. For the contact form the host must run PHP.
Dependencies
Every library the pages use comes from package.json and is imported in the source. Astro bundles it into dist/_astro/ when you build. Nothing is loaded from a CDN.
Libraries used by the pages
| Package | Version | Used for |
|---|---|---|
astro | ^7.4.11 | Static site generator and bundler (Vite) |
@astrojs/mdx | ^8.1.5 | MDX for blog and portfolio content |
@astrojs/sitemap | ^3.7.4 | Sitemap generation |
tailwindcss, @tailwindcss/vite | ^4.3.5 | Utility CSS, compiled at build time |
zod | ^4.6.7 | Contact-form validation, read by bindApiForm |
cn | ^0.5.2 | Conditional Tailwind class-name joining |
boxicons | ^2.1.4 | Icons |
motion | ^14.12.0 | Scroll and hover animation |
@fontsource/outfit, @fontsource/inter | ^5.3.0 / ^5.2.5 | Self-hosted fonts |
Build tools
Listed under devDependencies: @astrojs/check and typescript (type checking), prettier with prettier-plugin-astro and prettier-plugin-tailwindcss (formatting). They run on your computer only.
Add or update a library
npm install some-library # add it
npm update # update everythingCustomisation
Make the template yours: rename it, change the colours and fonts, swap the copy and images, and update the services and prices.
Change the name and logo
Update SITE.name in src/lib/site.ts, the inline SVG mark in layout/Navbar.astro and layout/Footer.astro, and public/favicon.svg.
Change fonts
Fonts come from Fontsource packages. Run npm install @fontsource/your-font, import it where @fontsource/outfit and @fontsource/inter are imported today, and update --font-display / --font-sans in the @theme inline block of tokens.css.
Replace the imagery
Every image currently loads live from images.unsplash.com so the project runs with zero binary assets. IMAGE-ASSETS.md in the project root lists each image's purpose, exact crop size and source URL — download, crop and save each one locally, then update the matching src in src/data/*.ts before you ship.
Change services and prices
Edit the service cards directly in services.astro, and the headline stats in src/data/home.ts.
AI assistants
The project root contains CLAUDE.md and AGENTS.md: a short guide that coding assistants read before they touch your code, so they use the right commands and edit the right files.
CLAUDE.md and AGENTS.md already written, so tools such as Claude Code, Cursor, Codex and GitHub Copilot understand the project structure, commands and conventions from the first prompt.CLAUDE.md is read by Claude Code; AGENTS.md by Cursor, Codex, Copilot and similar tools. The two files are identical.
What is inside
| Section | Tells the assistant |
|---|---|
| Stack | Astro, Tailwind and Magic UI versions, that there's no UI framework, and which form actually talks to PHP |
| Commands | The exact install, dev, build and format commands, so it does not guess |
| Project structure | Where pages, components, data, schemas and styles live |
| How to customize | Step by step: brand colour, new page, menu, contact recipient, images |
| Conventions | Coding rules to follow (token classes, fixed spacing scale, one component per file …) |
| Do NOT | Folders and changes that are off limits, and the known README/code mismatch around the contact-form endpoint |
Keep them in sync
When the project changes (a new folder, command or rule), edit CLAUDE.md and copy it over AGENTS.md.
cp CLAUDE.md AGENTS.mdTroubleshooting
Quick answers to the problems people run into most often when setting up the template.
The page looks unstyled after I build
Open the built site through a server (npm run dev or npm run preview), not by double-clicking a file, and make sure npm install finished without errors. Tailwind is compiled during the build, so a failed build leaves no stylesheet.
The contact form shows an error
The form needs a server that runs PHP and can send mail. Set TO_EMAIL in contact.php and check the server can send mail. It will not work with npm run dev alone.
My edits do not show up
Edit files in src/ and public/, never in dist/, which is rebuilt every time. With npm run dev the page reloads on save; if it does not, do a hard refresh.
How do I change the brand colour?
Change --forma-primary (and its light-mode override) at the top of src/styles/tokens.css. Buttons, links and focus rings all follow it.
Dark mode does not remember my choice
The choice is saved in localStorage. If the browser blocks storage (private mode, blocked cookies) the template stays on the default dark theme.
Credits and support
Forma builds on a few well-maintained open-source tools. Here is what they do, who to ask for help, and what changed in each release.
| Resource | Used for |
|---|---|
| Tailwind CSS 4 | Styling |
| Astro 7 | Static site build |
| Zod | Contact-form validation |
| Magic UI | Bento grid, marquee, number ticker |
| Motion | Scroll and entrance animation |
| Fontsource | Outfit, Inter (installed from npm) |
Need help? Email studio@forma.example.com.
Changelog
| Version | Date | Notes |
|---|---|---|
| 1.0.2 | November 17, 2026 | Added CLAUDE.md and AGENTS.md (AI assistant guide) and an AI assistants section in this documentation |
| 1.0.1 | November 17, 2026 | Rebuilt documentation and preview pages to match the current token system and real page list |
| 1.0.0 | November 13, 2026 | Initial release: seventeen pages, PHP contact form, dark/light "Digital Violet" theme, Magic UI, production build |