🔥 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

Build a Real Estate Website with Astro: Full Tutorial

Build a real estate website with Astro: typed property listings, filterable search, pagination, photo galleries, enquiry forms and listing feed loaders.

#Astro#Real Estate Website#Content Collections#Tutorial

A real estate website in Astro is a set of property listings stored as a typed Content Collection, rendered into fast static pages: a filterable listings index, one detail page per property with a photo gallery and enquiry form, and agent and area pages. Listings can live as Markdown files edited by the agency, or come from a property feed through a custom loader at build time. This tutorial builds both the pages and the data model.

Key Takeaways

  • Model each property as a collection entry with a Zod schema: price, beds, baths, area, status, images and location.
  • Generate detail pages with getStaticPaths() and the index with paginate() for large inventories.
  • A small script filtering data-* attributes gives instant filtering without a framework or server.
  • Use <Image /> for listing photos; they are the heaviest part of every property page.
  • For MLS or CRM feeds, write a loader that fetches listings at build time and rebuild on a schedule or webhook.

Plan the pages

A small agency site typically needs:

Page URL Source
Home / Featured listings, search shortcut, agency intro
Listings /listings/ and /listings/2/ All available properties, paginated
Property detail /listings/<id>/ One entry from the collection
Areas /areas/<area>/ Listings grouped by neighbourhood
Agents /agents/ Agent profiles and contact
Valuation /valuation/ Lead form for sellers

Create the project:

npm create astro@latest harbour-homes -- --template minimal
cd harbour-homes
npx astro add tailwind sitemap

Model listings as a Content Collection

Each listing is a Markdown file with frontmatter for the structured facts and a body for the description.

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

const listings = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/listings' }),
  schema: ({ image }) =>
    z.object({
      title: z.string(),
      status: z.enum(['for-sale', 'for-rent', 'under-offer', 'sold']),
      price: z.number().int().positive(),
      type: z.enum(['house', 'apartment', 'townhouse', 'land']),
      beds: z.number().int().min(0),
      baths: z.number().min(0),
      areaSqft: z.number().int().positive().optional(),
      area: z.string(),
      address: z.string(),
      images: z.array(image()).min(1),
      agent: reference('agents'),
      featured: z.boolean().default(false),
      listedAt: z.coerce.date(),
    }),
});

const agents = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/agents' }),
  schema: ({ image }) =>
    z.object({ name: z.string(), phone: z.string(), email: z.string().email(), photo: image() }),
});

export const collections = { listings, agents };
---
# src/content/listings/12-quay-lane.md
title: Three-bedroom townhouse with harbour views
status: for-sale
price: 685000
type: townhouse
beds: 3
baths: 2.5
areaSqft: 1840
area: old-port
address: 12 Quay Lane, Portland, ME
images:
  - ./images/12-quay-lane/front.jpg
  - ./images/12-quay-lane/living.jpg
  - ./images/12-quay-lane/kitchen.jpg
agent: dana-reyes
featured: true
listedAt: 2026-10-20
---

A bright end-of-terrace townhouse two streets from the waterfront...

The image() helper validates that every photo exists and lets <Image /> optimize it. reference('agents') links the listing to an agent entry, and the build fails if the agent ID doesn’t exist. The Content Collections guide covers references and image fields in detail.

Build a listing card

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

interface Props { listing: CollectionEntry<'listings'> }
const { listing } = Astro.props;
const { title, price, beds, baths, area, status, type, images } = listing.data;
const money = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 });
---
<article
  class="listing-card"
  data-status={status}
  data-type={type}
  data-beds={beds}
  data-price={price}
  data-area={area}
>
  <a href={`/listings/${listing.id}/`}>
    <Image src={images[0]} alt={title} width={640} height={420} class="rounded-lg object-cover" />
    <p class="mt-3 text-xl font-semibold">{money.format(price)}{status === 'for-rent' && ' / month'}</p>
    <h3>{title}</h3>
    <p class="text-sm text-zinc-600">{beds} bed · {baths} bath · {area.replace('-', ' ')}</p>
  </a>
</article>

The data-* attributes are what the filter script reads next.

Paginated listings index with filters

For a few dozen properties, render all available listings on one page and filter in the browser. For hundreds, paginate with paginate().

