Skip to main content

Theme-aware gradients

Use gradient on Box when the stops should follow the nearest Silva UI theme. It is a compact, typed API for custom gradients that accepts semantic theme tokens, Radix colour tokens, or valid CSS colour values.

Use semantic stops for UI meaning

Use semantic stops when a gradient has a UI role: primary and primaryActive follow the active theme, including a custom theme. Use named hue tokens such as violet9 and cyan9 for decorative accents. Literal CSS values are useful for one-off brand work, but remain fixed when the theme changes.

Choose the right gradient API

Named gradients and animation are documented in Visuals. Use gradient when a component needs its own colours, direction, or gradient type.

Gradient options

from and to are required. via, type, and deg are optional.

Theme scopes update gradient stops

Token stops compile to Silva UI CSS variables. The gradient does not need to be rebuilt when its nearest Theme changes: its semantic values resolve in the new scope. The same applies to a custom Vanilla Extract theme that implements the Silva UI contract.
See Theming to define a custom theme contract.

Custom theme example

A gradient inside a custom theme resolves through that wrapper just like bg, color, and component variants do.

Gradient types

deg changes the direction of linear gradients and the start angle of conic gradients. Radial gradients ignore it.

Reuse the generated CSS

Use gradientToCss when a wrapper component or a plain element needs the exact same theme-aware background-image value.
For CSS capabilities beyond the compact API, use style directly: