---
title: Install Gnostic UI in Astro
description: "Add shadcn style components to Astro with the Gnostic registry. Set up Tailwind CSS, shared styles, and fonts, then install editable component source."
seo:
    title: "Install shadcn UI components in Astro"
sidebar:
    label: Installation
---

Complete this setup once. Then use each component's **Command** or **Manual**
tab to add its source and any extra packages.

The shared setup includes Tailwind, animation styles, `cn`,
`class-variance-authority`, and Lucide icons. Component pages list only the extra
packages they need, such as a `@data-slot` controller, Embla Carousel, or Motion.

## Prepare your Astro project

Use Astro 7, Tailwind 4, and Node 22.12 or later. If you need a new project:

```sh
bun create astro@latest my-site
cd my-site
```

Add the source alias to `tsconfig.json`. Keep any existing options:

```json
{
    "extends": "astro/tsconfigs/strict",
    "compilerOptions": {
        "paths": { "@/*": ["./src/*"] }
    }
}
```

## Install the shared setup

Choose **Command** to use the shadcn CLI, or **Manual** to inspect and copy each
file yourself. Both use the same registry source.

The CLI checks for Tailwind before it runs. If Tailwind is not yet installed,
run this command first:

```sh
bun add tailwindcss @tailwindcss/vite
```

If you do not have a Tailwind entry file, create `src/styles/tailwind.css`:

```css
@import "tailwindcss";
```

For manual installation, skip these two steps. The **Manual** tab below includes
the Tailwind packages and the complete stylesheet.

The `init --preset` command installs the preset selected in **Design**. It creates
`components.json`, configures the `@gnostic` registry, and installs the shared
packages and font configuration. The CLI merges preset tokens and shared rules into
the configured Tailwind stylesheet. Existing site rules remain in that file.
Keep the Tailwind configuration and stylesheet import in the next step.

### Command

```sh
bunx --bun shadcn@latest init --preset https://ui.gnosticai.com/r/preset-default.json
```

### Manual

Install the shared packages once, then copy the files below to their target paths. Merge the CSS into your Tailwind entry file and keep existing site rules.

Install the shared packages:

```sh
bun add @lucide/astro class-variance-authority cn shadcn tailwindcss tw-animate-css
bun add -d @tailwindcss/vite
```

#### THIRD-PARTY-NOTICES.md

```markdown
# Upstream component style licenses

The shadcn class maps and Fulldev Astro adaptations use the MIT license.

Copyright (c) 2023 shadcn

Copyright (c) 2024 Fulldev, Sil Veltman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

#### src/lib/fonts.ts

```ts
// Generated from the selected preset. Do not edit directly.
// Change the preset to generate a new font selection.
import { fontProviders } from 'astro/config'
import type { AstroUserConfig, FontProvider } from 'astro'

