Labeling in different colors is possible with html-formatted labels, introduced in QGIS 3.28. See here for some use cases.
Check the box Allow html formatting
in the Text
tab of label settings. Then insert a html code in the value field. Use format()
function, define the styles you want using placeholders like %1
, then add the text content you want to have formatted this way.
Here is an example of the syntax to use to have the first line with the content of field_1
in blue, on the next line field_2
in red:
format(
'<span style="color:blue"> <p> %1 </p> </span> <br>
<span style="color:red"> %2 </span>',
field_1,
field_2
)
or, with the same result, simply concatenating the different elements:
'<span style="color:blue"><p>' || field_1 || '</p></span>' ||
'<span style="color:red">' || field_2 || '</span><br>'
You can also mix this to get different font sizes, bold/strong, italic etc. like this:
'<span style="color:blue"><p style="font-size: 40pt"; ><strong>' || field_1 || '</strong></p></span>' ||
'<span style="color:red"><p style="font-size: 30pt"><i>' || field_2 || '</i></p></span>' ||
'<span style="color:green"><p style="font-size: 20pt">' || field3 || '</p></span>'