---
title: Create an Astro UI theme
description: "Use the Gnostic theme generator to choose a style, brand colors, font, and radius. Export a complete preset for shadcn installation in Astro."
seo:
    title: "How to create an Astro theme with Gnostic"
sidebar:
    label: Theme generator
---

Open the [theme generator](/ui/themes) to compare Default, Glow, Soft, Graphite, and all eight shadcn styles.
A style controls component design. A palette controls colors. A saved theme
records both choices. Templates supply page layouts and content separately.
Open **Design** in the header to change the docs and examples. **Preset** applies
a complete named design, including colors, fonts, and radius. **Style** groups
component styles under **Gnostic** and **shadcn**. A style change keeps the current
color system and explicit font and radius choices. Import a shadcn code to use
its complete preset and color controls.

The font lists mark the style defaults with **(default)**. The font controls
show the current font names. **Radius** shows each size once. Gnostic uses
**md** (`0.625rem`) as its default. Soft adds a `1rem` choice for its default.
Select the style's default to follow future style changes, or select another
size to use a fixed radius. Each style sets its component radius classes. Luma buttons use
`rounded-4xl`, and Gnostic buttons use
`rounded-lg`. Vertical Tabs keep a maximum corner radius of `1rem`.

```astro
---
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import {
  Card,
  CardHeader,
  CardTitle,
  CardDescription,
  CardContent,
  CardFooter,
} from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import {
  Select,
  SelectTrigger,
  SelectValue,
  SelectContent,
  SelectItem,
} from "@/components/ui/select"
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"
import {
  Accordion,
  AccordionItem,
  AccordionTrigger,
  AccordionContent,
} from "@/components/ui/accordion"
import {
  Dialog,
  DialogTrigger,
  DialogContent,
  DialogHeader,
  DialogTitle,
  DialogDescription,
  DialogClose,
} from "@/components/ui/dialog"
---

<div class="@container/workbench mx-auto w-full max-w-4xl p-6 sm:p-10">
  <header class="mb-8 flex flex-wrap items-center justify-between gap-4">
    <div>
      <Badge variant="secondary">Workspace</Badge>
      <h2 class="mt-3 text-3xl font-semibold tracking-tight">
        Make room for good work.
      </h2>
    </div>
    <Dialog>
      <DialogTrigger variant="outline">Invite someone</DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Share your workspace</DialogTitle>
          <DialogDescription>
            Preview the dialog, input, and button styles together.
          </DialogDescription>
        </DialogHeader>
        <Label for="invite-email">Email address</Label>
        <Input id="invite-email" type="email" placeholder="you@example.com" />
        <Label for="invite-role">Role</Label>
        <Select defaultValue="member">
          <SelectTrigger id="invite-role" class="w-full">
            <SelectValue>Choose a role</SelectValue>
          </SelectTrigger>
          <SelectContent>
            <SelectItem value="member">Member</SelectItem>
            <SelectItem value="viewer">Viewer</SelectItem>
          </SelectContent>
        </Select>
        <DialogClose>Done</DialogClose>
      </DialogContent>
    </Dialog>
  </header>
  <Tabs defaultValue="overview" class="w-full">
    <TabsList>
      <TabsTrigger value="overview">Overview</TabsTrigger>
      <TabsTrigger value="details">Details</TabsTrigger>
    </TabsList>
    <TabsContent value="overview">
      <div class="mt-6 grid gap-6 @min-xl/workbench:grid-cols-2">
        <Card>
          <CardHeader>
            <CardTitle>A new project</CardTitle>
            <CardDescription>
              Give your next idea a place to start.
            </CardDescription>
          </CardHeader>
          <CardContent class="grid gap-3">
            <Label for="project-name">Project name</Label>
            <Input id="project-name" placeholder="Your next idea" />
          </CardContent>
          <CardFooter class="flex flex-wrap gap-3">
            <Button>Create project</Button>
            <Button variant="outline">View projects</Button>
          </CardFooter>
        </Card>
        <Card>
          <CardHeader>
            <CardTitle>Built for your team</CardTitle>
            <CardDescription>One style across all the details.</CardDescription>
          </CardHeader>
          <CardContent>
            <Accordion>
              <AccordionItem value="colors">
                <AccordionTrigger>Can I change the colors?</AccordionTrigger>
                <AccordionContent>
                  Choose a palette above. The selected style stays the same.
                </AccordionContent>
              </AccordionItem>
              <AccordionItem value="source">
                <AccordionTrigger>Do I own the source?</AccordionTrigger>
                <AccordionContent>
                  Yes. The registry installs editable Astro and CSS files.
                </AccordionContent>
              </AccordionItem>
            </Accordion>
          </CardContent>
          <CardFooter>
            <Button size="sm" variant="secondary">
              Explore the components
            </Button>
          </CardFooter>
        </Card>
      </div>
    </TabsContent>
    <TabsContent value="details">
      <p class="py-6 text-muted-foreground">
        Try each style with the same palette, then use the site toggle to check
        light and dark modes.
      </p>
    </TabsContent>
  </Tabs>
</div>
```

