Page metadata in Astro
Checked against the Astro docs (layouts and recipes) via Context7 on 2026-11-13. Astro has no
built-in metadata API. Metadata lives in a layout or a <Head> component that every page uses.
One layout, props in, tags out
---interface Props { title: string; description: string; image?: string; type?: 'website' | 'article'; }const { title, description, image = '/og-default.png', type = 'website' } = Astro.props;const canonical = new URL(Astro.url.pathname, Astro.site); // needs `site` in astro.configconst ogImage = new URL(image, Astro.site);---<html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>{title}</title> <meta name="description" content={description} /> <link rel="canonical" href={canonical} /> <meta property="og:title" content={title} /> <meta property="og:description" content={description} /> <meta property="og:type" content={type} /> <meta property="og:url" content={canonical} /> <meta property="og:image" content={ogImage} /> <meta name="twitter:card" content="summary_large_image" /> </head> <body><slot /></body></html>Make title and description required props. A default value is how every page ends up with
the same title (tech.unique-titles) or a missing description. If a page forgets them, the build
should fail, not ship a generic one.
Specifics
- Set
siteinastro.config.*. Without itAstro.siteis undefined and the canonical and OG URLs break. lang: for multilingual sites compute it from the route (the Astro i18n recipe derives it fromAstro.url) rather than hard-codingen.- Content collections: put
title,description,imageand anupdateddate in the frontmatter schema (zod), marktitleanddescriptionrequired, and pass them into the layout. That also givesaeo-content-freshnessa real date source. - Images: use the
<Image />component or<img>with analt. Astro requiresalton<Image />at build time; usealt=""for decoration. - Astro renders to static HTML by default, so tags are in the served HTML. If you added client-only
islands that set
document.title, move that to the layout.
Verify
Run astro build only if the user asks (heavy on small machines). Otherwise inspect the deployed
page with curl and look at the <head>.
AEO Toolkit is an open-source instrument by Advance Labs.