# Color conditional formatting on a label

**URL:** <https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 17, 2025, 2:58pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718 "2025-09-17T14:58:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bshriner](https://avatars.discourse-cdn.com/v4/letter/b/46a35a/32.png) [@bshriner](https://forum.inductiveautomation.com/u/bshriner)\
**Post date:** [September 17, 2025, 2:58pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/1 "2025-09-17T14:58:40Z")

</div>

I am trying to change the color of the text on a label depending on the value of the tag. I am pulling in the tag from a PLC and applying a python script to it, the tag is either 1 or 0. Right now my python script is putting GOOD or BAD on the label depending on if the tag is 1 or 0. I would also like it to change the color of the text to green if GOOD (1) or red if BAD (0).

Is this possible to do through the python script?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [September 17, 2025, 3:07pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/2 "2025-09-17T15:07:13Z")

</div>

Best way to do this is to make 2 custom style classes, one for good value and one for bad value. Set the text color in each class appropriately.

From there, put an expression binding on the label's `props.style.classes` property that looks at the tag value, and returns the appropriate custom class style based on the tag value.

You can go simpler by just doing an expression on the label's `props.style.color` property, but the style class is the best way to do this.

In general, you should be attempting to achieve simple things like this via expressions, as they are faster than scripts.

> **[Expression Bindings in Perspective | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.3/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/expression-bindings-in-perspective)**
>
> Binding Properties to the Outcome of an Expression

> **[Style Classes | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.3/ignition-modules/perspective/styles/style-classes)**
>
> A Style Class is a group of Style settings that are saved together. Style Classes can be applied to multiple components to provide consistency in design. A Style Class enables you to define style elements in one place, and then quickly apply that...

(I can hear the UI design complaints already)

---

<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:** [September 17, 2025, 3:11pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/3 "2025-09-17T15:11:43Z")

</div>

Use expressions rather than scripts wherever possible. They are more efficient as they don't require starting the script engine.

Expression for GOOD / BAD on the label's `PROPS.text`:  
`if({[default]MyBooleanTag}, "GOOD", "BAD")`

Expression for label color:

- Add a color property to `PROPS.style`.

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

Expression:  
`if({[default]MyBooleanTag}, '--success', '--error')`

This also introduces you to [Perspective Built-In Themes | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/styles/perspective-built-in-themes) which is the way of the web. You should use built-in or your own theme colors rather than hard-coding colors in your application. That is fundamental to separation of content and style.

Ryan's encouragement to use style classes is good advice.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 17, 2025, 3:13pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/4 "2025-09-17T15:13:32Z")

</div>

Using a script for that is very inefficient. Expression bindings will execute much quicker, so I would create a custom property in the view that binds to the tag, then apply an expression binding on the `text` property of the label:

```python
if({view.custom.myProp},
	'GOOD',
	'BAD'
)

```

You can do the same to bind a style or color value as @ryan.white suggests.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 17, 2025, 3:40pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/5 "2025-09-17T15:40:44Z")

</div>

> [@Ryan\_Deardorff](#):
>
> a custom property in the view that binds to the tag,

There's no significant performance benefit from this, but this is **absolutely** the way to go from a maintainability standpoint.

If you add a single custom property with the single 'driving' binding for your component, then if you ever need to update the path it's pointed to, it's very easy to do. If you reference the tag individually in multiple bindings, you'll have to update each of those bindings if you ever need to make a change.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [September 17, 2025, 3:49pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/6 "2025-09-17T15:49:08Z")

</div>

> [@paul-griffith](#):
>
> **absolutely** the way to go from a maintainability standpoint.

And I would add that for that same reason, it’s important to place the custom property on the view, not on a particular component. That way you can reorganize view components and not break relative path references like those created with `getChild()` and the like.

---

<div class="post-metadata">

**Author:** ![bshriner](https://avatars.discourse-cdn.com/v4/letter/b/46a35a/32.png) [@bshriner](https://forum.inductiveautomation.com/u/bshriner)\
**Post date:** [September 17, 2025, 3:53pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/7 "2025-09-17T15:53:40Z")

</div>

I think this is the best method for what I am trying to do. I have some questions still though.

1. Am I able to apply both of these expressions at the same time? Im assuming I just add the color one on another line?
2. When I try to do the color change expression you provided it just changes my label to ‘–success’ or ‘–error’ if({[default]_LeakTesting-PLC_/TestResults}, '--success', '--error')

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 17, 2025, 4:00pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/8 "2025-09-17T16:00:54Z")

</div>

You need two bindings (three, if you go the recommended way above).

One on the text property of the label, returning 'good' or 'bad'.  
One on the style classes property, returning which style class or color to use (`--success` or `--error`)  
Optionally, one on a custom property bound to the tag that just returns a boolean.

Bindings **must** return a value, they don't \[1\] work by 'side effects'.

* * *

1. shouldn't

---

<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:** [September 17, 2025, 4:15pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/9 "2025-09-17T16:15:36Z")

</div>

> 1. Am I able to apply both of these expressions at the same time?

Yes, but not on the same property. One binding max on each property.

> 1. When I try to do the color change expression you provided it just changes my label to ‘–success’ or ‘–error’ if({[default]_LeakTesting-PLC_/TestResults}, '--success', '--error')

You've applied the color binding to `PROPS.text.`. You need to add it to `PROPS.style.color` which you will have created if you used my instructions in post #3.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1b6808e189a24fe457bd75b45014dd82e73b911e.png)

---

<div class="post-metadata">

**Author:** ![bshriner](https://avatars.discourse-cdn.com/v4/letter/b/46a35a/32.png) [@bshriner](https://forum.inductiveautomation.com/u/bshriner)\
**Post date:** [September 17, 2025, 4:55pm UTC](https://forum.inductiveautomation.com/t/color-conditional-formatting-on-a-label/110718/10 "2025-09-17T16:55:08Z")

</div>

I got it now. Thank you!
