Skip to content

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:

package.json

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:

globals.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:

globals.css

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:

icons.ts
globals.css

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

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:

layout.tsx

isolate is Tailwind's class for isolation: isolate. Overlays 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:

globals.css

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.

assemble.tsx

Next steps

  • Styling covers state styling, className merging with cn, theme and writing direction.
  • Overlays covers portals, layering and choosing between Dialog, Popover, Menu and the other popups.
  • Colors and Typography list the tokens and text styles used above.
  • Each component page, starting with Button, documents its usage guidelines, anatomy, examples and API reference.