To build a gym website with Astro, model classes, trainers and memberships as content collections, generate a weekly timetable from a single schedule file, link sign-ups and class bookings to your gym management software, and add ExerciseGym structured data for local search. A static Astro gym website loads fast on phones, which is where most people check class times, and there’s no plugin stack or database to keep patched.
This guide covers the pages a gym site needs, the Astro 7 code for each, and the local SEO details that bring in members from nearby.
Key Takeaways
- Visitors want three things: what classes run and when, what membership costs, and how to start. Put all three one tap from the home page.
- Keep the timetable in one data file so changing a class time is a one-line edit.
- Send bookings and payments to your existing gym software instead of building accounts on the website.
- Add
ExerciseGymJSON-LD with address, opening hours and phone for local search.- Use
astro:assetsfor trainer and studio photos so a photo-heavy site still loads quickly.
What a gym website needs
Most visitors arrive with a short list of questions. Build a page for each answer.
| Page | What it must answer |
|---|---|
| Home | Type of gym, location, opening hours, trial offer, how to join |
| Classes | One page per class: intensity, duration, who it suits, which trainers teach it |
| Timetable | The week’s classes by day and time |
| Trainers | Name, qualifications, specialties, photo, classes taught |
| Membership | Plans, prices, contract length, what’s included |
| Free trial or day pass | A short form or a link to your booking system |
| Location | Address in text, parking, transit, opening hours, holiday hours |
The opening hours and the trial offer should be visible without scrolling on mobile. People often decide whether to visit while standing outside.
Create the project
# Terminal
npm create astro@latest gym-site
cd gym-site
npx astro add sitemap
npm run dev
Want a finished design to start from? The Astro wellness themes category includes gym and fitness designs such as Fitman CMS, built for gyms and fitness centers, Active-X for health clubs and personal trainers, and Climbr for climbing and bouldering gyms. If you’d rather start free, a general business template such as AstroWind or one of Astro’s official starters works, though you’ll build the class and timetable pages yourself.
Model classes, trainers and the schedule
Classes and trainers are Markdown entries with their own pages. The timetable is plain data, so it fits a single JSON file loaded with the file() loader.
// src/content.config.ts
import { defineCollection, reference } from 'astro:content';
import { glob, file } from 'astro/loaders';
import { z } from 'astro/zod';
const trainers = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/trainers' }),
schema: ({ image }) =>
z.object({
name: z.string(),
qualifications: z.array(z.string()),
specialties: z.array(z.string()),
photo: image(),
photoAlt: z.string(),
}),
});
const classes = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/classes' }),
schema: z.object({
title: z.string(),
summary: z.string().max(180),
durationMinutes: z.number(),
intensity: z.enum(['Low', 'Moderate', 'High']),
suitableFor: z.string(),
trainers: z.array(reference('trainers')),
}),
});
const schedule = defineCollection({
loader: file('src/data/schedule.json'),
schema: z.object({
class: reference('classes'),
trainer: reference('trainers'),
day: z.enum(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']),
start: z.string().regex(/^\d{2}:\d{2}$/),
room: z.string(),
}),
});
export const collections = { trainers, classes, schedule };
// src/data/schedule.json
[
{ "id": "mon-0630-hiit", "class": "hiit", "trainer": "sam-okafor", "day": "Mon", "start": "06:30", "room": "Studio 1" },
{ "id": "mon-1830-yoga", "class": "yoga-flow", "trainer": "lena-hart", "day": "Mon", "start": "18:30", "room": "Studio 2" }
]
reference() means a typo in a class or trainer id fails the build instead of producing a broken timetable. The content collections guide covers references and the file() loader in more detail.
Build the weekly timetable
The timetable is the most visited page on most gym sites. Generate it at build time and render it as a real table, which works on every device and reads well to screen readers.
---
// src/pages/timetable.astro
import { getCollection, getEntry } from 'astro:content';
import BaseLayout from '../layouts/BaseLayout.astro';
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
const slots = await getCollection('schedule');
const rows = await Promise.all(
slots
.sort((a, b) => DAYS.indexOf(a.data.day) - DAYS.indexOf(b.data.day) || a.data.start.localeCompare(b.data.start))
.map(async (slot) => ({
...slot.data,
classEntry: await getEntry(slot.data.class),
trainerEntry: await getEntry(slot.data.trainer),
})),
);
---
<BaseLayout title="Class timetable" description="This week's classes, times and trainers.">
<h1>Class timetable</h1>
{DAYS.map((day) => {
const today = rows.filter((r) => r.day === day);
return today.length > 0 && (
<section>
<h2>{day}</h2>
<table>
<thead><tr><th>Time</th><th>Class</th><th>Trainer</th><th>Room</th></tr></thead>
<tbody>
{today.map((r) => (
<tr>
<td>{r.start}</td>
<td><a href={`/classes/${r.classEntry.id}/`}>{r.classEntry.data.title}</a></td>
<td>{r.trainerEntry.data.name}</td>
<td>{r.room}</td>
</tr>
))}
</tbody>
</table>
</section>
);
})}
</BaseLayout>
Grouping by day with a heading per day reads better on phones than a seven-column grid. If you want day tabs, the tabs component guide shows an accessible version with very little JavaScript.
Class and trainer pages
Each class gets its own page with the practical facts first: duration, intensity, who it suits, and when it runs.
---
// src/pages/classes/[id].astro
import { getCollection, getEntries, render } from 'astro:content';
import BaseLayout from '../../layouts/BaseLayout.astro';
export async function getStaticPaths() {
const classes = await getCollection('classes');
return classes.map((c) => ({ params: { id: c.id }, props: { gymClass: c } }));
}
const { gymClass } = Astro.props;
const { Content } = await render(gymClass);
const team = await getEntries(gymClass.data.trainers);
const sessions = (await getCollection('schedule')).filter((s) => s.data.class.id === gymClass.id);
---
<BaseLayout title={gymClass.data.title} description={gymClass.data.summary}>
<h1>{gymClass.data.title}</h1>
<dl class="facts">
<div><dt>Duration</dt><dd>{gymClass.data.durationMinutes} minutes</dd></div>
<div><dt>Intensity</dt><dd>{gymClass.data.intensity}</dd></div>
<div><dt>Good for</dt><dd>{gymClass.data.suitableFor}</dd></div>
</dl>
<Content />
<h2>When it runs</h2>
<ul>{sessions.map((s) => <li>{s.data.day} {s.data.start}, {s.data.room}</li>)}</ul>
<h2>Trainers</h2>
<ul>{team.map((t) => <li><a href={`/trainers/${t.id}/`}>{t.data.name}</a></li>)}</ul>
</BaseLayout>
Class pages are also good search landing pages. People search for “spin class near me” or “beginner kettlebell class”, and a dedicated page with the class name in the title can rank for that, where a single timetable page can’t.
Membership pricing and sign-ups
Be clear about price, contract length and what’s included. Hidden pricing is one of the most common complaints about gym websites, and it sends visitors to competitors who show it.
---
// src/components/MembershipPlans.astro
const plans = [
{ name: 'Off-peak', price: 29, term: 'Monthly, cancel anytime', perks: ['Gym floor 10:00 to 16:00', 'Two classes a week'] },
{ name: 'Full', price: 45, term: 'Monthly, cancel anytime', perks: ['Gym floor all hours', 'Unlimited classes', 'One induction session'] },
{ name: 'Annual', price: 450, term: 'Paid yearly', perks: ['Everything in Full', 'Two guest passes a month'] },
];
const joinUrl = import.meta.env.PUBLIC_JOIN_URL ?? '/contact/';
---
<div class="plans">
{plans.map((plan) => (
<article class="plan">
<h3>{plan.name}</h3>
<p class="price">${plan.price}</p>
<p>{plan.term}</p>
<ul>{plan.perks.map((perk) => <li>{perk}</li>)}</ul>
<a class="btn" href={`${joinUrl}?plan=${plan.name.toLowerCase()}`}>Join</a>
</article>
))}
</div>
The Join link goes to your gym management or membership software, which handles payments, direct debits and member accounts. Keep that URL in an environment variable so switching providers is a one-line change. The pricing table component guide covers layout and accessibility details for plan cards.
Local SEO and ExerciseGym schema
Most gym searches are local, so your site and your Google Business Profile should agree on name, address, phone and hours. Add ExerciseGym structured data to the home and location pages.
---
// src/components/GymSchema.astro
const schema = {
'@context': 'https://schema.org',
'@type': 'ExerciseGym',
name: 'Northside Strength & Fitness',
url: Astro.site?.href,
telephone: '+1-555-010-2020',
address: {
'@type': 'PostalAddress',
streetAddress: '48 Mill Street',
addressLocality: 'Portland',
addressRegion: 'OR',
postalCode: '97201',
addressCountry: 'US',
},
openingHoursSpecification: [
{ '@type': 'OpeningHoursSpecification', dayOfWeek: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], opens: '05:30', closes: '22:00' },
{ '@type': 'OpeningHoursSpecification', dayOfWeek: ['Saturday', 'Sunday'], opens: '07:00', closes: '18:00' },
],
};
---
<script type="application/ld+json" set:html={JSON.stringify(schema)} />
Check the type against schema.org’s ExerciseGym definition. The JSON-LD guide shows how to build schema from your collections instead of hard-coding it.
Photos and performance
Gym sites lean on photos: the gym floor, studios, trainers. Process them through astro:assets so each visitor gets an appropriately sized, modern-format image.
---
// src/components/TrainerCard.astro
import { Image } from 'astro:assets';
const { trainer } = Astro.props;
---
<a href={`/trainers/${trainer.id}/`} class="card">
<Image src={trainer.data.photo} alt={trainer.data.photoAlt} width={400} height={500} />
<strong>{trainer.data.name}</strong>
<span>{trainer.data.specialties.join(', ')}</span>
</a>
Avoid an autoplaying background video in the hero. It’s the heaviest item on most gym home pages and pushes the timetable and join button further away on slow connections. A single strong photo does the job. The responsive images tip covers widths and sizes for hero images.
Deploy and maintain
Run npm run build and deploy dist/ to Cloudflare Pages, Netlify or Vercel; the static deployment docs cover each host. Most ongoing changes are content: a new class, a holiday schedule, a trainer joining. Each is a Markdown or JSON edit that rebuilds the site in a minute or two. For the official reference on collections, see the Astro content collections docs.
FAQ
Is Astro good for a gym website?
Yes. A gym website is mostly classes, trainers, prices and opening hours, which Astro builds into fast static pages. Visitors on phones get quick loads, and there’s no database or admin plugin to keep updated.
How do I add class booking to an Astro gym website?
Link the Book or Join buttons to the booking page of your gym management software, or embed its booking widget on the timetable page. That software handles accounts, payments and reminders, so your Astro site stays static.
What pages should a gym website have?
At minimum: a home page with location and hours, a class list with one page per class, a weekly timetable, trainer profiles, membership pricing, a free trial or day pass page, and a location page with directions and parking.
Should a gym website show membership prices?
In most cases, yes. Visitors compare gyms on price and contract terms, and a clear pricing page reduces enquiries that end in a no. If prices vary by location or promotion, show a starting price and the main plan differences.
What schema markup should a gym use?
Use the schema.org ExerciseGym type with name, address, telephone and opening hours on your home and location pages. Keep those details identical to your Google Business Profile so search engines see consistent information.