Convert Figma logo to code with AI

radix-ui logoprimitives

Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.

15,356
765
15,356
482

Top Related Projects

37,442

⚡️ Simple, Modular & Accessible UI Components for your React Applications

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.

68,588

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.

Quick Overview

Radix UI Primitives is a low-level UI component library for building high-quality, accessible design systems and web applications. It provides a set of unstyled, functional components that handle complex interactions and accessibility concerns, allowing developers to focus on styling and composition.

Pros

  • Highly accessible components that adhere to WAI-ARIA standards
  • Flexible and customizable, allowing for easy integration with any styling solution
  • Lightweight and modular, with each component available as a separate package
  • Excellent TypeScript support for improved developer experience

Cons

  • Requires more setup and configuration compared to fully-styled component libraries
  • Learning curve for developers unfamiliar with headless UI concepts
  • Limited number of components compared to some larger UI libraries
  • Styling responsibility falls entirely on the developer, which can be time-consuming

Code Examples

  1. Using the Dialog component:
import * as Dialog from '@radix-ui/react-dialog';

function App() {
  return (
    <Dialog.Root>
      <Dialog.Trigger>Open Dialog</Dialog.Trigger>
      <Dialog.Portal>
        <Dialog.Overlay />
        <Dialog.Content>
          <Dialog.Title>Dialog Title</Dialog.Title>
          <Dialog.Description>Dialog content goes here.</Dialog.Description>
          <Dialog.Close>Close</Dialog.Close>
        </Dialog.Content>
      </Dialog.Portal>
    </Dialog.Root>
  );
}
  1. Implementing a custom Checkbox:
import * as Checkbox from '@radix-ui/react-checkbox';

function CustomCheckbox() {
  return (
    <Checkbox.Root className="CheckboxRoot">
      <Checkbox.Indicator className="CheckboxIndicator"></Checkbox.Indicator>
    </Checkbox.Root>
  );
}
  1. Creating a Dropdown Menu:
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';

function MyDropdownMenu() {
  return (
    <DropdownMenu.Root>
      <DropdownMenu.Trigger>Options</DropdownMenu.Trigger>
      <DropdownMenu.Portal>
        <DropdownMenu.Content>
          <DropdownMenu.Item>New Tab</DropdownMenu.Item>
          <DropdownMenu.Item>New Window</DropdownMenu.Item>
          <DropdownMenu.Separator />
          <DropdownMenu.Item>Settings</DropdownMenu.Item>
        </DropdownMenu.Content>
      </DropdownMenu.Portal>
    </DropdownMenu.Root>
  );
}

Getting Started

To start using Radix UI Primitives in your project:

  1. Install the desired component package:

    npm install @radix-ui/react-dialog
    
  2. Import and use the component in your React application:

    import * as Dialog from '@radix-ui/react-dialog';
    
    function App() {
      return (
        <Dialog.Root>
          <Dialog.Trigger>Open</Dialog.Trigger>
          <Dialog.Portal>
            <Dialog.Content>
              <Dialog.Title>Hello</Dialog.Title>
              <Dialog.Close>Close</Dialog.Close>
            </Dialog.Content>
          </Dialog.Portal>
        </Dialog.Root>
      );
    }
    
  3. Add your own styles to customize the appearance of the components.

Competitor Comparisons

37,442

⚡️ Simple, Modular & Accessible UI Components for your React Applications

Pros of Chakra UI

  • Comprehensive component library with pre-styled elements
  • Extensive theming capabilities and built-in dark mode support
  • Easier learning curve for developers familiar with React

Cons of Chakra UI

  • Larger bundle size due to included styles and components
  • Less flexibility for custom styling and behavior
  • Potential performance impact with heavy use of style props

Code Comparison

Chakra UI:

import { Button } from "@chakra-ui/react"

function MyComponent() {
  return <Button colorScheme="blue">Click me</Button>
}

Radix Primitives:

import * as Button from "@radix-ui/react-button"

function MyComponent() {
  return <Button.Root>Click me</Button.Root>
}

Key Differences

Chakra UI provides a more opinionated and complete UI solution, while Radix Primitives offers unstyled, accessible components that give developers more control over styling and behavior. Chakra UI is better suited for rapid development and consistent design, whereas Radix Primitives is ideal for custom design systems and granular control over components.

Radix Primitives focuses on accessibility and customization, providing a solid foundation for building complex UI components. It requires more initial setup but offers greater flexibility in the long run. Chakra UI, on the other hand, provides a quicker start with its pre-styled components and utility-first approach, making it easier to create visually appealing interfaces with less custom CSS.

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.

Pros of Headless UI

  • Seamless integration with Tailwind CSS, providing a cohesive development experience
  • Lighter weight and more focused on core UI components
  • Easier learning curve for developers already familiar with Tailwind CSS