---
// src/pages/listings/[...page].astro
import { getCollection } from 'astro:content';
import type { GetStaticPaths } from 'astro';
import Base from '../../layouts/Base.astro';
import ListingCard from '../../components/ListingCard.astro';

export const getStaticPaths = (async ({ paginate }) => {
  const listings = (await getCollection('listings', ({ data }) => data.status !== 'sold'))
    .sort((a, b) => b.data.listedAt.valueOf() - a.data.listedAt.valueOf());
  return paginate(listings, { pageSize: 24 });
}) satisfies GetStaticPaths;

const { page } = Astro.props;
---
<Base title="Homes for sale and rent | Harbour Homes" description="Browse every available home from Harbour Homes, with photos, prices and floor areas.">
  <form id="filters" class="flex flex-wrap gap-3" aria-label="Filter listings">
    <select name="status" aria-label="Status">
      <option value="">Buy or rent</option>
      <option value="for-sale">For sale</option>
      <option value="for-rent">For rent</option>
    </select>
    <select name="beds" aria-label="Minimum bedrooms">
      <option value="0">Any beds</option>
      <option value="2">2+ beds</option>
      <option value="3">3+ beds</option>
      <option value="4">4+ beds</option>
    </select>
    <input name="max" type="number" inputmode="numeric" placeholder="Max price" aria-label="Maximum price" />
  </form>

  <p id="count" aria-live="polite"></p>
  <div class="grid gap-8 md:grid-cols-3">
    {page.data.map((listing) => <ListingCard listing={listing} />)}
  </div>

  <nav class="mt-10 flex justify-between" aria-label="Pagination">
    {page.url.prev && <a href={page.url.prev}>Previous</a>}
    {page.url.next && <a href={page.url.next}>Next</a>}
  </nav>
</Base>

<script>
  const form = document.getElementById('filters') as HTMLFormElement;
  const cards = [...document.querySelectorAll<HTMLElement>('.listing-card')];
  const count = document.getElementById('count')!;

  function apply() {
    const f = new FormData(form);
    const status = String(f.get('status') || '');
    const beds = Number(f.get('beds') || 0);
    const max = Number(f.get('max') || Infinity);
    let shown = 0;
    for (const card of cards) {
      const ok =
        (!status || card.dataset.status === status) &&
        Number(card.dataset.beds) >= beds &&
        Number(card.dataset.price) <= max;
      card.hidden = !ok;
      if (ok) shown++;
    }
    count.textContent = `${shown} homes`;
  }

  form.addEventListener('input', apply);
  apply();
</script>

The page works without JavaScript (all listings are visible), and the script only hides cards that don’t match. With pagination, filters apply to the current page; once inventory is large enough that this matters, add a search index such as Pagefind with filter attributes, or move search to an on-demand route. The Astro pagination component shows numbered page links.

Property detail pages

---
// src/pages/listings/[id].astro
import { getCollection, getEntry, render } from 'astro:content';
import { Image } from 'astro:assets';
import Base from '../../layouts/Base.astro';
import Enquiry from '../../components/Enquiry.astro';

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

const { listing } = Astro.props;
const { Content } = await render(listing);
const agent = await getEntry(listing.data.agent);
const [cover, ...gallery] = listing.data.images;
---
<Base title={`${listing.data.title} | Harbour Homes`} description={`${listing.data.beds} bed ${listing.data.type} in ${listing.data.address}.`}>
  <Image src={cover} alt={listing.data.title} widths={[640, 1024, 1600]} sizes="100vw" loading="eager" fetchpriority="high" />
  <h1>{listing.data.title}</h1>
  <p>{listing.data.address}</p>
  <dl class="facts">
    <dt>Bedrooms</dt><dd>{listing.data.beds}</dd>
    <dt>Bathrooms</dt><dd>{listing.data.baths}</dd>
    {listing.data.areaSqft && <><dt>Floor area</dt><dd>{listing.data.areaSqft} sq ft</dd></>}
  </dl>
  <Content />
  <div class="gallery grid gap-4 md:grid-cols-2">
    {gallery.map((img, i) => <Image src={img} alt={`${listing.data.title}, photo ${i + 2}`} width={800} height={533} />)}
  </div>
  <Enquiry listing={listing.data.title} agent={agent.data} />
