---
title: Port Base-UI To Astro
description: "Port Base-UI to Astro with server-rendered markup, data-slot behavior, and shadcn semantic tokens such as --background."
seo:
    title: "Port Base-UI To Astro"
search:
    keywords:
        - Port Base-UI To Astro
        - Base UI
        - data-slot
        - shadcn registry
        - semantic tokens
sidebar:
    label: Port Base-UI to Astro
mode: wide
related:
    - /docs
    - /docs/installation
    - /docs/theming
    - /docs/credits
    - /components
    - /themes
---

Port Base-UI to Astro when a React component tree must become HTML that Astro can render on the server. [Base UI](https://base-ui.com/) supplies React components. [data-slot](https://data-slot.com/base-ui-parity/#component-status) adds the same keyboard behavior, ARIA patterns, and many of the same state attributes to elements you write. gnostic-ui wraps those elements in Astro components. The installed source stays in your project. Read [Credits](/docs/credits) for the design sources, and the [introduction](/docs) for how components, blocks, and templates fit together.

The [Base UI parity](https://data-slot.com/base-ui-parity/#component-status) page is the part-by-part reference. This page records what that comparison means for an Astro port, and how shadcn themes stay on the same semantic tokens.

## What you keep

A port keeps the interaction model. Accordion, tabs, dialogs, menus, and the other controls in the status table below still open, close, and move focus with the keyboard. Popup parts still expose placement through `data-side` and `data-align`. Accordion and collapsible panels still publish their size as CSS variables such as `--accordion-panel-height`.

The runtime is the part that changes. You compose Astro components, or the `data-slot` attributes those components render. A React `render` prop, a `className` function, and a controlled `open` prop become markup, state attributes, and a small browser controller.

## Map the React API

| Base UI | Astro port |
| --- | --- |
| Compound components such as `Dialog.Popup` | An element with `data-slot="dialog-content"`, usually through [Dialog](/components/dialog) |
| `render` prop | The element you choose. Triggers are buttons. |
| `className` or `style` as a function of state | A selector for the attribute the controller sets, such as `[data-open]` or `[data-state=active]` |
| Controlled `value` or `open` | A controller method such as `open()` or `setValue()`, or a `<name>:set` event on the root |
| `onValueChange(value, eventDetails)` | An `onValueChange(value)` option and a bubbling `<name>:change` event |
| `defaultValue` and `defaultOpen` | The same JavaScript options, or `data-default-value` and `data-default-open`. JavaScript options win. |
| `<Portal>` | Popover, tooltip, hover card, select, combobox, dropdown menu, navigation menu, and drawer move the popup to `document.body` while it is open. Dialog and alert dialog move when you include their portal part. |
| `keepMounted` | Closed content stays in the document with `hidden` on accordion, collapsible, tabs, dialog, and alert dialog. Tooltip, hover card, select, and navigation menu can use `mountStrategy`. |
| Item arrays and object values | Items in the markup, each with a string `data-value` |
| Field, Fieldset, and Form | Native `label`, `fieldset`, and constraint validation. See [Field](/components/field) and [Form](/components/form). |
| `DirectionProvider` | The `dir` attribute |
| `Tooltip.Provider` | One shared warm-up window for every tooltip on the page |
| Unmounting the component | `destroy()` on the controller |

## Port a dialog

A Base UI dialog is a tree of React parts. The Astro version is the same tree as components. [Dialog](/components/dialog) renders the `data-slot` hooks and starts the controller:

```astro
---
import { Button } from "@/components/ui/button"
import {
	Dialog,
	DialogClose,
	DialogContent,
	DialogDescription,
	DialogFooter,
	DialogHeader,
	DialogTitle,
	DialogTrigger,
} from "@/components/ui/dialog"
---

<Dialog>
	<DialogTrigger>Open</DialogTrigger>
	<DialogContent>
		<DialogHeader>
			<DialogTitle>Notifications</DialogTitle>
			<DialogDescription>You are all caught up.</DialogDescription>
		</DialogHeader>
		<DialogFooter>
			<DialogClose variant="outline">Close</DialogClose>
			<Button>Continue</Button>
		</DialogFooter>
	</DialogContent>
</Dialog>
```

Those components render `data-slot="dialog"`, `dialog-trigger`, `dialog-portal`, `dialog-overlay`, `dialog-content`, `dialog-title`, `dialog-description`, and `dialog-close`. Closed overlay and content include `hidden`, so the page shows the server HTML until the script runs.

Installed dialog source creates controllers on `astro:page-load` and calls `destroy()` on `astro:before-swap`. View transitions replace the bound elements, so a controller must follow that cycle. To drive one dialog from script, query the root and use the controller:

```ts
import { createDialog } from "@data-slot/dialog"

const root = document.querySelector('[data-slot="dialog"]')
const dialog = createDialog(root)

dialog.open()
root?.dispatchEvent(new CustomEvent("dialog:set", { detail: { open: false } }))
root?.addEventListener("dialog:change", (event) => {
	console.log(event.detail.open)
})
```

`closeOnClickOutside: false` replaces `disablePointerDismissal`. Focus moves to an element with `autofocus`. The full option list is on the [parity page](https://data-slot.com/base-ui-parity/#dialog).

## Style from state

Popups and panels use `data-starting-style` and `data-ending-style`, and they wait for your CSS transition or animation before they hide. Most components also set `data-state`, so a selector written for Radix or shadcn/ui can keep its open, closed, active, on, and off rules.

| Meaning | Attribute to style |
| --- | --- |
| Open or closed | `data-open`, `data-closed`, and `data-state="open"` or `"closed"`. Collapsible sets `data-state` only. |
| Trigger of an open popup | `aria-expanded="true"`. Select and combobox triggers also get `data-open`. |
| Open accordion trigger | `data-panel-open` |
| Highlighted item | `data-highlighted`. [Command](/components/command) uses `data-selected`. |
| Selected option | `data-selected` |
| Checked | `data-checked` and `data-unchecked` on [Switch](/components/switch) and [Radio Group](/components/radio-group) |
| Pressed toggle | `data-state="on"` or `"off"` on [Toggle](/components/toggle) |
| Active tab | `data-state="active"` on the [Tabs](/components/tabs) trigger and panel |
| Disabled | `data-disabled` or `aria-disabled`, depending on the component |
| Placement | `data-side` and `data-align` |

Popover, tooltip, hover card, select, combobox, and dropdown menu default to a side offset of 4 and a collision padding of 8. Popups stay inside the viewport.

## Component status

Near parity means the core behavior is covered and the gaps are secondary options, parts, or names. Partial means a major feature or accessibility behavior can be missing. None means Base UI has no matching component. The linked guide is the Astro component in this library. The [parity page](https://data-slot.com/base-ui-parity/#component-status) lists every gap.

| Component | Guide | Base UI | Status | Main gaps |
| --- | --- | --- | --- | --- |
| Accordion | [Accordion](/components/accordion) | Accordion | Near parity | No Header part, per-item `onOpenChange`, or object values |
| Alert dialog | [Alert Dialog](/components/alert-dialog) | Alert Dialog | Partial | Outside content stays active. No `initialFocus`, `finalFocus`, detached triggers, or nesting attributes |
| Carousel | [Carousel](/components/carousel) | — | None | Base UI has no carousel |
| Collapsible | [Collapsible](/components/collapsible) | Collapsible | Near parity | Uses `data-state`. No root `disabled` |
| Combobox | [Combobox](/components/combobox) | Combobox | Partial | No multiple selection, chips, object values, limit, or virtualization |
| Command | [Command](/components/command) | — | None | Base UI has no command menu |
| Dialog | [Dialog](/components/dialog) | Dialog | Partial | Outside content stays active. No non-modal modes, `initialFocus`, or `finalFocus` |
| Drawer | [Drawer](/components/drawer) | Drawer | Partial | One snap point. No swipe area |
| Dropdown menu | [Dropdown Menu](/components/dropdown-menu) | Menu | Partial | No submenus, hover open, or multiple radio groups |
| Hover card | [Hover Card](/components/hover-card) | Preview Card | Near parity | No arrow, safe-polygon hover, or detached triggers |
| Navigation menu | [Navigation Menu](/components/navigation-menu) | Navigation Menu | Partial | No vertical orientation, nested menus, or collision avoidance |
| Popover | [Popover](/components/popover) | Popover | Partial | No `role="dialog"`, modal mode, hover open, arrow, or title part |
| Radio group | [Radio Group](/components/radio-group) | Radio Group, Radio | Near parity | No `form` prop or Field integration |
| Resizable | [Resizable](/components/resizable) | — | None | Base UI has no resizable panels |
| Select | [Select](/components/select) | Select | Partial | No multiple selection, scroll arrows, or typeahead on the closed trigger |
| Slider | [Slider](/components/slider) | Slider | Partial | At most two thumbs. No form name or value part |
| Switch | [Switch](/components/switch) | Switch | Near parity | No `form` prop or Field integration |
| Tabs | [Tabs](/components/tabs) | Tabs | Near parity | Arrow keys select a tab unless activation is manual |
| Toggle | [Toggle](/components/toggle) | Toggle | Near parity | Uses `data-state="on"` |
| Toggle group | [Toggle Group](/components/toggle-group) | Toggle Group | Near parity | Uses `data-state="on"`. No RTL arrow keys |
| Tooltip | [Tooltip](/components/tooltip) | Tooltip | Near parity | No provider scope, `closeDelay`, or safe-polygon hover |

Toast follows the Sonner API in data-slot. This library uses [Alert](/components/alert) for a message that stays in the page.

### Use native HTML for the rest

| Base UI | Astro equivalent |
| --- | --- |
| Autocomplete | [Combobox](/components/combobox) without `name`, or [Command](/components/command) for a list of actions |
| Avatar | [Avatar](/components/avatar) |
| Button | [Button](/components/button). `aria-disabled` keeps a disabled button focusable. |
| Checkbox and Checkbox Group | [Checkbox](/components/checkbox) inside [Field](/components/field) |
| Field, Fieldset, Form, Input | [Label](/components/label), [Field](/components/field), [Form](/components/form), and [Input](/components/input) |
| Meter | [Meter](/components/meter) |
| Number Field | [Input](/components/input) with `type="number"` |
| Progress | [Progress](/components/progress) |
| Scroll Area | [Scroll Area](/components/scroll-area) |
| Separator | [Separator](/components/separator) |
| Toolbar | [Toggle Group](/components/toggle-group) for a row of toggles |

Context menu, menubar, and OTP field have no data-slot package. Write those with native elements when a page needs them.

## Shadcn styles and semantic tokens

The styles for these components follow the [shadcn registry specification](https://ui.shadcn.com/docs/registry). A preset is a registry item. It carries the component recipe, colors, fonts, and radius. `bunx --bun shadcn@latest init --preset <id-or-url>` installs that item into an Astro project. [Installation](/docs/installation) shows the setup command. Gnostic choices that an upstream short code cannot store use a registry preset URL from the [theme generator](/themes).

Because the classes follow that spec, a theme can change values and leave the component source in place. Semantic tokens such as `--background` remain. The shared stylesheet maps each token into Tailwind:

```css
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-primary: var(--primary);
--color-card: var(--card);
```

`bg-background`, `text-foreground`, `bg-primary`, `bg-card`, `border-border`, and `ring-ring` then read the current theme. The same set includes `--secondary`, `--muted`, `--accent`, `--popover`, `--destructive`, `--input`, and their `-foreground` pairs. [Theming](/docs/theming) lists the tokens to edit. The [shadcn theming docs](https://ui.shadcn.com/docs/theming) are the reference for the token model.

A preset writes OKLCH color values and a `--radius` token. Light and dark mode each set the same variable names. Installed components contain the Tailwind utilities for the preset you chose. They do not contain a second copy of the color values. Change `--background` in the theme file, and every surface that uses `bg-background` follows it.

`data-state` on the ported controls is what lets a shadcn selector survive the move from React to Astro. An open dialog, an active tab, and a pressed toggle keep the state hooks those recipes already use. Switch and radio group are the exception: style `[data-checked]` and `[data-unchecked]` on those two.

## Continue

**[Install the registry](/docs/installation)**

Add the shared setup, then install component source.

**[Choose a theme](/docs/theming)**

Keep semantic tokens and change colors, fonts, and radius.

**[Open the theme generator](/themes)**

Compare presets and copy a registry preset URL.

**[Browse components](/components)**

Open the Astro guide for each control in the status table.