Cons of Headless UI

  • Less comprehensive component library compared to Primitives
  • Limited styling options out of the box, requiring more custom CSS
  • Fewer accessibility features built-in by default

Code Comparison

Headless UI (React):

import { Menu } from '@headlessui/react'

function MyDropdown() {
  return (
    <Menu>
      <Menu.Button>Options</Menu.Button>
      <Menu.Items>
        <Menu.Item>
          {({ active }) => (
            <a className={`${active && 'bg-blue-500'}`} href="/account">
              Account
            </a>
          )}
        </Menu.Item>
      </Menu.Items>
    </Menu>
  )
}

Primitives (React):

import * as DropdownMenu from '@radix-ui/react-dropdown-menu';

const MyDropdown = () => (
  <DropdownMenu.Root>
    <DropdownMenu.Trigger>Options</DropdownMenu.Trigger>
    <DropdownMenu.Content>
      <DropdownMenu.Item>
        <a href="/account">Account</a>
      </DropdownMenu.Item>
    </DropdownMenu.Content>
  </DropdownMenu.Root>
);

Both libraries offer unstyled, accessible components, but Primitives provides more extensive customization options and a larger set of components out of the box. Headless UI is more tightly integrated with Tailwind CSS, making it a natural choice for Tailwind users.

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.

Pros of React Spectrum

  • Comprehensive design system with pre-styled components
  • Extensive accessibility features built-in
  • Strong support and maintenance from Adobe

Cons of React Spectrum

  • Larger bundle size due to included styles and features
  • Less flexibility in customization compared to Radix Primitives
  • Steeper learning curve for developers new to the system

Code Comparison

Radix Primitives (Dialog example):

import * as Dialog from '@radix-ui/react-dialog';

<Dialog.Root>
  <Dialog.Trigger>Open</Dialog.Trigger>
  <Dialog.Portal>
    <Dialog.Overlay />
    <Dialog.Content>
      <Dialog.Title>Dialog Title</Dialog.Title>
      <Dialog.Description>Dialog content here</Dialog.Description>
      <Dialog.Close>Close</Dialog.Close>
    </Dialog.Content>
  </Dialog.Portal>
</Dialog.Root>

React Spectrum (Dialog example):

import {Dialog, DialogTrigger, Button, Heading, Content} from '@adobe/react-spectrum';

<DialogTrigger>
  <Button>Open</Button>
  <Dialog>
    <Heading>Dialog Title</Heading>
    <Content>Dialog content here</Content>
  </Dialog>
</DialogTrigger>

Both libraries provide accessible and customizable components, but React Spectrum offers a more opinionated and pre-styled approach, while Radix Primitives focuses on unstyled, highly flexible building blocks. The choice between them depends on project requirements, desired level of customization, and development team preferences.

68,588

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.

Pros of ui

  • More opinionated and styled out-of-the-box, reducing setup time
  • Includes additional components not found in primitives
  • Easier to customize with Tailwind CSS integration

Cons of ui

  • Less flexible and harder to adapt to unique design systems
  • Potentially larger bundle size due to included styles
  • Newer project with a smaller community and less documentation

Code Comparison

primitives:

import * as Checkbox from '@radix-ui/react-checkbox';

<Checkbox.Root className="CheckboxRoot" defaultChecked id="c1">
  <Checkbox.Indicator className="CheckboxIndicator">
    <CheckIcon />
  </Checkbox.Indicator>
</Checkbox.Root>

ui:

import { Checkbox } from "@/components/ui/checkbox"

<Checkbox id="terms" />

The ui example is more concise and doesn't require importing multiple subcomponents. However, primitives offers more granular control over the structure and styling of the component.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Radix Primitives Logo

Radix Primitives

An open-source UI component library for building high-quality, accessible design systems and web apps.

Radix Primitives is a low-level UI component library with a focus on accessibility, customization and developer experience. You can use these components either as the base layer of your design system, or adopt them incrementally.


Documentation

For full documentation, visit radix-ui.com/docs/primitives.

Releases

For changelog, visit radix-ui.com/docs/primitives/overview/releases.

Contributing

Please follow our contributing guidelines.

Authors

Contributors


Community

  • Pedro Duarte (@peduarte)

  • Colm Tuite (@colmtuite) - WorkOS

  • Discord - To get involved with the Radix community, ask questions and share tips.

  • Twitter - To receive updates, announcements, blog posts, and general Radix tips.

Thanks

Chromatic

Thanks to Chromatic for providing the visual testing platform that helps us review UI changes and catch visual regressions.


License

Licensed under the MIT License, Copyright © 2022-present WorkOS.

See LICENSE for more information.