---
title: Logo for Astro
description: "Astro brand containers with optional home-page links."
seo:
    title: Logo for Astro | Shadcn & Tailwind CSS
related:
    - Logo Blocks: /blocks/logos
    - Header: /components/header
sidebar:
    label: "Logo"
---

```astro
---
import { Logo, LogoImage, LogoText } from "@/components/ui/logo"
import logoDark from "@/assets/logo-dark.svg"
import logoLight from "@/assets/logo-light.svg"
---

<Logo>
  <LogoImage src={{ light: logoLight, dark: logoDark }} alt="Logo" />
  <LogoText class="flex items-center gap-1">
    <span>gnostic</span>
    <span class="text-foreground/64 font-semibold">ui</span>
  </LogoText>
</Logo>
```

## Installation

### Command

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

### Manual

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

No extra packages are required.

#### src/components/ui/logo/types.ts

```ts
import type { ImageMetadata } from 'astro'
import type { RemoteImageProps } from 'astro:assets'
import type { LocalImageProps } from 'astro:assets'

type SharedImageProps = Omit<RemoteImageProps | LocalImageProps, 'src'>

export type LogoImageProps = SharedImageProps & {
    /**
     * One image for both modes, or a light and dark pair.
     */
    src?:
        | ImageMetadata
        | {
              light: ImageMetadata
              dark: ImageMetadata
          }
}
```

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

```ts
export { default as Logo } from "./logo.astro"
export { default as LogoImage } from "./logo-image.astro"
export { default as LogoText } from "./logo-text.astro"
```

#### src/components/ui/logo/logo-image.astro

```astro
---
import { Image } from "astro:assets"
import type { LogoImageProps } from "./types"

import { cn } from "cn"

type Props = LogoImageProps

const {
  class: className,
  src,
  alt = "logo",
  sizes = "200px",
  widths = [200],
  ...props
} = Astro.props

const baseClasses = "w-auto shrink-0 h-6"

let srcLight: ImageMetadata | undefined = undefined
let srcDark: ImageMetadata | undefined = undefined

if (src && "light" in src && "dark" in src) {
  srcLight = src.light
  srcDark = src.dark
}
---

{srcLight && srcDark ? (
  <>
    <Image
      class={cn(baseClasses, "dark:hidden", className)}
      data-slot="logo-image"
      src={srcLight}
      fit="contain"
      alt={alt}
      sizes={sizes}
      widths={widths}
      {...(props as any)}
    />
    <Image
      class={cn(baseClasses, "hidden dark:block", className)}
      data-slot="logo-image"
      src={srcDark}
      fit="contain"
      sizes={sizes}
      widths={widths}
      alt={alt}
      {...(props as any)}
    />
  </>
) : src ? (
  <Image
    class={cn(baseClasses, className)}
    data-slot="logo-image"
    src={src}
    fit="contain"
    sizes={sizes}
    widths={widths}
    alt={alt}
    {...(props as any)}
  />
) : null}
```

#### src/components/ui/logo/logo-text.astro

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

import { cn } from "cn"

type Props = HTMLAttributes<"span">

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

<span class={cn("text-lg", className)} {...props}>
  <slot />
</span>
```

#### src/components/ui/logo/logo.astro

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

import { cn } from "cn"

type Props = HTMLAttributes<"div"> & HTMLAttributes<"a">

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

const Comp = href ? "a" : "div"
---

<Comp data-slot="logo" class={cn("flex h-10 items-center justify-start gap-2 text-base font-semibold whitespace-nowrap", className)} href={href} {...props}>
  <slot />
</Comp>
```

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

```ts
import { Logo, LogoImage, LogoText } from "@/components/ui/logo"
import logo from "@/assets/logo.svg"
```

```astro
<Logo>
  <LogoImage src={logo} alt="Logo" />
  <LogoText>gnosticai UI</LogoText>
</Logo>
```

For theme-specific marks, pass both sources on `src`.

```astro
<Logo href="/">
  <LogoImage src={{ light: logoLight, dark: logoDark }} alt="Logo" />
  <LogoText>gnosticai UI</LogoText>
</Logo>
```

## Notes

- `Logo` becomes an anchor automatically when you pass `href`.
- `LogoImage` is optional, which makes text-only marks straightforward.
- Use `src` for a single logo. Pass `{ light, dark }` when the mark changes
  by theme.
- Use `Logo` for compact brand marks and site headers, not for general-purpose
  hero artwork.

## Examples

### Responsive Logo

Adjust the container width to see the logo image and text respond to the container width.

```astro
---
import { Logo, LogoImage, LogoText } from "@/components/ui/logo"
import logo from "@/assets/gnostic-ai-logo.svg"
---

<!--
  Put the query container on a parent that has a width.
  Logo sizes to the icon, so it cannot be that container.
-->
<div class="@container flex w-full justify-center">
  <Logo href="/" class="h-auto">
    <LogoImage
      src={logo}
      alt="Logo"
      widths={[100, 200]}
      class="h-auto w-[clamp(24px,1rem+10cqi,96px)]"
    />
    <LogoText class="hidden items-center gap-1 @2xs:flex text-[clamp(18px,1rem+8cqi,72px)]">
      <span>gnostic</span>
      <span class="text-foreground/64 font-semibold">ui</span>
    </LogoText>
  </Logo>
</div>
```

### SVG Logo

The `Logo` accepts a default slot, where you can pass an SVG component.

```astro
---
import { Logo, LogoText } from "@/components/ui/logo"
import LogoSvg from "@/assets/gnostic-ai-logo.svg"
---

<Logo>
  <LogoSvg class="h-6 w-fit" />
  <LogoText class="flex items-center gap-1">
    <span>gnostic</span>
    <span class="text-foreground/64 font-semibold">ui</span>
  </LogoText>
</Logo>
```

## API Reference

### LogoImageProps

<AutoTypeTable path="../../packages/ui/src/components/ui/logo/types.ts" name="LogoImageProps" />
## When to use Logo

Place a symbol, wordmark, or text inside Logo. Set `href` when it should act as a link. Keep the brand mark separate from navigation so it can be reused in headers and footers.

## Keyboard and behavior

A linked image needs an accessible name for its destination. If the wordmark is also visible text, avoid announcing the name twice. Use a normal anchor for home navigation.

## Theme and layout

Check the mark on light, dark, and tinted surfaces. Prefer artwork with an intentional dark-mode treatment instead of applying a filter that changes brand colors unpredictably.
