I want to separate two labels and then coloring each one separately, using QGIS 3.4.1. So, I was trying to color a label within the Expression Dialog. However, I could not figure out how to wright the function.

enter image description here

I tried all the Color function, but it did not worked. The color's name was taken from the "Select Text Color" within the "layer Styling" bar and it a shade of green that supposed to replace the red.

enter image description here


1 Answer 1


You can set a label color using expressions, but not in the label value field. You need to use the datadefined override for the color selector.


if( "Attribute_name" = 'value', '#FF0000', '#000000')

The above expression sets the color to red if true and black if false.

To help you build your expression you can also use the "Assistant..." when clicking on the datadefined override button to the right of the color selector.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.