Styling a component part
Every Zag component is made up of named parts. For example, the dialog component has these parts:backdrop, positioner, content, title, description, and close-trigger.
Each part element receives a data-part attribute automatically when you spread the props returned by the machine’s connect function.
Here is what the dialog’s rendered HTML looks like:
Styling a state
When a component part can be in multiple states, Zag automatically attachesdata-* attributes reflecting the current state. You do not need to add these manually — they are applied when you spread the props from connect.
For example, an accordion trigger exposes:
data-disabled— when the trigger is disableddata-expanded— when the trigger is in its expanded state
Common state attributes
Different components expose different state attributes depending on their behavior. Here are the most commonly used ones:| Attribute | When it is present |
|---|---|
data-disabled | The element or its ancestor is disabled |
data-expanded | The element is in an open/expanded state |
data-highlighted | The element is currently highlighted (e.g. hovered in a listbox) |
data-selected | The element is selected |
data-checked | The element is checked |
data-invalid | The element has a validation error |
data-readonly | The element is read-only |
data-placeholder-shown | A placeholder value is currently displayed |
data-orientation | The orientation ("horizontal" or "vertical") |
Scoping styles to a component
To avoid style collisions when using multiple components on the same page, scope your selectors to a root element using thedata-scope attribute:
CSS variables and theming
Because Zag components are fully unstyled, CSS custom properties are a natural fit for theming. Define your design tokens at a high level and reference them inside your part selectors:Framework integration example
When you use a Zag machine in a framework, thedata-part and state attributes are applied for you via the spread props pattern:
Zag was designed to encapsulate logic, accessibility, and interactions while giving you full control over styling. You own every pixel.