Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Layout for Astro

Astro document parts for the page shell, head, body, and main content.

Use the Layout parts in a document shell or a template layout. The framed examples show how those parts arrange a page with its own document structure.

Installation

bunx --bun shadcn@latest add @gnostic/layout

Usage

---
import { Layout, LayoutBody, LayoutHead, LayoutMain } from "@/components/ui/layout"
---

<Layout lang="en">
    <LayoutHead name="gnostic ui" title="Page title" description="Page description" />
    <LayoutBody>
        <LayoutMain>
            <slot />
        </LayoutMain>
    </LayoutBody>
</Layout>

Responsive layout

Set containerSize on Layout to change the maximum section content width. For example, <Layout containerSize="64rem"> sets --container to 64rem on the document root. The default is Tailwind’s var(--container-7xl).

LayoutMain uses @container/main to create a responsive layout.

Notes

  • Layout owns the root <html> element and global visual baseline.
  • LayoutHead centralizes metadata, canonical URLs, and social tags.
  • Seo supplies the same metadata inside an existing <head>. Import it from @/components/ui/layout/seo.astro.
  • LayoutBody and LayoutMain provide the default body and page-content wrappers.
  • LayoutMain is a neutral structural wrapper for page content.

API Reference

LayoutHead and Seo share SeoProps from layout/types.ts. Both require a site name (name) and a page title (title). Each value must contain text.

LayoutProps

PropType
containerSize?string

The maximum content width. Sets `--container` on the document root.

Typestring
Default"var(--container-7xl)"

SeoProps

PropType
namestring

The name of the site.

Typestring
titlestring

The title of the page. Used for the `<title>` tag.

Typestring
description?string

The description of the page.

Typestring
image?{ src?: ImageMetadata | string; alt?: string }

The image of the page. Used for the `<meta property="og:image" content="...">` tag.

Type{ src?: ImageMetadata | string; alt?: string }
noindex?boolean

Whether to add the `noindex` attribute to the `<meta name="robots" content="...">` tag.

Typeboolean
nofollow?boolean

Whether to add the `nofollow` attribute to the `<meta name="robots" content="...">` tag.

Typeboolean
canonical?string

The canonical URL of the page. Used for the `<link rel="canonical" href="...">` tag.

Typestring
graph?Record<string, unknown> | null

The graph data for the page. Used for the `<script type="application/ld+json">` tag.

TypeRecord<string, unknown> | null
titleTemplate?string

Template for composing the full `<title>`. Use `%s` where the title should be substituted. Defaults to the raw `title`.

Typestring
preserveQueryParams?boolean

Keep the query string in the default canonical URL. Defaults to `false` (query params are stripped — the SEO-correct behavior for most cases). Has no effect when `canonical` is explicitly set.

Typeboolean
ogType?'website' | 'article' | 'profile' | 'book'

Open Graph type. Defaults to `'website'`.

Type'website' | 'article' | 'profile' | 'book'
ogImage?string

Absolute URL of the share image.

Typestring
ogImageAlt?string

Alt text for the share image.

Typestring
ogImageWidth?number

Width of the share image in pixels.

Typenumber
ogImageHeight?number

Height of the share image in pixels.

Typenumber
siteName?string

Site name shown in OG tags, e.g. `"Joost.blog"`.

Typestring
locale?string

OG locale. Defaults to `'en_US'`.

Typestring
twitter?{ /** Twitter handle of the site owner, e.g. `'@jdevalk'`. */ site?: string; /** Twitter handle of the author. */ creator?: string; /** Card type. Defaults to `'summary_large_image'`. */ card?: 'summary' | 'summary_large_image' | 'app' | 'player'; /** Override twitter:title. Omit to fall back to og:title. */ title?: string; /** Override twitter:description. Omit to fall back to og:description. */ description?: string; /** Override twitter:image. Omit to fall back to og:image. */ image?: string; /** Override twitter:image:alt. Omit to fall back to og:image:alt. */ imageAlt?: string; }

Twitter card metadata. Only Twitter-specific tags (card, site, creator) are emitted by default — twitter:title, :description, :image, and :image:alt fall back to their `og:` counterparts automatically. Set `title`, `description`, `image`, or `imageAlt` here only when you want Twitter-specific content that differs from the OG values.

Type{ /** Twitter handle of the site owner, e.g. `'@jdevalk'`. */ site?: string; /** Twitter handle of the author. */ creator?: string; /** Card type. Defaults to `'summary_large_image'`. */ card?: 'summary' | 'summary_large_image' | 'app' | 'player'; /** Override twitter:title. Omit to fall back to og:title. */ title?: string; /** Override twitter:description. Omit to fall back to og:description. */ description?: string; /** Override twitter:image. Omit to fall back to og:image. */ image?: string; /** Override twitter:image:alt. Omit to fall back to og:image:alt. */ imageAlt?: string; }
article?{ publishedTime?: Date | string; modifiedTime?: Date | string; expirationTime?: Date | string; authors?: readonly string[]; tags?: readonly string[]; section?: string; }

Article-specific OG metadata. Only emitted when `ogType` is `'article'`.

Type{ publishedTime?: Date | string; modifiedTime?: Date | string; expirationTime?: Date | string; authors?: readonly string[]; tags?: readonly string[]; section?: string; }
articlePublisher?string

Facebook page URL of the publisher. Emitted as `article:publisher` when `ogType` is `'article'`.

Typestring
author?string

Author name for the `<meta name="author">` tag. If omitted but `article.authors` is set, the first author is used.

Typestring
extraLinks?ReadonlyArray<Record<string, string>>

Extra `<link>` tags (icons, sitemap, RSS alternate, etc.).

TypeReadonlyArray<Record<string, string>>
extraMeta?ReadonlyArray<Record<string, string>>

Extra `<meta>` tags (author, custom fields).

TypeReadonlyArray<Record<string, string>>
alternates?BuildAlternateLinksInput

hreflang alternate-language annotations. Emits one `<link rel="alternate" hreflang="…" href="…">` per entry, plus an `x-default` entry pointing at the default-locale sibling (or the first entry, if no default match is found). Also emits matching `og:locale:alternate` tags.

TypeBuildAlternateLinksInput

Read the installed source for the complete prop types.

When to use Layout

Use Layout parts in the site template that owns the route. Set the document language and provide page metadata in the head. Keep reusable blocks inside the main content rather than making them own the document.

Keyboard and behavior

A page needs one main landmark and a logical heading order. Add a skip link when repeated navigation comes before the main content. These shell parts do not infer titles or canonical URLs from arbitrary content.

Theme and layout

Import the shared stylesheet once in your site layout. LayoutBody applies the preset background, text color, sans font, and font smoothing to the body. Theme and page background choices belong at this level. Avoid a second html or body element inside a reusable block.