# Installation

> Add Dify UI to a workspace package, set up its styles, theme, icons and layering, and assemble a first component.

## Install the package

Dify UI is a private workspace package. It is consumed from source inside the Dify monorepo and is not published to npm. Add it to the consuming package:

```json title="package.json"
{
  "dependencies": {
    "@langgenius/dify-ui": "workspace:*"
  }
}
```

`react`, `react-dom`, `@base-ui/react`, `class-variance-authority` and `tailwindcss` are peer dependencies, so the consuming package provides them. Each component is a public subpath, such as `@langgenius/dify-ui/button`; there is no root barrel, and a bundle contains only the components it imports.

## Set up

### Styles

The root stylesheet imports Tailwind CSS first, then the Dify UI stylesheet once:

```css title="globals.css"
@import 'tailwindcss';
@import '@langgenius/dify-ui/styles.css';
```

The Dify UI stylesheet contributes the design tokens, the light and dark token values, the `dark:` variant and the typography utilities. It does not generate utilities on its own; that is Tailwind's engine, which the first import brings in.

### Source scanning

Components ship as source, and their classes live in that source. Tailwind generates only the classes it finds in scanned files, so the stylesheet registers the Dify UI `src/` directory with `@source` and excludes tests. Paths resolve from the stylesheet itself, so they depend on where it sits in the workspace:

```css title="globals.css"
@source '../../../packages/dify-ui/src';
@source not '../../../packages/dify-ui/src/**/*.{spec,test}.{ts,tsx}';
```

### Icons

Components draw icons from the Remix Icon set with `i-ri-*` classes. They come from the `@egoist/tailwindcss-icons` plugin with the `ri` collection from `@iconify-json/ri`, both installed as dev dependencies. The options match Dify UI's own plugin configuration, so icons keep the default size and display the components are written against:

```ts title="icons.ts"
import { getIconCollections, iconsPlugin } from '@egoist/tailwindcss-icons'

export default iconsPlugin({
  collections: getIconCollections(['ri']),
  extraProperties: {
    width: '1rem',
    height: '1rem',
    display: 'block',
  },
})
```

```css title="globals.css"
@plugin './icons.ts';
```

The plugin can register more collections next to `ri` for the application's own icons.

### Theme

Token values and the `dark:` variant both read the `data-theme` attribute on `<html>`, set to `light` or `dark`. Tokens have no values without it, so components render without colors. The system color scheme is not read directly; a theme library that follows it writes the attribute.

```html
<html data-theme="light"></html>
```

### Portals

Popups such as Dialog, Popover and Select render through a portal into `document.body` and set no `z-index`. The application root gets its own stacking context, so a `z-index` inside the application cannot rise above a popup:

```tsx title="layout.tsx"
<body>
  <div className="isolate">{children}</div>
</body>
```

`isolate` is Tailwind's class for `isolation: isolate`. [Overlays](/guides/overlays.md) covers the layering contract in full.

### iOS 26+ Safari

Starting with iOS 26, Safari shows page content beneath its browser chrome. Modal backdrops in Dify UI use `position: absolute` rather than `fixed` so they cover that area too. Positioning `body` keeps the backdrop covering the full viewport after the page has scrolled:

```css title="globals.css"
body {
  position: relative;
}
```

## Assemble a component

This Popover imports its parts from `@langgenius/dify-ui/popover` and a Button from `@langgenius/dify-ui/button`. The trigger renders the Button, the content brings its own portal, positioning and surface, and the remaining classes are Dify tokens and typography utilities. It exercises each setup step: tokens follow the theme, the icon comes from the `ri` collection, and the popup renders in a portal above the page.

```tsx title="assemble.tsx"
import { Button } from '@langgenius/dify-ui/button'
import {
  Popover,
  PopoverContent,
  PopoverDescription,
  PopoverTitle,
  PopoverTrigger,
} from '@langgenius/dify-ui/popover'

export function AssembleDemo() {
  return (
    <Popover>
      <PopoverTrigger
        render={
          <Button className="data-popup-open:bg-components-button-secondary-bg-hover data-popup-open:inset-ring-components-button-secondary-border-hover" />
        }
      >
        <span aria-hidden="true" className="i-ri-notification-3-line size-4" />
        Notifications
      </PopoverTrigger>
      <PopoverContent className="flex w-72 flex-col gap-1 p-4">
        <PopoverTitle className="system-md-semibold text-text-primary">Notifications</PopoverTitle>
        <PopoverDescription className="system-sm-regular text-text-tertiary">
          The Customer Support app finished publishing. Its API now serves version 3.
        </PopoverDescription>
      </PopoverContent>
    </Popover>
  )
}
```

## Next steps

- [Styling](/guides/styling.md) covers state styling, `className` merging with [`cn`](/utilities/cn.md), theme and writing direction.
- [Overlays](/guides/overlays.md) covers portals, layering and choosing between Dialog, Popover, Menu and the other popups.
- [Colors](/foundations/colors.md) and [Typography](/foundations/typography.md) list the tokens and text styles used above.
- Each component page, starting with [Button](/components/button.md), documents its usage guidelines, anatomy, examples and API reference.
