Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.

Styling

How to approach styling with Radix Themes.

Introduction

Radix Themes does not come with a built-in styling system. There’s no css or sx prop, and it does not use any styling libraries internally. Under the hood, it’s built with vanilla CSS.

There’s no overhead when it comes to picking a styling technology for your app.

What you get

The components in Radix Themes are relatively closed—they come with a set of styles that aren’t always easily overridden. They are customizable within what’s allowed by their props and the theme configuration.

However, you also get access to the same CSS variables that power the Radix Themes components. You can use these tokens to create custom components that naturally feel at home in the original theme. Changes to the token system are treated as breaking.

For more information on specific tokens, refer to the corresponding guides in the Theme section.

Color system

ABCD

ABCDEFG

ABCDEFGHI

ABCDEFGHIJ

ABCDEFGHIJKL

A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream; and, as I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks, and grow familiar with the countless indescribable forms of the insects and flies, then I feel the presence of the Almighty, who formed us in his own image, and the breath

Ambiguous voice of a heart which prefers kiwi bowls to a zephyr.

Typography examples
Shadow and radius examples

Per-component CSS

styles.css contains every component and every color and stays the default. You can instead import the tokens, the shared rules and one file per component. All files are compiled; none needs PostCSS.

Import them in this order:

import "@wsagency/radix2solid-themes/tokens/base.css";
import "@wsagency/radix2solid-themes/tokens/colors/indigo.css";
import "@wsagency/radix2solid-themes/tokens/colors/slate.css";
import "@wsagency/radix2solid-themes/css/common.css";
import "@wsagency/radix2solid-themes/css/button.css";
import "@wsagency/radix2solid-themes/css/dropdown-menu.css";
import "@wsagency/radix2solid-themes/css/utilities.css";
  • Tokens: tokens/base.css plus the palette file of every accent and gray color you use, or tokens.css for all of them. With grayColor="auto", import the gray that matches your accent (slate for indigo).
  • css/common.css comes first. It holds the reset, animations, layout, Skeleton and Text rules that every component relies on.
  • css/<component>.css holds only that component's rules and those of the components it renders (a loading Button includes Spinner; menus include ScrollArea). Layout components (Box, Flex, Grid, Container, Section), Text, Skeleton, Reset and Theme have files too. Components without styles of their own, such as Slot, Portal, AccessibleIcon, AspectRatio and VisuallyHidden, have none.
  • css/utilities.css comes last. It holds the Theme root and forced-colors rules and the responsive utility classes behind props such as m, p, width and display, so css/theme.css is not needed with it.
  • common.css and utilities.css are required. Leaving one out raises no error: the page quietly loses the reset, layout and typography rules, or high-contrast and responsive styles.
  • ThemePanel shows a swatch for every built-in accent and gray color and does not load palettes. With per-palette tokens its swatches, and any accent you pick from it, stay unpainted unless that palette is imported. Use styles.css or tokens.css while it is mounted, or import every palette; in split mode also import css/theme-panel.css.

Measured with Lightning CSS 1.33.0 for eight components (Button, Checkbox, Radio, TextField, DropdownMenu, Dialog, Popover and Flex); every row also includes the same small app stylesheet:

ImportsMinifiedgzipBrotli
styles.css702,487 B82,822 B50,321 B
tokens.css + per-component files464,287 B65,102 B39,097 B
Base tokens, gray/jade/sage + components.css + utilities.css608,460 B58,063 B34,658 B
Base tokens, gray/jade/sage + per-component files369,971 B39,862 B23,273 B

After compression, importing only the palettes you use saves more than splitting components; doing both saves the most. The .layer.css variants measure within 1% of these sizes. Measure your own imports.

Cascade layers

Every CSS file has a .layer.css sibling that wraps the same rules in @layer radix: styles.layer.css, tokens/base.layer.css, tokens/colors/indigo.layer.css, css/common.layer.css, css/button.layer.css, css/utilities.layer.css and so on. Your unlayered CSS then wins over Themes styles regardless of selector specificity or import order. To order Themes among your own layers, declare the order first, for example @layer reset, radix, app;.

import "@wsagency/radix2solid-themes/tokens/base.layer.css";
import "@wsagency/radix2solid-themes/tokens/colors/indigo.layer.css";
import "@wsagency/radix2solid-themes/tokens/colors/slate.layer.css";
import "@wsagency/radix2solid-themes/css/common.layer.css";
import "@wsagency/radix2solid-themes/css/button.layer.css";
import "@wsagency/radix2solid-themes/css/utilities.layer.css";

Pick one mode for the whole app. Never import a file together with its .layer.css sibling: the rules would load twice, and the unlayered copy would beat your own layered styles.

Overriding styles

Beyond simple style overrides, we recommend using the components as-is, or create your own versions using the same building blocks.

