---
title: Header for Astro
description: "Astro header parts for a site logo, navigation, and actions."
seo:
    title: Header for Astro | Shadcn & Tailwind CSS
related:
    - Header blocks: /blocks/header
    - /components/navigation-menu
sidebar:
    label: "Header"
---

## Usage

```ts
import { Button } from "@/components/ui/button"
import { Header, HeaderContainer, HeaderGroup } from "@/components/ui/header"
import { Logo, LogoText } from "@/components/ui/logo"
```

## Examples

```astro
---
import { Button } from "@/components/ui/button"
import { Header, HeaderContainer, HeaderGroup } from "@/components/ui/header"
import { Logo, LogoText } from "@/components/ui/logo"
---

<Header>
  <HeaderContainer>
    <HeaderGroup>
      <Logo href="/">
        <LogoText>
          gnostic <span class="text-foreground/64">ui</span>
        </LogoText>
      </Logo>
    </HeaderGroup>

    <HeaderGroup class="ml-auto justify-end">
      <Button size="sm" variant="ghost">
        Sign In
      </Button>
      <Button size="sm">Sign Up</Button>
    </HeaderGroup>
  </HeaderContainer>
</Header>
```

## Installation

### Command

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

### Manual

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

No extra packages are required.

#### src/components/ui/header/header-container.astro

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

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="header-container"
  class={cn("relative mx-auto flex w-full max-w-7xl gap-4 px-4", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/header/header-group.astro

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

import { cn } from "cn"

type Props = HTMLAttributes<"div">

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

<div
  data-slot="header-group"
  class={cn("flex min-w-0 items-center gap-2", className)}
  {...props}
>
  <slot />
</div>
```

#### src/components/ui/header/header.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "cn"

type Props = HTMLAttributes<"header"> & VariantProps<typeof variants>

const variants = cva("@container/header relative z-50 flex w-full items-center gap-4 py-2", {
  variants: {
    variant: {
      default: "",
      floating: "bg-background mx-auto my-2 w-[calc(100%-2rem)] max-w-[calc(var(--container,1280px)-2rem)] overflow-hidden rounded-lg border shadow-sm",
    },
  },
  defaultVariants: {
    variant: "default",
  },
})

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

<header
  class={cn(variants({ variant }), className)}
  data-slot="header"
  data-variant={variant}
  {...props}
>
  <slot />
</header>
```

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

```ts
export { default as Header } from "./header.astro"
export { default as HeaderContainer } from "./header-container.astro"
export { default as HeaderGroup } from "./header-group.astro"
```

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.


```astro
---
import { Button } from "@/components/ui/button"
import { Header, HeaderContainer, HeaderGroup } from "@/components/ui/header"
import { Logo, LogoText } from "@/components/ui/logo"
---

<Header variant="floating">
  <HeaderContainer>
    <HeaderGroup>
      <Logo href="/">
        <LogoText>
          gnostic <span class="text-foreground/64">ui</span>
        </LogoText>
      </Logo>
    </HeaderGroup>

    <HeaderGroup class="ml-auto justify-end">
      <Button size="sm" variant="ghost">
        Sign In
      </Button>
      <Button size="sm">Sign Up</Button>
    </HeaderGroup>
  </HeaderContainer>
</Header>
```

## Notes

- `Header` controls the layout — `default` is full-width, `floating` is a constrained rounded card.
- `HeaderGroup` is an unopinionated flex row. Use utility classes like `ml-auto` or `justify-end` on the group when you need alignment.
- `HeaderContainer` is an optional middle slot when you need a flex region between left and right groups.
- For a mobile menu, use `Sheet` and `SheetTrigger` from `@/components/ui/sheet` directly inside a `HeaderGroup`.

## API Reference

Read the [installed source](/r/header.json) for the complete prop types.

## When to use Header

Use Header as the page-level header container, then add the logo, navigation, and actions through its parts. The default and floating variants change the shell; they do not choose navigation links for you.

## Keyboard and behavior

Keep a clear navigation landmark and label icon controls. A compact header still needs a working route to all primary links. Add a mobile menu composition when the full navigation does not fit.

## Theme and layout

Check the logo width, long link labels, and action spacing at narrow widths. Floating surfaces need enough contrast over the page beneath them. Sticky positioning is a page layout choice.
