JSX Attributes

style

Edit this page

Solid's style attribute lets you provide either a CSS string or an object where keys are CSS property names:

// string
<div style={`color: green; height: ${state.height}px`} />
// object
<div style={{
color: "green",
height: state.height + "px" }}
/>

Unlike React's style attribute, Solid uses element.style.setProperty under the hood. This means you need to use the lower-case, dash-separated version of property names instead of the JavaScript camel-cased version, such as background-color rather than backgroundColor. This actually leads to better performance and consistency with SSR output.

// string
<div style={`color: green; background-color: ${state.color}; height: ${state.height}px`} />
// object
<div style={{
color: "green",
"background-color": state.color,
height: state.height + "px" }}
/>

This also means you can set CSS variables! For example:

// set css variable
<div style={{ "--my-custom-color": state.themeColor }} />
Report an issue with this page