Most components do have class and style props, but if you find yourself needing to override a lot of styles, it’s a good sign that you should either:

  • Try to achieve what you need with the existing props and theme configuration.
  • See whether you can achieve your design by tweaking the underlying token system.
  • Create your own component using lower-level building blocks, such Primitives and Colors.
  • Reconsider whether Radix Themes is the right fit for your project.

Tailwind

Tailwind is great. Yet, if you plan to use Radix Themes with Tailwind, keep in mind how its ergonomics may encourage you to create complex styles on the fly, sometimes reaching into the component internals without friction.

Tailwind is a different styling paradigm, which may not mix well with the idea of a closed component system where customization is achieved through props, tokens, and creating new components on top of a shared set of building blocks.

Custom components

If you need to create a custom component, use the same building blocks that Radix Themes uses:

  • Theme tokens that power the components
  • Radix Primitives, a library of accessible, unstyled components
  • Radix Colors, a color system for building beautiful websites and apps

Feel free to explore the source code of Radix Themes to see how it is built.

Common issues

z-index conflicts

Out of the box, portalled Radix Themes components can be nested and stacked in any order without conflicts. For example, you can open a popover that opens a dialog, which in turn opens another popover. They all stack on top of each other in the order they were opened:

When building your own components, use the following rules to avoid z-index conflicts:

  • Don’t use z-index values other than auto, 0, or -1 in rare cases.
  • Render the elements that should stack on top of each other in portals.

Your main content and portalled content are separated by the stacking context that the styles of the root <Theme> component create. This allows you to stack portalled content on top of the main content without worrying about z-indices.

CSS import order

Import the native theme stylesheet before your custom styles from the same client entry so the bundler preserves their intended order:

import "@wsagency/radix2solid-themes/styles.css";
import "./my-styles.css";

When using separate CSS entry points, keep the emitted stylesheet links in the same order for both development and production. If your bundler does not preserve this order, combine the imports in one stylesheet with postcss-import and import that stylesheet once.

Historical context: the original React guide documented an import-order issue in Next.js 13–14. That framework-specific workaround is not a requirement of this native Solid package.

Tailwind base styles

As of Tailwind v3, styles produced by the @tailwind directive are usually appended after any imported CSS, no matter the original import order. In particular, Tailwind’s button reset style may interfere with Radix Themes buttons, rendering certain buttons without a background color.

Workarounds:

  • Don’t use @tailwind base
  • Set up separate CSS layers for Tailwind and Radix Themes
  • Set up postcss-import and manually import Tailwind base styles via @import tailwindcss/base before Radix Themes styles. Example setup

Missing styles in portals

When you render a custom portal in a Radix Themes project, it will naturally appear outside of the root <Theme> component, which means it won’t have access to most of the theme tokens and styles. To fix that, wrap the portal content with another <Theme>:

// Implementation example of a custom dialog using the low-level Dialog primitive
// Refer to https://www.radix-ui.com/primitives/docs/components/dialog
import { Dialog } from "@wsagency/radix2solid-primitives";
import { Theme } from "@wsagency/radix2solid-themes";
function MyCustomDialog() {
return <Dialog.Root>
<Dialog.Trigger>Open</Dialog.Trigger>
<Dialog.Portal>
<Theme>
<Dialog.Overlay />
<Dialog.Content>
<Dialog.Title />
<Dialog.Description />
<Dialog.Close />
</Dialog.Content>
</Theme>
</Dialog.Portal>
</Dialog.Root>;
}

Components like Dialog and Popover in Radix Themes already handle this for you, so this is only necessary when creating your own portalled components.

Complex CSS precedence

Usually, you’d want your custom CSS to override Radix Themes styles. However, there are cases when it is natural to expect the opposite.

Consider a simple paragraph style that just resets the browser’s default margin:

.my-paragraph {
margin: 0;
}

You might apply the margin prop from a Box onto your custom paragraph via asChild:

import "@wsagency/radix2solid-themes/styles.css";
import "./my-styles.css";
function MyApp() {
return <Theme>
<Box asChild m="5">{target => target("p", {
"class": "my-paragraph",
children: <>My custom paragraph</>
})}</Box>
</Theme>;
}

Yet, this won’t work intuitively. The custom styles are imported after Radix Themes styles, so they will override the margin prop. As a workaround, Radix Themes provides separate tokens.css, components.css, and utilities.css files that the original styles.css is built upon:

import "@wsagency/radix2solid-themes/tokens.css";
import "@wsagency/radix2solid-themes/components.css";
import "@wsagency/radix2solid-themes/utilities.css";

You can import utilities.css after your custom styles to ensure that the layout props work as expected with your custom styles. Keep the CSS import order consistent between your development and production bundles.

If you use standalone layout components, split CSS files are also available for them:

import "@wsagency/radix2solid-themes/layout/tokens.css";
import "@wsagency/radix2solid-themes/layout/components.css";
import "@wsagency/radix2solid-themes/layout/utilities.css";