## Use an exported theme

Save the theme JSON, then generate a site from this workspace:

```sh
bun run gnostic create ../my-site --template sable --preset ./my-theme.json --yes
```

Or select a complete preset from the catalog:

```sh
bun run gnostic create ../my-site --template sable --preset earth --yes
```

## Choose colors

Use **Color theme** to select an authored palette. A color change keeps the
current component style. For example, select **Sand** colors and **Lyra**
components. Use the **Dark mode** switch to edit the dark values. Resetting
a color restores its palette value for the current mode.

To add a palette to this workspace, create a file such as
`packages/themes/palettes/dracula.css`. Declare its colors under `:root` and
`.dark`. Use `var(--primary)` when a token should follow the primary color.
Run `bun run registry:build`. The palette appears in the Design menu, at
`/themes/dracula.css`, and at `/r/preset-dracula.json`.
An optional JSON file in `packages/themes/presets/` can give a combination
of palette, style, and fonts its own name.

## Use the shadcn CLI

Copy the command from **Keep your theme** on the generator page. It uses a
short preset URL in an existing Astro project. For example:

```sh
bunx --bun shadcn@latest init --preset https://gnosticai.com/ui/p/b2fA
```

Then add components

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

The preset installs Astro styles and sets the registry in `components.json`.
Keep that registry URL: it preserves your selected recipe during component
updates. Follow the printed Tailwind setup instructions and import
`src/styles/tailwind.css` in your layout.

Design can also import a shadcn short code. Supported codes use Lucide icons,
the default menu color, and a color in the supplied shadcn data. A matching
code is shown when it can retain every design choice. Both `a` and `b` code
versions are supported. The short Gnostic URL uses that official code when
possible. Catalog presets can use a named URL such as `/p/n-soft`. Custom
Gnostic palettes and style-default fonts use a saved preset ID. Saved IDs keep
the complete preset and do not change when you edit the current preview.
A plain shadcn code by itself does not select the Gnostic Astro registry;
use the generated URL to install it. Earlier JSON preset URLs still work.

Run `bun run gnostic create` for guided setup. Add `--dry-run` to a command to
list the changes without writing files. The CLI is available from this private
workspace; it is not yet an npm package.

## Apply a theme to an existing site

The project needs Astro, Gnostic registry base styles, and `components.json`.
Apply changes color, font, and radius tokens within the installed component style.
The requested style must match `components.json`. To change component classes,
use the generated `shadcn init --preset <url> --reinstall` command after you review
local component edits. Then apply the token settings.
Run these commands from this workspace:

```sh
bun run gnostic theme check ./my-theme.json
bun run gnostic theme apply ./my-theme.json --cwd ../my-site --dry-run
bun run gnostic theme apply ./my-theme.json --cwd ../my-site
```

The CLI adds `gnostic-theme.css` beside the configured global stylesheet and
imports it after the layout's other imports. It sets the layout's preset boundary
to the installed style. Presets also update the configured registry URL
so later component installs use the same settings.
When several document layouts exist, add `--layout src/layouts/site.astro`.
This path is relative to the target project. The theme file path is relative
to the directory where you run the command.

Commit the `.gnostic/` folder with your theme. It records the applied recipe and
file hashes. The CLI stops before replacing a managed file with local edits.
Component files, content, and base styles stay intact. New generated templates
share the style through `src/lib/theme.ts`. Explicit preset props in other
sites keep their value. A computed HTML preset boundary requires manual setup.

## Export token CSS

```sh
bun run gnostic theme export ./my-theme.json --out ./my-theme.css
```

Check, apply, and export accept JSON, a built-in preset such as `earth`,
a supported shadcn code, or a Gnostic preset URL.
Export writes CSS to stdout when `--out` is absent. Add `--format json` to export
normalized JSON. Use the CSS export to merge local theme edits manually.

To use the CSS export manually, import it **after**
`src/styles/tailwind.css`. The file contains color, font, and radius tokens.
It does not change the utility classes in installed components. Use an export
with the same component style as the installed preset. To change component
styles, use the preset installation command and review the resulting source changes.

The docs shell, controls, examples, and overlays use the selected preset.
Fixed comparison samples and full template previews keep their assigned presets.
The site light/dark toggle controls both the documentation and the examples.
