Styling

A guide to styling Base UI components with your preferred styling engine.

Base UI components are unstyled, don’t bundle CSS, and are compatible with Tailwind, CSS Modules, CSS-in-JS, or any other styling solution you prefer. You retain total control of your styling layer.

Style hooks

CSS classes

Components that render an HTML element accept a className prop to style the element with CSS classes.

switch.tsx

The prop can also be passed a function that takes the component’s state as an argument.

switch.tsx

Data attributes

Components provide data attributes designed for styling their states. For example, Switch can be styled using its [data-checked] and [data-unchecked] attributes, among others.

switch.css

CSS variables

Components expose CSS variables to aid in styling, often containing dynamic numeric values to be used in sizing or transform calculations. For example, Popover exposes CSS variables on its Popup component like --available-height and --anchor-width.

popover.css

Check out each component’s API reference for a complete list of available data attributes and CSS variables.

Tailwind CSS

Apply Tailwind classes to each part via the className prop.

menu.tsx

CSS Modules

Apply custom CSS classes to each part via the className prop. Then style those classes in a CSS Modules file.

menu.tsx

CSS-in-JS

Wrap each component part and apply styles, then assemble your styled components.

menu.tsx