> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/foundations/styling.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# Styling components

Customise Core UI components with class names, state selectors and CSS variables.

Core UI components come styled, and there are four ways to change how they look. From the broadest to the most specific:

| To change…                                                      | Use                                                                                               |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| Accent and border colours everywhere, or in one area            | [Theme variables](https://docs.rierino.com/sdk-core-ui/foundations/colors.md) such as `--primary` |
| One instance of a component                                     | A [`className`](#adding-a-class-name)                                                             |
| How a component looks in a state (selected, focused, disabled…) | [State selectors](#styling-states) or a [`className` function](#class-names-that-depend-on-state) |
| A value a component exposes, such as a button's background      | [Component variables](#component-variables)                                                       |

## Adding a class name

Components accept `className` (except `Calendar` and `TreeView`, which don't take one yet). Your classes are **added** to the component's built-in classes, so you only write what you want to change:

```jsx
<Button className="Rie-Checkout-pay">Pay now</Button>
```

```css
.Rie-Checkout-pay {
  min-width: 160px;
  letter-spacing: 0.02em;
}
```

If you pass Tailwind utilities that conflict with a built-in one, such as a different padding or radius, the built-in class is removed and **yours wins** in almost all components. The merge is done with [tailwind-merge](https://github.com/dcastil/tailwind-merge):

```jsx
// The built-in rounded-lg is replaced by rounded-full
<Button className="rounded-full px-6">Pay now</Button>
```

{% hint style="info" %}
**Tailwind classes need a Tailwind build**

Core UI's stylesheet contains only the classes its own components use. Tailwind utilities in your `className` work only if your app's Tailwind build generates them. Without Tailwind, including in [hosted editors](https://docs.rierino.com/sdk-core-ui/guides/hosted-editors.md), use your own class names and CSS.
{% endhint %}

## Styling states

Interactive components put their current state on the DOM as `data-*` attributes. Target those in CSS rather than adding and removing classes yourself.

| Attribute            | Present when                                                     |
| -------------------- | ---------------------------------------------------------------- |
| `data-hovered`       | The pointer is over the element                                  |
| `data-pressed`       | The element is being pressed (mouse, touch or keyboard)          |
| `data-focused`       | The element has focus                                            |
| `data-focus-visible` | The element has focus **and** it came from the keyboard          |
| `data-disabled`      | The component is disabled (`isDisabled`)                         |
| `data-selected`      | A Checkbox, Radio, Switch or Tab is checked or selected          |
| `data-invalid`       | The component is invalid (`isInvalid`)                           |
| `data-orientation`   | Set to `horizontal` or `vertical` on Tabs, Slider and RadioGroup |

```jsx
<RadioGroup aria-label="Plan" defaultValue="pro">
  <Radio value="basic" className="Rie-Plan-option">Basic</Radio>
  <Radio value="pro" className="Rie-Plan-option">Pro</Radio>
</RadioGroup>
```

```css
.Rie-Plan-option {
  border: 1px solid var(--color-mischka);
  border-radius: 8px;
  padding: 12px;
}

.Rie-Plan-option[data-selected] {
  border-color: var(--primary, var(--color-electric-violet));
  background: var(--color-blue-chalk);
}

.Rie-Plan-option[data-disabled] {
  opacity: 0.5;
}
```

Use `data-focus-visible`, not `:focus`, for focus rings. It only shows the ring when the user is navigating with the keyboard, which is what React Aria's own components do.

With Tailwind, write the same selectors as `data-[selected]:border-violet-600`, or add the [`tailwindcss-react-aria-components`](https://www.npmjs.com/package/tailwindcss-react-aria-components) plugin for shorthands such as `selected:` and `disabled:`.

## Class names that depend on state

Components built on React Aria also accept a **function** as `className`. It receives the component's current state and returns the classes to add:

```jsx
<Button
  className={({ isPressed, isDisabled }) =>
    isDisabled ? "Rie-Toolbar-btn is-off" : isPressed ? "Rie-Toolbar-btn is-down" : "Rie-Toolbar-btn"
  }
>
  Refresh
</Button>
```

The state object has the same values as the `data-*` attributes, in camel case: `isHovered`, `isPressed`, `isFocused`, `isFocusVisible`, `isDisabled`, `isSelected`, `isInvalid` and so on, depending on the component.

A function is accepted by `Button`, `Input`, `Checkbox`, `CheckboxGroup`, `Radio`, `RadioGroup`, `Switch`, `Slider`, `Tabs`, `TabList`, `Tab`, `TabPanel`, `Popover` and `Menu` items. `TextField`, `Grid`, `Grid.Item`, `Rating` and `AutocompleteInput` take a plain string.

Prefer data-attribute selectors when the styles live in a stylesheet. The function form is useful when the classes are Tailwind utilities, or when you need logic beyond a selector.

## Styling inner parts

Some components render several elements and give you a prop for each part:

| Component       | Props                                                                                                            |
| --------------- | ---------------------------------------------------------------------------------------------------------------- |
| `Modal.Content` | `classNames={{ overlay, content }}` for the backdrop and the dialog box                                          |
| `Rating`        | `ratingClassName` for the row of stars, `starClassName` for each star, plus `emptyClassName` and `fullClassName` |
| `Radio`         | `descriptionClassName` for the description text                                                                  |

A few elements also carry fixed class names that are safe to target from CSS:

| Class                              | Element                                                  |
| ---------------------------------- | -------------------------------------------------------- |
| `Rie-input`                        | The `<input>` inside `Input`, `TextField` and `TextArea` |
| `Rie-textfield`                    | The wrapper of `TextField`                               |
| `Rie-track` and `Rie-slider-thumb` | The track and thumb of `Slider`                          |

```css
.Rie-Search-field .Rie-input::placeholder {
  color: var(--color-lynch);
}
```

## Icons in buttons

Give an icon `data-slot="icon"` and `Button` sizes it, aligns it and colours it to match the button's intent:

```jsx
import { Plus } from "lucide-react";

<Button intent="g-button">
  <Plus data-slot="icon" />
  Create
</Button>
```

This works with any icon library, or with a plain `<svg>`.

## Component variables

Some components expose CSS variables for values that are otherwise set by a prop. `Button` uses two:

| Variable     | Controls                                                           |
| ------------ | ------------------------------------------------------------------ |
| `--btn-bg`   | The background of a solid button. It can be a colour or a gradient |
| `--btn-icon` | The colour of icons marked `data-slot="icon"`                      |

Each `intent` sets these with a class, so to override them for one button use an inline style:

```jsx
<Button style={{ "--btn-bg": "var(--color-eucalyptus)" }}>
  Approve
</Button>
```

## What to avoid

* **Don't target Core UI's internal Tailwind classes** such as `.rounded-lg` or `.px-4`. They are implementation details and can change in any release. Target your own classes, the `data-*` attributes and the `Rie-` classes listed above.
* **Avoid `!important`.** With `className` merging and state selectors you shouldn't need it, and it stops theme variables and state styles from applying.
* **Don't restyle for focus or disabled states with `:focus` or `[disabled]`.** Use `data-focus-visible` and `data-disabled`, which match what React Aria tracks.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/foundations/styling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
