Styles
uno implements a strict CSS-like subset. Style names accept both camelCase and kebab-case. The TypeScript type StyleName only includes camelCase names. Values are strings; node.style() also accepts a number for numeric longhands.
node.style('backgroundColor', '#1f6fb2')
node.style('padding', '12px 16px')
node.style('flex-grow', '1')
node.style('translateX', 120) // 120px
node.style('opacity', 0.5)
// Invalid: shorthands, colors, and keywords need a string.
node.style('padding', 12) // Throws an errorUnits and common values
| Value family | Accepted values |
|---|---|
| Length | px, rem, vw, or vh |
| Percentage length | The length units above plus % |
| Color | Hex only: #RGB, #RGBA, #RRGGBB, or #RRGGBBAA |
| Number | A number encoded as a string, for example '1' or '0.5' |
| Integer | An integer encoded as a string |
| Angle | deg only, for example '45deg' or '-90deg' |
In WebGPU, rem uses the value set by ui.setRootSize() (16 by default), while vw and vh use the last values supplied to ui.setViewport().
CSS-wide keywords other than unset, CSS functions such as calc() and var(), named colors, rgb(), em, and arbitrary CSS declarations are not supported.
Numeric values
node.style() accepts a number for the longhands in the NumberStyleName type. Lengths read it as px and rotate as deg; opacity, zIndex, flexGrow, flexShrink, aspectRatio, lineHeight, scaleX, and scaleY read it as is. node.style('width', 200) stores the same value as node.style('width', '200px') and applies the same range checks, but skips string parsing, so prefer numbers for values that change every frame. Percentages, rem, vw, vh, auto, unset, shorthands, colors, and keywords still need a string, and framework style props keep string values.
Resetting styles with unset
All properties accept 'unset'. Use it to clear a previously applied value:
node.style('opacity', '0.5')
node.style('opacity', 'unset')For shorthands, 'unset' clears all the properties they expand into. For example, it clears padding on all four sides:
node.style('padding', '12px 16px')
node.style('padding', 'unset')Framework adapters automatically apply 'unset' when a previously applied property is removed from the style object. In this React example, changing dimmed from true to false removes opacity and clears its previous value:
function Example({ dimmed }: { dimmed: boolean }) {
return <View style={dimmed ? { opacity: '0.5' } : {}} />
}Style properties
| Property | Type | Accepted values / expansion |
|---|---|---|
display | yoga-layout | flex, none, contents |
position | yoga-layout | static, relative, absolute |
top | yoga-layout | Signed percentage length or auto |
right | yoga-layout | Signed percentage length or auto |
bottom | yoga-layout | Signed percentage length or auto |
left | yoga-layout | Signed percentage length or auto |
width | yoga-layout | Non-negative percentage length or auto |
height | yoga-layout | Non-negative percentage length or auto |
minWidth | yoga-layout | Non-negative percentage length |
minHeight | yoga-layout | Non-negative percentage length |
maxWidth | yoga-layout | Non-negative percentage length |
maxHeight | yoga-layout | Non-negative percentage length |
boxSizing | yoga-layout | border-box, content-box |
aspectRatio | yoga-layout | Non-negative number |
flexDirection | yoga-layout | column, column-reverse, row, row-reverse |
flexWrap | yoga-layout | nowrap, wrap, wrap-reverse |
flexGrow | yoga-layout | Non-negative number |
flexShrink | yoga-layout | Non-negative number |
flexBasis | yoga-layout | Non-negative percentage length or auto |
justifyContent | yoga-layout | flex-start, center, flex-end, space-between, space-around, space-evenly |
alignContent | yoga-layout | Values above plus stretch, baseline |
alignItems | yoga-layout | normal, flex-start, center, flex-end, stretch, baseline |
alignSelf | yoga-layout | auto, normal, flex-start, center, flex-end, stretch, baseline |
marginTop | yoga-layout | Signed percentage length or auto |
marginRight | yoga-layout | Signed percentage length or auto |
marginBottom | yoga-layout | Signed percentage length or auto |
marginLeft | yoga-layout | Signed percentage length or auto |
paddingTop | yoga-layout | Non-negative percentage length |
paddingRight | yoga-layout | Non-negative percentage length |
paddingBottom | yoga-layout | Non-negative percentage length |
paddingLeft | yoga-layout | Non-negative percentage length |
gap | yoga-layout | Non-negative percentage length |
rowGap | yoga-layout | Non-negative percentage length |
columnGap | yoga-layout | Non-negative percentage length |
overflowX | yoga-layout | visible, hidden, scroll |
overflowY | yoga-layout | visible, hidden, scroll |
direction | yoga-layout | inherit, ltr, rtl |
backgroundColor | painting | Hex color |
backgroundImage | painting | A key registered in the UI's resource store |
backgroundSizeWidth | painting | Non-negative percentage length, cover, or contain |
backgroundSizeHeight | painting | Non-negative percentage length, cover, or contain |
backgroundPositionX | painting | Signed percentage length |
backgroundPositionY | painting | Signed percentage length |
backgroundRepeat | painting | no-repeat, repeat, repeat-x, repeat-y |
borderTopWidth | painting | Non-negative length (no %) |
borderRightWidth | painting | Non-negative length (no %) |
borderBottomWidth | painting | Non-negative length (no %) |
borderLeftWidth | painting | Non-negative length (no %) |
borderTopStyle | painting | none, solid |
borderRightStyle | painting | none, solid |
borderBottomStyle | painting | none, solid |
borderLeftStyle | painting | none, solid |
borderTopColor | painting | Hex color |
borderRightColor | painting | Hex color |
borderBottomColor | painting | Hex color |
borderLeftColor | painting | Hex color |
borderTopLeftRadius | painting | Non-negative percentage length |
borderTopRightRadius | painting | Non-negative percentage length |
borderBottomRightRadius | painting | Non-negative percentage length |
borderBottomLeftRadius | painting | Non-negative percentage length |
boxShadow | painting | offset-x offset-y blur spread [color]; length units only, non-negative blur, black default color |
opacity | painting | Number from 0 through 1 |
translateX | painting | Signed px length |
translateY | painting | Signed px length |
scaleX | painting | Non-negative number |
scaleY | painting | Non-negative number |
rotate | painting | Signed deg angle; positive turns clockwise |
zIndex | painting | Integer |
pointerEvents | painting | all, none |
color | text | Hex color |
fontFamily | text | Font name; case is preserved. WebGPU requires a registered font. |
fontSize | text | Non-negative length (no %) |
lineHeight | text | Non-negative unitless number or non-negative length |
letterSpacing | text | Signed length |
textAlign | text | left, right, center, justify |
whiteSpace | text | normal, nowrap, pre-wrap, pre |
textShadow | text | offset-x offset-y blur [color]; length units only, non-negative blur, black default color |
textStroke | text | width color; non-negative length and a hex color |
overflow | shorthands | overflowX, overflowY |
border | shorthands | Width, style, and color for all four sides |
borderRadius | shorthands | One to four corner radii |
backgroundSize | shorthands | One or two dimensions, or cover/contain alone |
backgroundPosition | shorthands | X and optional Y; Y defaults to 50% |
translate | shorthands | translateX and optional translateY; Y defaults to 0px |
scale | shorthands | scaleX and optional scaleY; Y defaults to X |
margin | shorthands | One to four edge values |
padding | shorthands | One to four edge values |
flex | shorthands | CSS-like one-, two-, or three-value expansion to grow/shrink/basis; auto is supported, none is not |
whiteSpace: 'pre' preserves whitespace and explicit line breaks in text nodes while disabling automatic wrapping. Unlike nowrap, it preserves repeated spaces; unlike pre-wrap, it does not wrap text to fit the available width.
pointerEvents: 'none' removes a node from WebGPU hit testing.
translate, scale, and rotate move, scale, and turn what a node and its subtree paint without changing layout. As with the CSS individual transform properties, the origin is the center of the box: the scale applies first, then the rotation, then the translation. rotate only turns in the plane of the screen; the CSS axis forms such as rotate: x 45deg are not supported. Hit testing follows the transformed box. To animate every frame, prefer them over left, top, or fontSize: they do not trigger layout. To change a single axis, set translateX, translateY, scaleX, or scaleY; they have no CSS equivalent and the DOM renderer composes them into translate and scale.
A UI created with yoga: false only reads the box styles listed in Layout without Yoga and ignores the other yoga-layout styles.
The WebGPU renderer uses MTSDF alpha distance for strokes and shadows and the RGB distance field for the glyph fill.
Longhands are also public style names. For example, backgroundSizeWidth, backgroundPositionY, translateX, and every side-specific border property can be assigned directly.
Rendering differences
- Opacity: WebGPU multiplies ancestor opacity into each drawable separately. Overlapping elements can therefore look different from CSS, which composites the subtree before applying group opacity.
- Overflow:
overflow: 'hidden'andoverflow: 'scroll'clip children to a rectangle.borderRadiusdoes not round this clip, so children can remain visible in the rounded corners. - Transforms: in WebGPU,
translate,scale, androtatedo not extend the scrollable overflow (scrollWidth,scrollHeight). With a non-uniformscale, shadow blur and spread and the text stroke width use the smaller factor. Box shadow offsets, blur, and spread are rounded to whole pixels, so an animatedscalemoves them in 1 px steps. - Rotation: WebGPU ignores
overflow: 'hidden'andoverflow: 'scroll'on a rotated node and inside its subtree, so their children are not clipped; a scroll container still scrolls. Clips from ancestors above the rotation still apply. The DOM renderer clips rotated subtrees, as CSS does. Under a non-uniformscaleabove a rotation, WebGPU places every descendant exactly but draws each box as a rotated rectangle, without the skew that CSS shows.
Images and objectFit
objectFit is not a core style name. It is an Image component option implemented by the framework adapters:
objectFit | Applied background size |
|---|---|
fill (default) | 100% 100% |
contain | contain |
cover | cover |
none | unset |
When neither dimension is supplied, Image uses the registered resource dimensions. When only one is supplied, it derives aspectRatio. Values inside style take precedence over the component's width and height props.