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.
The prop can also be passed a function that takes the component’s state as an argument.
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.
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.
Check out each component’s API reference for a complete list of available data attributes and CSS variables.
Style prop
Components that render an HTML element accept a style prop to style the element with a CSS object.
The prop also accepts a function that takes the component’s state as an argument.
Tailwind CSS
Apply Tailwind CSS classes to each part via the className prop.
CSS Modules
Apply custom CSS classes to each part via the className prop.
Then style those classes in a CSS Modules file.
CSS-in-JS
Wrap each component part and apply styles, then assemble your styled components.
FineSoft Stencil comparison
Stencil parts expose the corresponding classes, state attributes, and CSS variables. In React consumers, use className; in HTML or Stencil JSX, use class. Styles on transparent parts are forwarded to their native semantic element by the component.
The Popup belongs inside the Root, Portal, and Positioner shown on the Menu page. Plain CSS and Tailwind can be used together as above. With CSS Modules, assign the imported class using element.className = styles.Popup. A CSS-in-JS library can likewise assign its generated class to the custom element; its React-specific styled(Menu.Popup) API is not a Stencil API. For state-dependent styles, prefer the part’s documented data-* attributes.