Is it possible to underline a label in a different color than the one used to write the said label using QGIS?

In my case, I would like to underline some countries' names, which are in black, in red. Here is how I would like it to look like:

enter image description here


2 Answers 2


It's possible but it's a bit messy.

The overall idea is to add a background rectangle that is squashed vertically so much that it's just a horizontal line, and then offset downwards so it looks like its an underline. Then just colour the background outline a different colour like red.

To do this I went to the background tab in Labels and I used the following settings:

  • Shape = Rectangle
  • Size X = 0
  • Size Y = -1.9
  • Offset X,Y = 0, 2.2
  • Stroke colour = red

You might have to play around with the sizes and offsets depending on your label size and font. For me I used MS Shell Dlg 2 at size 9 points and it ended up looking like this: enter image description here

You can then add a conditional expression for the stroke colour if you want different labels to have different colour underlines.

Also the obvious downside of this is that it impacts your ability to add a background if you want one. It would probably be possible but it would be harder to do.

  • 1
    Okay! Thank you very much! I had thought about this but I wondered whether there was a better solution especially in the case of a multi-line label... Do you think it could work in that case? It does not seem so to me... Thanks again for taking the time to answer me!
    – Léo Mazel
    Commented Jun 1, 2021 at 12:30
  • @LéoMazel Happy to help. For a multiline you may have to turn on Rule Based Labelling to split the two lines into different rules then apply some offset to the second rule. I think that would be possible but it would definitely make it more complicated. Commented Jun 1, 2021 at 16:01

The other answer, with a coloured squashed background, is probably your best bet.

Alternatively, with some effort you could probably achieve what you want by constructing embedded SVG to use as your label, including both your desired label text as well as the target underline. As a starting point, see the answer to QGIS Labels with HTML formating, where it is developed for a different use case (emulating HTML) but gives some ideas.

Note QGIS does offer HTML formatting of labels, but currently only text colour is implemented, so it won't solve your problem directly.

  • Thanks for elaborating! I will try to use this, thanks!
    – Léo Mazel
    Commented Jun 1, 2021 at 13:24

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.