# Conditional color - What is correct formula syntax?

**URL:** <https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865>\
**Category:** How do I?\
**Created:** [October 12, 2023, 10:39pm UTC](https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865 "2023-10-12T22:39:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredo22](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/fredo22/32/2283_2.png) [@fredo22](https://community.weweb.io/u/fredo22)\
**Post date:** [October 12, 2023, 10:39pm UTC](https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865/1 "2023-10-12T22:39:28Z")

</div>

I have a vertical nav menu element (made from scratch). When a user selects an item (category), I want that menu item’s div to be a specific color. The attached image shows my current formula (which isn’t working). Can someone please give me the correct formula syntax for a conditional color? Thanks!

 ![Screen Shot 2023-10-12 at 6.37.40 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/f/f0c214b0de83d3f2f81167b07a62b8c82c4b8176.png)

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [October 13, 2023, 12:09am UTC](https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865/2 "2023-10-13T00:09:37Z")

</div>

You need to wrap background color css “into quotes first”.

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [October 13, 2023, 12:14am UTC](https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865/3 "2023-10-13T00:14:11Z")

</div>

If you bind a color the value should be a string with a valid css color. Something like `"red"` or `"#00ff00` ecc.  
Don’t add the css property, bind the right option in the editor, for example the text color or the background color.

---

<div class="post-metadata">

**Author:** ![fredo22](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/fredo22/32/2283_2.png) [@fredo22](https://community.weweb.io/u/fredo22)\
**Post date:** [October 13, 2023, 2:43am UTC](https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865/4 "2023-10-13T02:43:58Z")

</div>

thanks for you replies @Broberto and @dorilama . I’m a noob, and don’t know css and I’m not a programmer, and I don’t understand your answers. Can either of you kindly re-write my formula correctly (verbatim)? If so, thanks in advance!

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/max/32/4844_2.png) [@Max](https://community.weweb.io/u/Max)\
**Post date:** [October 13, 2023, 4:00am UTC](https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865/5 "2023-10-13T04:00:07Z")

</div>

Hi @fredo22  
You need to output a string with a color value, so in your case “#74992E” directly. Also, you need to have an option for when “selected\_admin” is false. It looks like this:

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e19734ea367317a83a472e9d6341366b1f2e7f7d.png)

A better approach would be to use your pre-defined project colors:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/4/4001733b7a3dbf47f2686708087ebb632a7bfdb8.png)

This way, if you need to change your colors later, you don’t have to adjust all your formulas.

Best,  
Max

---

<div class="post-metadata">

**Author:** ![fredo22](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/fredo22/32/2283_2.png) [@fredo22](https://community.weweb.io/u/fredo22)\
**Post date:** [October 13, 2023, 5:16pm UTC](https://community.weweb.io/t/conditional-color-what-is-correct-formula-syntax/4865/6 "2023-10-13T17:16:59Z")

</div>

Thanks @Max - Much appreciated! The solution is so much simpler than I imagined 🙂
