---
name: radix-ui
description: Expert guidance for building React UIs with Radix Themes and Radix Primitives. Use when creating accessible, customisable UI components, setting up theming systems, working with pre-styled Radix Themes components, or building custom components on top of unstyled Radix Primitives. Trigger keywords include "radix", "radix ui", "radix themes", "radix primitives", "accessible components", "Dialog", "Dropdown", "Select", "Accordion", "Tabs", "Tooltip".
---
# Radix UI
Radix provides two complementary libraries for React:
- **Radix Themes**: Pre-styled, ready-to-use component library with built-in theming
- **Radix Primitives**: Unstyled, accessible component primitives for custom design systems
## Choosing Between Themes and Primitives
**Use Radix Themes when:**
- Building applications quickly with minimal styling effort
- Wanting a consistent, polished design out of the box
- Theming via configuration props is sufficient
**Use Radix Primitives when:**
- Building a custom design system with complete styling control
- Integrating with existing styling solutions (Tailwind, styled-components, CSS modules)
- Needing only specific components without a full theme system
## Quick Start
### Radix Themes Setup
```bash
npm install @radix-ui/themes
```
```tsx
import "@radix-ui/themes/styles.css";
import { Theme } from "@radix-ui/themes";
export default function App() {
return (
);
}
```
### Radix Primitives Setup
Install individual components:
```bash
npm install @radix-ui/react-dialog @radix-ui/react-dropdown-menu
```
Or install the full package:
```bash
npm install radix-ui
```
## Radix Themes
### Theme Configuration
The `Theme` component accepts these props:
| Prop | Values | Default |
| ----------------- | ------------------------------------- | ----------- |
| `accentColor` | indigo, cyan, crimson, orange, etc. | indigo |
| `grayColor` | gray, mauve, slate, sage, olive, sand | gray |
| `radius` | none, small, medium, large, full | medium |
| `scaling` | 90%, 95%, 100%, 105%, 110% | 100% |
| `panelBackground` | solid, translucent | translucent |
### Component Variants
Most Themes components support these variant props:
```tsx
```
Common variants: `classic`, `solid`, `soft`, `surface`, `outline`, `ghost`
Sizes: `"1"`, `"2"`, `"3"`, `"4"` (component-specific)
### Layout Components
```tsx
import { Flex, Box, Grid, Container, Section } from "@radix-ui/themes";
Content
1
2
3
```
### Typography
```tsx
import { Text, Heading, Code, Em, Strong } from "@radix-ui/themes";
Title
Body text
const x = 1
```
For complete Themes component reference, see [references/themes-components.md](references/themes-components.md).
## Radix Primitives
### Core Concepts
**Compound Components**: Primitives use a compound component pattern with multiple parts:
```tsx
import * as Dialog from "@radix-ui/react-dialog";
Open
Title
Description
Close
;
```
**Uncontrolled by Default**: Components work without state management:
```tsx
// Uncontrolled - manages its own state
...
// Controlled - you manage the state
...
```
### The asChild Prop
Use `asChild` to compose Radix behaviour onto custom components:
```tsx
import * as Tooltip from "@radix-ui/react-tooltip";
import { MyButton } from "./MyButton";
Hover me
;
```
Requirements for custom components with `asChild`:
1. Spread all props onto the underlying DOM element
2. Forward refs using `React.forwardRef`
```tsx
const MyButton = React.forwardRef(
({ children, ...props }, ref) => (
),
);
```
### Styling Primitives
**With CSS classes:**
```tsx
```
**With data attributes for state:**
```css
.accordion-item[data-state="open"] {
background: var(--accent-3);
}
.accordion-item[data-state="closed"] {
background: transparent;
}
```
**With Tailwind CSS:**
```tsx
```
For complete Primitives patterns, see [references/primitives-patterns.md](references/primitives-patterns.md).
## Accessibility
Radix Primitives implement WAI-ARIA patterns automatically:
- Focus management and trapping (modals)
- Keyboard navigation (arrow keys, Tab, Escape)
- Screen reader announcements
- Proper ARIA attributes
Ensure custom implementations maintain accessibility:
```tsx
// Dialog requires Title for screen readers
Required for a11y
{/* If no description, set aria-describedby={undefined} on Content */}
```