export const fonts = [
{ provider: fontProviders.fontshare(), ...{
    "name": "Satoshi",
    "cssVariable": "--font-satoshi",
    "weights": [
        "300 900"
    ],
    "styles": [
        "normal",
        "italic"
    ],
    "fallbacks": [
        "sans-serif"
    ],
    "subsets": [
        "latin"
    ],
    "display": "swap"
} },
{ provider: fontProviders.google(), ...{
    "name": "Instrument Serif",
    "cssVariable": "--font-instrument-serif",
    "weights": [
        400
    ],
    "styles": [
        "normal",
        "italic"
    ],
    "fallbacks": [
        "serif"
    ],
    "subsets": [
        "latin"
    ],
    "display": "swap"
} },
{ provider: fontProviders.fontsource(), ...{
    "name": "IBM Plex Mono",
    "cssVariable": "--font-ibm-plex-mono",
    "weights": [
        400,
        500,
        600,
        700
    ],
    "styles": [
        "normal",
        "italic"
    ],
    "fallbacks": [
        "monospace"
    ],
    "subsets": [
        "latin"
    ],
    "display": "swap"
} }
] satisfies NonNullable<AstroUserConfig<never, never, FontProvider[]>['fonts']>
```

#### src/styles/tailwind.css

```css
@import "tailwindcss";
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@custom-variant dark (&:where(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *));
@utility text-hero {
font-size: clamp(
        calc(var(--typeset-size, 1rem) * var(--heading-min, 2.25)),
        calc(var(--typeset-size, 1rem) + 6cqi),
        calc(var(--typeset-size, 1rem) * var(--heading-max, 4.5))
    );
line-height: 1.1;
}
@utility text-page-title {
font-size: clamp(
        calc(var(--typeset-size, 1rem) * var(--heading-min, 1.875)),
        calc(var(--typeset-size, 1rem) + 5cqi),
        calc(var(--typeset-size, 1rem) * var(--heading-max, 3.75))
    );
line-height: 1.15;
}
@utility text-section-title {
font-size: clamp(
        calc(var(--typeset-size, 1rem) * var(--heading-min, 1.875)),
        calc(var(--typeset-size, 1rem) + 4cqi),
        calc(var(--typeset-size, 1rem) * var(--heading-max, 3))
    );
line-height: 1.2;
}
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
--selection-bg: color-mix(in srgb, var(--primary) 72%, transparent);
}
@supports selector(contrast-color) {
body ::selection {
background-color: var(--selection-bg);
color: contrast-color(var(--selection-bg));
}
}
body &::selection {
background-color: var(--selection-bg);
color: var(--primary-foreground);
}
}
@media (prefers-reduced-motion: reduce) {
*,
    ::before,
    ::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
@keyframes skeleton {
to {
background-position: -200% 0;
}
}
:root[data-theme="dark"] {
--background: oklch(0.188 0 0);
--card: oklch(0.204 0 0);
--popover: oklch(0.204 0 0);
--primary: oklch(0.56 0.198 278.555);
--secondary: oklch(1 0 0 / 0.04);
--muted: oklch(1 0 0 / 0.04);
--accent: oklch(1 0 0 / 0.04);
--border: oklch(1 0 0 / 0.06);
--input: oklch(1 0 0 / 0.08);
--ring: oklch(0.556 0 0);
--sidebar: oklch(0.171 0 0);
--sidebar-border: oklch(1 0 0 / 0.05);
--sidebar-ring: oklch(0.708 0 0);
--foreground: oklch(0.97 0 0);
--card-foreground: oklch(0.97 0 0);
--popover-foreground: oklch(0.97 0 0);
--primary-foreground: oklch(0.97 0 0);
--secondary-foreground: oklch(0.97 0 0);
--accent-foreground: oklch(0.97 0 0);
--muted-foreground: oklch(0.612 0 0);
--sidebar-foreground: oklch(0.682 0 0);
--sidebar-primary: oklch(0.56 0.198 278.555);
--sidebar-primary-foreground: oklch(0.97 0 0);
--sidebar-accent: oklch(1 0 0 / 0.04);
--sidebar-accent-foreground: oklch(0.97 0 0);
--destructive: oklch(0.673 0.213 25.331);
--destructive-foreground: oklch(0.704 0.191 22.216);
--info: oklch(0.623 0.214 259.815);
--info-foreground: oklch(0.707 0.165 254.624);
--success: oklch(0.696 0.17 162.48);
--success-foreground: oklch(0.765 0.177 163.223);
--warning: oklch(0.769 0.188 70.08);
--warning-foreground: oklch(0.828 0.189 84.429);
--chart-1: oklch(0.56 0.198 278.555);
--chart-2: oklch(1 0 0 / 0.04);
--chart-3: oklch(0.577 0.19 278.555 / 0.52);
--chart-4: oklch(0.662 0.148 278.555);
--chart-5: oklch(0.973 0 0 / 0.28);
}
@theme inline {
--radius-xs: var(--radius-xs);
--radius-sm: var(--radius-sm);
--radius-md: var(--radius-md);
--radius-lg: var(--radius-lg);
--radius-xl: var(--radius-xl);
--radius-2xl: var(--radius-2xl);
--radius-3xl: var(--radius-3xl);
--radius-4xl: var(--radius-4xl);
--font-sans: var(--font-sans);
--font-serif: var(--font-serif);
--font-mono: var(--font-mono);
--font-heading: var(--font-heading);
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-ring: var(--ring);
--color-input: var(--input);
--color-border: var(--border);
--color-destructive: var(--destructive);
--color-destructive-foreground: var(--destructive-foreground);
--color-accent-foreground: var(--accent-foreground);
--color-accent: var(--accent);
--color-muted-foreground: var(--muted-foreground);
--color-muted: var(--muted);
--color-secondary-foreground: var(--secondary-foreground);
--color-secondary: var(--secondary);
--color-primary-foreground: var(--primary-foreground);
--color-primary: var(--primary);
--color-popover-foreground: var(--popover-foreground);
--color-popover: var(--popover);
--color-card-foreground: var(--card-foreground);
--color-card: var(--card);
--color-sidebar-ring: var(--sidebar-ring);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar: var(--sidebar);
--color-chart-1: var(--chart-1);
--color-chart-2: var(--chart-2);
--color-chart-3: var(--chart-3);
--color-chart-4: var(--chart-4);
--color-chart-5: var(--chart-5);
--color-info: var(--info);
--color-info-foreground: var(--info-foreground);
--color-success: var(--success);
--color-success-foreground: var(--success-foreground);
--color-warning: var(--warning);
--color-warning-foreground: var(--warning-foreground);
--animate-skeleton: skeleton 2s -1s infinite linear;
}
:root {
--background: oklch(1 0 0);
--card: oklch(1 0 0);
--popover: oklch(1 0 0);
--primary: oklch(0.536 0.208 264.67);
--secondary: oklch(0 0 0 / 0.04);
--muted: oklch(0 0 0 / 0.04);
--accent: oklch(0 0 0 / 0.04);
--border: oklch(0 0 0 / 0.08);
--input: oklch(0 0 0 / 0.1);
--ring: oklch(0.708 0 0);
--sidebar: oklch(0.985 0 0);
--sidebar-border: oklch(0 0 0 / 0.06);
--sidebar-ring: oklch(0.708 0 0);
--foreground: oklch(0.269 0 0);
--card-foreground: oklch(0.269 0 0);
--popover-foreground: oklch(0.269 0 0);
--primary-foreground: oklch(0.97 0 0);
--secondary-foreground: oklch(0.269 0 0);
--accent-foreground: oklch(0.269 0 0);
--muted-foreground: oklch(0.5 0 0);
--sidebar-foreground: oklch(0.527 0 0);
--sidebar-primary: oklch(0.536 0.208 264.67);
--sidebar-primary-foreground: oklch(0.97 0 0);
--sidebar-accent: oklch(0 0 0 / 0.04);
--sidebar-accent-foreground: oklch(0.269 0 0);
--destructive: oklch(0.637 0.237 25.331);
--destructive-foreground: oklch(0.505 0.213 27.518);
--info: oklch(0.623 0.214 259.815);
--info-foreground: oklch(0.488 0.243 264.376);
--success: oklch(0.696 0.17 162.48);
--success-foreground: oklch(0.508 0.118 165.612);
--warning: oklch(0.769 0.188 70.08);
--warning-foreground: oklch(0.555 0.163 48.998);
--chart-1: oklch(0.536 0.208 264.67);
--chart-2: oklch(0 0 0 / 0.04);
--chart-3: oklch(0.516 0.2 264.67 / 0.52);
--chart-4: oklch(0.469 0.156 264.67);
--chart-5: oklch(0.24 0 0 / 0.28);
--font-sans: var(--font-satoshi, "Satoshi"), ui-sans-serif, system-ui, sans-serif;
--font-serif: var(--font-instrument-serif, ui-serif), Georgia, Cambria, "Times New Roman", Times, serif;
--font-mono: var(--font-ibm-plex-mono, ui-monospace), SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
--font-heading: var(--font-sans);
--font-weight-normal: 450;
--radius: 0.625rem;
--radius-xs: calc(var(--radius) * 0.2);
--radius-sm: calc(var(--radius) * 0.6);
--radius-md: calc(var(--radius) * 0.8);
--radius-lg: calc(var(--radius) * 1);
--radius-xl: calc(var(--radius) * 1.4);
--radius-2xl: calc(var(--radius) * 1.8);
--radius-3xl: calc(var(--radius) * 2.2);
--radius-4xl: calc(var(--radius) * 2.6);
}
.dark {
--background: oklch(0.188 0 0);
--card: oklch(0.204 0 0);
--popover: oklch(0.204 0 0);
--primary: oklch(0.56 0.198 278.555);
--secondary: oklch(1 0 0 / 0.04);
--muted: oklch(1 0 0 / 0.04);
--accent: oklch(1 0 0 / 0.04);
--border: oklch(1 0 0 / 0.06);
--input: oklch(1 0 0 / 0.08);
--ring: oklch(0.556 0 0);
--sidebar: oklch(0.171 0 0);
--sidebar-border: oklch(1 0 0 / 0.05);
--sidebar-ring: oklch(0.708 0 0);
--foreground: oklch(0.97 0 0);
--card-foreground: oklch(0.97 0 0);
--popover-foreground: oklch(0.97 0 0);
--primary-foreground: oklch(0.97 0 0);
--secondary-foreground: oklch(0.97 0 0);
--accent-foreground: oklch(0.97 0 0);
--muted-foreground: oklch(0.612 0 0);
--sidebar-foreground: oklch(0.682 0 0);
--sidebar-primary: oklch(0.56 0.198 278.555);
--sidebar-primary-foreground: oklch(0.97 0 0);
--sidebar-accent: oklch(1 0 0 / 0.04);
--sidebar-accent-foreground: oklch(0.97 0 0);
--destructive: oklch(0.673 0.213 25.331);
--destructive-foreground: oklch(0.704 0.191 22.216);
--info: oklch(0.623 0.214 259.815);
--info-foreground: oklch(0.707 0.165 254.624);
--success: oklch(0.696 0.17 162.48);
--success-foreground: oklch(0.765 0.177 163.223);
--warning: oklch(0.769 0.188 70.08);
--warning-foreground: oklch(0.828 0.189 84.429);
--chart-1: oklch(0.56 0.198 278.555);
--chart-2: oklch(1 0 0 / 0.04);
--chart-3: oklch(0.577 0.19 278.555 / 0.52);
--chart-4: oklch(0.662 0.148 278.555);
--chart-5: oklch(0.973 0 0 / 0.28);
}
```

Follow the Tailwind configuration and global stylesheet import steps in this guide.


Manual installation does not need `components.json`. Select the same preset in
**Design** before copying the setup files and each component. Merge the shown
CSS into your Tailwind entry file; keep your existing site rules. To use registry
commands later, select that preset and run the setup command above. Review the
file changes before accepting replacements in an existing project.

Keep the `components.json` configuration written by that command, including the
complete `@gnostic` registry URL. It selects the same classes for later component
installs. The command does not add the Tailwind plugin to your Astro config.

## Connect Tailwind and fonts

Add the Tailwind Vite plugin to `astro.config.ts`. If your project already has
this plugin, keep that configuration. Enable it once. Import the selected font config from the installed setup.

```ts
import { defineConfig } from "astro/config"
import tailwindcss from "@tailwindcss/vite"
import { fonts } from "./src/lib/fonts"

export default defineConfig({
    fonts,
    vite: { plugins: [tailwindcss()] },
})
```

Import the global stylesheet once in your site layout. For example,
`src/layouts/Layout.astro`:

```astro
---
import "@/styles/tailwind.css"
import { Font, fontData, type CssVariable } from "astro:assets"
---

<html lang="en">
  <head>
    {(Object.keys(fontData) as CssVariable[]).map((cssVariable, index) => (
      <Font
        cssVariable={cssVariable}
        preload={index === 0 ? [{ weight: 400, style: "normal" }] : false}
      />
    ))}
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>My site</title>
  </head>
  <body>
    <slot />
  </body>
</html>
```

Astro downloads the selected fonts during the build and serves them from your
site. The selected config lists the body font first. The example preloads that
font only. Remove the `preload` prop if
that font is not used above the fold. Keep existing font entries when merging
`fonts` into an established project. The shadcn CLI supplies these source files;
it does not connect your Astro config or layout automatically.

Astro font variables use the font name, such as `--font-satoshi` or
`--font-instrument-serif`. The preset maps these names to Tailwind's
`--font-sans` and `--font-heading` style tokens. `--font-serif` uses Instrument
Serif, and `--font-mono` uses IBM Plex Mono. Both have system fallbacks. Generated
sites register these defaults, the selected body and heading fonts, and required
block fonts. The full catalog loader belongs to the docs app.

The Tailwind entry file contains the selected preset tokens and shared rules.
Separate files contain Astro font configuration. Component styles are
Tailwind classes in the copied source. You can
edit that source in your project.

## Use an existing shadcn project

To keep an existing theme, add this namespace to the `registries` field in
`components.json`. Keep the other configuration fields and registries:

```json
{
    "registries": {
        "@gnostic": "https://ui.gnosticai.com/r/{name}.json"
    }
}
```

Then add the shared rules and a component:

```sh
bunx --bun shadcn@latest add @gnostic/init @gnostic/lightbox-carousel
```

`@gnostic/init` merges shared rules and installs shared packages. It leaves the
existing color tokens and font files unchanged. This namespace uses the default
Gnostic component classes. To select a complete Gnostic preset instead, use
`init --preset` as shown above.

Gnostic source imports `cn` directly from the `cn` package. If your project uses
`src/lib/utils.ts`, keep that file. The optional `@gnostic/utils` item remains
available and exports `cn` at that path. It is not installed by default.
Keep your existing file when the CLI offers to overwrite it.

## Add components and blocks

Choose a [component](/components) or [block](/blocks), then use its command:

```sh
bunx --bun shadcn@latest add @gnostic/button @gnostic/card
```

The CLI installs the required source and packages. For manual installation,
open the component's **Manual** tab. Install its extra packages, if listed, and
copy the files to the shown target paths. Shared packages and files from this
guide do not need to be installed again.

Components and blocks do not install the shared setup again. They use the
project's existing tokens and fonts. Blocks that render prose install their own Typeset CSS.
Keep the preset registry URL in `components.json` to select the component
classes. Passing a preset does not reduce the required component files.

For example, add Lightbox Carousel after setup:

```sh
bunx --bun shadcn@latest add @gnostic/lightbox-carousel
```

It includes Button, Carousel, Lightbox, Dialog, Scroll Area, and Spinner.
Existing files are skipped when their content matches. Local changes
can cause an overwrite prompt.

Components install into `src/components/ui/<name>/`. Blocks install into
`src/components/blocks/<category>/`. Relative imports keep the source files
connected. Use the layout above on your pages:

```astro
---
import Layout from "../layouts/Layout.astro"
import { Button } from "@/components/ui/button"
---

<Layout>
  <Button>Continue</Button>
</Layout>
```

## Choose a preset

Use **Design** or the [theme generator](/themes) to select component styles,
colors, fonts, and radius as one preset. The setup command and Manual source
follow this selection.

Changing colors or fonts updates tokens. Changing the component style requires
new component classes. Review local changes before a preset reinstall; loading
another stylesheet does not replace installed classes. Read
[Theming](/docs/theming) for the supported update paths.

Keep the registry URL written by `init --preset`. It preserves the complete
preset when you install more components.
Short preset URLs use `/p/<code-or-id>`. The saved registry URL retains that
selection, so later `add @gnostic/...` commands use the same component classes.
Keep the query field in that URL. Earlier URLs with a `config` field remain
supported.

## Serif accent fonts for editorial blocks

The shared preset setup includes Instrument Serif for `font-serif` and IBM Plex
Mono for `font-mono`. Both include normal and italic styles. They do not replace
the selected body or heading font.

Agency's editorial accents use `font-serif`. They inherit the project's serif
font through `--font-serif`. There is no separate accent font module to install
or merge into the Astro config.

Complete the [shared Astro setup](/docs/installation) and render the registered
fonts in the document head. The generated `src/lib/fonts.ts` includes the default
serif and mono fonts. Astro serves the font files from your site; no remote font
stylesheet is required.
