# Button background color binding expression

**URL:** <https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 8, 2024, 6:03am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945 "2024-10-08T06:03:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Sheldon-Colli](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Daniel\_Sheldon-Colli](https://forum.inductiveautomation.com/u/Daniel_Sheldon-Colli)\
**Post date:** [October 8, 2024, 6:03am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/1 "2024-10-08T06:03:17Z")

</div>

Is it possible to change a background color of a button through a binding Expression  
Thank you

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/5/95dd674a5c45d88ae6201221a27b136145206027.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 8, 2024, 8:03am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/2 "2024-10-08T08:03:57Z")

</div>

From [https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/colors/color:](https://docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/colors/color:)

> This function was designed to return color objects to Vision bindings, and **will not work with Perspective bindings**. Instead, Perspective color properties can simply use string hex codes to derive a color from a binding, for example: "#00FF00".

However, the Binding Preview is showing you that you have `Error_InvalidPathSyntax`. Did you enter that using the tag button on the right?

(I've moved your post from General Discussion to Ignition and tagged it as Perspective.)

---

<div class="post-metadata">

**Author:** ![Nathan\_Moore](https://avatars.discourse-cdn.com/v4/letter/n/d78d45/32.png) [@Nathan\_Moore](https://forum.inductiveautomation.com/u/Nathan_Moore)\
**Post date:** [October 8, 2024, 9:38am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/3 "2024-10-08T09:38:44Z")

</div>

In addition to being able to use a hex code like Transistor said, you can also use rbg(), rgba() or any other css color format. It just needs to be formatted as a string.

---

<div class="post-metadata">

**Author:** ![Daniel\_Sheldon-Colli](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Daniel\_Sheldon-Colli](https://forum.inductiveautomation.com/u/Daniel_Sheldon-Colli)\
**Post date:** [October 8, 2024, 11:01am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/4 "2024-10-08T11:01:45Z")

</div>

I did find this after posting and have updated it to a string and hex. saved and tested, still not working the button background doesn't update.

so the button just toggles a bit on and off and the same bit is going to be used as the color change. when testing Designer changes when monitoring but the website doesn't.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 8, 2024, 11:17am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/5 "2024-10-08T11:17:34Z")

</div>

Your problem is that you're using an expression TAG binding instead of an expression binding. The result of a tag binding should always be a tag path, but in this case you're wanting a CSS color so you nerd to switch to using an expression binding.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 8, 2024, 11:22am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/6 "2024-10-08T11:22:49Z")

</div>

> [@michael.flagler](#):
>
> Your problem is that you're using an expression TAG binding ...

That's it. I knew I was missing something when I wrote my answer.

---

<div class="post-metadata">

**Author:** ![Daniel\_Sheldon-Colli](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@Daniel\_Sheldon-Colli](https://forum.inductiveautomation.com/u/Daniel_Sheldon-Colli)\
**Post date:** [October 11, 2024, 3:57am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/7 "2024-10-11T03:57:05Z")

</div>

Figured that out cheers, ended up with this worked better than a expression with and IF statement,  
the if statement for some reason loaded as the Primary button in blue and then when clicked it changed back and forth between red and green. the below screen shot loads in current tag state and works fine

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/5/2546d46be4ffd482905873789abdac44fd4ce9b6.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 11, 2024, 7:22am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/8 "2024-10-11T07:22:42Z")

</div>

When your expression is only a tag, you should use a tag binding.  
NOT an expression tag binding. Just a simple tag binding, then the same map transform.

Alternatively, you can use an expression script that would look like this:

```python
case ({[default]Modbus_master_PLC/GVL_OPC_CableGrabLight},
  false, 'red',
  true, 'green',
  'blue'
)

```

or, since it's a boolean:

```python
if ({[default]Modbus_master_PLC/GVL_OPC_CableGrabLight},
  'green',
  'red'
)

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 11, 2024, 7:39am UTC](https://forum.inductiveautomation.com/t/button-background-color-binding-expression/96945/9 "2024-10-11T07:39:11Z")

</div>

Or for consistency across your application, use [Perspective Built-In Themes | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles/perspective-built-in-themes#built-in-theme-colors) such as `--success`, `--error` and `--callToAction`. These will subtly change when you change your theme from light to dark, etc. Hard-coding colors isn't a great plan.
