Change button color


Is there any way I can change the background color of the button?
Example, if (ON) , background = green, else (OFF) , background = red !?


Maybe this old thread ?


I did not put any code, this example is the type of application, depending on the state of the output, the color of the button is changed, so you do not need to put two buttons and that the mi button itself shows the state that is currently.


Sorry, I've read your reply multiple times and it is not clear (to me) what you are trying to say. Could you try restating your response? Thanks.


I want a single button to activate and deactivate something (a relay for example) but when I activate the relay, the button will turn green, and when I turn it off, the button will turn red!



I don't know how much you know about Node-Red, so it may be difficult to do.

You have the button on the screen. It has code and that goes off to do things.

The example posted at the top from dceejay is an example FLOW to show you how a button's colour is changed.

To get that part working, you copy it into Node-Red.

To help here is the code - again:


Copy that "line" of code (put your mouse over it, drag/select the code and copy it.

Go to Node-Red, and in the top right corner where the three lines are (similar to the browser menu) click and select import. Then, FROM CLIPBOARD.

Paste the code there and press enter.

That will put the code onto the browser window.

Click somewhere blank and click the DEPLOY button.

Then open the web page and go to that page.
You will see a button.

Press it and it will turn red then in about 3 seconds it will turn green again.

The code supplied shows you how the colour change is done.

Getting it done with your code will need a bit of work from you to get the signals (to tell it which colour to be) from your flow to the button.

But basically you send the button a message with the colour, and in the button's settings you allow the colour to be set by putting stuff in where it has the background colour for the button.

Opening the button and looking will help you more than I can and a lot quicker too.

Good luck.

1 Like

Thank you very much, I learned


Good to hear.

Hope it all works out for you.