I want to label my values in a specific color. They are all in the same shapefile which makes it complicated.

For example:

  • if value is 10, it should appear in blue
  • if value is 15, it should appear in green
  • if value is 25, it should appear in red

How can I do that?

2 Answers 2


If you right-click your layer and go to:

Properties > Labels

Use the Show labels for this layer option, select the field to label with and then click the data-defined button for the Color section as shown below:

Properties for labels

Then enter an expression like:

  WHEN "Field" = 10 THEN color_rgb(0, 0, 255) 
  WHEN "Field" = 15 THEN color_rgb(0, 255, 0)
  WHEN "Field" = 25 THEN color_rgb(255, 0, 0)
  ELSE color_rgb(0, 0, 0)


  WHEN "Field" = 10 THEN '#0000ff'
  WHEN "Field" = 15 THEN '#00ff00'
  WHEN "Field" = 25 THEN '#ff0000'
  ELSE '#000000'

Click Apply then OK and hopefully you should see your labels with different colours:


Tested on QGIS 2.16.1-Nødebo.

  • Just one more question, if i have a range, lets say from 10 to 14 and i want to color the whole range to blue. How do i adapt it to the formula?
    – Philipp B.
    Nov 11, 2016 at 11:58
  • @Philipp - Use something like WHEN "Field" >= 10 AND "Field" <= 14 THEN color_rgb(0, 0, 255) .
    – Joseph
    Nov 11, 2016 at 12:00

If you want to change any more than the color your best bet would be Rule based labeling, though for a single value you are better off using expressions for that specific value as already mentioned.

Rule based labelling screen

From memory this method has also been around for longer than expressions in data definitions and so should work further back in versions. Though someone please correct me if my memory is off there.

  • Indeed, rule-based labelling is a lot more simpler to use when setting additional properties. +1!
    – Joseph
    Nov 11, 2016 at 11:30

Your Answer

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

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