0 day streak
javascript / beginner
Snippet

Inline Style Directives

The style: directive provides a clean way to apply individual CSS styles dynamically without needing to manage a full style string or object.

snippet.js
javascript
1
2
3
4
5
6
7
<script>
let activeColor = 'red';
</script>
<div style:color={activeColor} style:font-weight="bold">
Styled text
</div>
svelte
Breakdown
1
style:color={activeColor}
Sets the CSS 'color' property to the value of the activeColor variable.
2
style:font-weight="bold"
Applies a static CSS property using the same shorthand syntax.