</Base>

Only the cover photo loads eagerly. The gallery images keep <Image />’s default lazy loading, so a page with 30 photos still renders the first screen quickly. To open photos full-screen, the Astro image lightbox uses the native <dialog> element with a few lines of script.

Enquiry and valuation forms

Lead capture is the business goal of the site. A form that posts to your CRM’s web form endpoint, a form service or Netlify Forms keeps everything static. Include the listing title as a hidden field so the agent knows which property the lead is about.

---
// src/components/Enquiry.astro
const { listing, agent } = Astro.props;
---
<form method="post" action={import.meta.env.PUBLIC_ENQUIRY_ENDPOINT} class="enquiry">
  <h2>Ask {agent.name} about this home</h2>
  <input type="hidden" name="listing" value={listing} />
  <label>Name <input name="name" required autocomplete="name" /></label>
  <label>Email <input name="email" type="email" required autocomplete="email" /></label>
  <label>Phone <input name="phone" type="tel" autocomplete="tel" /></label>
  <label>Message <textarea name="message" rows="4">I'd like to arrange a viewing.</textarea></label>
  <button type="submit">Send enquiry</button>
  <p>Or call <a href={`tel:${agent.phone}`}>{agent.phone}</a></p>
</form>

Pulling listings from a feed

Many agencies already manage listings in a CRM or MLS system. Instead of copying them into Markdown, write a loader that fetches them at build time. An inline loader is just an async function returning entries:

// src/content.config.ts (feed version of the listings collection)
const listings = defineCollection({
  loader: async () => {
    const res = await fetch('https://crm.example.com/api/listings', {
      headers: { Authorization: `Bearer ${import.meta.env.CRM_TOKEN}` },
    });
    const data = await res.json();
    return data.items.map((item: any) => ({ id: item.slug, ...item }));
  },
  schema: z.object({ title: z.string(), price: z.number(), status: z.string() /* ... */ }),
});

Remote photos then use <Image /> with image.domains configured in astro.config.mjs. Schedule a rebuild (hourly or on a CRM webhook) to keep the site current. Check your feed’s terms first: MLS and IDX data usually comes with display rules and attribution requirements. If listings change by the minute, render the listing pages on demand with an adapter instead; the Astro SSR guide covers that set-up.

SEO for property sites

  • Give each listing a unique title and description built from its facts, as in the detail page above.
  • Add noindex or remove sold listings after a period, or keep them with a clear “Sold” status if they still attract searches.
  • Build area pages (/areas/old-port/) with a real paragraph about the neighbourhood plus its listings; they target “homes for sale in [area]” searches.
  • Generate a sitemap with @astrojs/sitemap so new listings are discovered quickly.

The official Astro images guide covers remote image configuration, and our folder structure docs explain where collections and assets live in a project.

Starting from a real estate template

If you’d rather customize than design from scratch, Komal Nakrani’s real estate category holds property themes for agencies, developers and rentals. One example is Cabin CMS, built for short-term rental properties such as vacation homes and cabins. Community themes on astro.build/themes are a free alternative for simpler sites.

FAQ

Is Astro good for real estate websites?

Yes. Real estate sites are mostly listings, photos and lead forms, which Astro renders as fast static pages. Typed Content Collections keep listing data consistent, <Image /> optimizes the many property photos, and forms can post to a CRM without a server.

How do I add property search to a static Astro site?

For a modest inventory, render all listings with data-* attributes and filter them with a short script. For larger catalogs, use a static search index such as Pagefind with filter attributes, or a hosted search service. For live inventory that changes constantly, render search results on demand with an adapter.

Can I connect an MLS or IDX feed to Astro?

Yes. Write a Content Collection loader that fetches listings from the feed’s API at build time, then rebuild on a schedule or webhook. Follow the feed provider’s display and attribution rules, which are often part of the data licence.

How should I handle sold listings?

Either remove them from the site and redirect their URLs to the area page, or keep them marked as sold for a period if they still attract visitors. Filtering by status in getCollection() makes either approach a one-line change.

How do I make property photos load fast?

Store photos in src/assets/ or a configured remote domain and render them with Astro’s <Image /> component. It resizes and converts them to modern formats at build time and lazy-loads everything except images you mark as eager, such as the cover photo.