Level 13
Managed to get it working like this
<div x-data="{ bcolor: 'red', tcolor: 'white' }">
<div
:style="`background-color: ${bcolor}; color: ${tcolor}` "
>
Test
</div>
</div>
7 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi
Just wanted to check I am not missing something here. In Vue JS, it is possible to data bind styles inline
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
Data block:
data: {
styleObject: {
color: 'red',
fontSize: '13px'
}
}
Alpine JS doesn't seem to support this. The x-bind works for class binding, but as soon as I try it to do a style inline in blows up!
Back to Vue JS for me I guess.
Please or to participate in this conversation.