---
title: Layout for Astro
description: "Astro document parts for the page shell, head, body, and main content."
seo:
    title: Layout for Astro | Shadcn & Tailwind CSS
related:
    - /components/section
    - /components/header
sidebar:
    label: "Layout"
---

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.

```astro
---
// @preview render=frame
import { LayoutMain } from "@/components/ui/layout"
---

<LayoutMain class="p-6">
  <h1 class="text-2xl @md/main:text-4xl font-semibold">Project overview</h1>
  <p class="mt-3 text-muted-foreground">The main content of an Astro page.</p>
</LayoutMain>
```

## Installation

### Command

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

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/layout/index.ts

```ts
export { default as Layout } from './layout.astro'
export { default as LayoutBody } from './layout-body.astro'
export { default as LayoutHead } from './layout-head.astro'
export { default as LayoutMain } from './layout-main.astro'
export { default as Seo } from './seo.astro'

export type { SeoProps } from './types.ts'
```

#### src/components/ui/layout/layout-body.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"body">

const { class: className, ...props } = Astro.props
---

<body
  class={cn(
    "bg-background text-foreground overscroll-none antialiased",
    className,
  )}
  data-slot="layout-body"
  {...props}
>
  <slot />
</body>

<style is:global>
  body {
    font-family: var(--font-sans);
  }
</style>
```

#### src/components/ui/layout/layout-head.astro

```astro
---
import Seo from "./seo.astro"
import type { SeoProps } from "./types.ts"

type Props = SeoProps

const {
  name,
  title,
  description,
  image,
  noindex,
  nofollow,
  canonical,
  graph,
  ...props
} = Astro.props
---

<head data-slot="layout-head" {...props}>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="generator" content={Astro.generator} />
  <Seo
    name={name}
    title={title}
    description={description}
    image={image}
    noindex={noindex}
    nofollow={nofollow}
    canonical={canonical}
    graph={graph}
  />
  <slot />
</head>
```

#### src/components/ui/layout/layout-main.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"main">

const { class: className, ...props } = Astro.props
---

<main
  data-slot="layout-main"
  class={cn(
    "@container/main flex flex-col in-data-[slot=sidebar-inset]:rounded-[inherit] not-in-data-[slot=sidebar-inset]:w-full",
    className,
  )}
  {...props}
>
  <slot />
</main>
```

#### src/components/ui/layout/layout.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"html">

const { class: className, lang, ...props } = Astro.props
---

<html
  class={cn(
    "bg-background text-foreground has-data-[variant=inset]:bg-sidebar overscroll-none scroll-smooth",
    className,
  )}
  data-slot="layout"
  lang={Astro.currentLocale || "en"}
  {...props}
>
  <slot />
</html>

<style is:global>
  :root {
    --container: 1280px;
    color-scheme: light;
  }

  .dark {
    color-scheme: dark;
  }

  @view-transition {
    navigation: auto;
  }
</style>
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```astro PageLayout.astro
---
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

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

```astro
---
import { LayoutMain } from "@/components/ui/layout"
---

<LayoutMain>
  <h1 class="text-[clamp(var(--text-3xl),1.5rem+3cqi,var(--text-6xl))] font-semibold">
    Responsive layout
  </h1>
  <p class="text-[clamp(var(--text-base),0.5rem+2cqi,var(--text-xl))] text-muted-foreground mt-3">
    Adjust the container width to see the text size change.
  </p>
</LayoutMain>
```

## 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`.

### SeoProps

<AutoTypeTable path="../../packages/ui/src/components/ui/layout/types.ts" name="SeoProps" />

Read the [installed source](/r/layout.json) 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

The layout imports shared styles so installed components use the same tokens. Theme and page background choices belong at this level. Avoid a second html or body element inside a reusable block.
