Overview
ScopedVariables overrides CSS variables for a specific subtree without changing the active theme or global variable values. Use it for component previews, branded sections, and local design-token overrides.
The nearest ScopedVariables value wins, so nested scopes inherit parent values and can override only what they need.
ScopedVariables is a runtime variable boundary. Class names, hooks, and withUniwind-wrapped components inside the boundary resolve variables from the scoped values first.Usage
Basic Example
Nested Scoped Variables
Nested scopes merge with their parents. The closest value for each variable wins.Reading a Scoped Variable in JavaScript
useCSSVariable reads the nearest scoped value and updates when the scope changes.
API Reference
Component Signature
Props
CSS variable overrides for this subtree. Every variable name must start with
--; invalid names are ignored.Behavior Notes
ScopedVariablesaffects only its descendants and never mutates global theme variables.- Nested scopes merge with parent scopes; the nearest value for a variable wins.
- Scoped values are used by
className,useCSSVariable,useResolveClassNames, andwithUniwind-wrapped components. - On web, numeric values become pixel values. For example,
16is applied as16px. - The overridden variable should be defined in your theme or used by a class name, just like other CSS variables.
Scoped Variables vs Other Theme APIs
- Use
ScopedVariablesto override one or more values for a subtree. - Use
ScopedThemeto apply an existing theme to a subtree. - Use
Uniwind.updateCSSVariablesto persistently update values for an entire theme at runtime.
Related
Scoped Themes
Apply an existing theme to a subtree
useCSSVariable
Read CSS variables in JavaScript
Update CSS Variables
Update variables for an entire theme at runtime
Global CSS
Define CSS variables in your theme configuration