Expressing styles in JavaScript isn't all that different than expressing them in css.
Imagine you had the following css and html:
.foobar {
color: red;
font-size: 4rem;
}
<i class="foobar" />
Or using React:
React.createElement("i", {
className: "foobar",
});
Now, expressing the same styles using JavaScript:
.foobar {
color: red;
font-size: 4rem;
}
becomes
var foobar = {
"color": "red",
"font-size": "4rem",
};
React.createElement("i", {
className: "foobar",
});
becomes
React.createElement("i", {
style: foobar,
});
And you get the power of JavaScript to boot!
What if you don't want to use React? It's not too different. You just need a way to "compile" JavaScript styles into style attributes.
Here's an example using mustache.
Mustache.render("<i style="{{style}}" />", {
style: stringifyStyle(foobar):
});
Or you could generate classes.