Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

upnorthal's avatar

Alpine .js Can't x-bind styles inline

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.

0 likes
3 replies
upnorthal's avatar

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

Please or to participate in this conversation.