Is it possible in QGIS to apply a gradient to linear features? I'd like for some roads to fade from opaque to transparent as they get further away from some set of points. I can measure the distance to any node on the line and thus for each line could define a start and end distance to base the gradient on.

I've approximated the effect I want by splitting my roads into shorter two-node segments and applying color based on the distance to the second node. The effect however is quite discontinuous and there are many more points where semi-transparent lines overlap slightly than there would be if I was using the original linestrings.

Highways fading with distance from street network

Is there any way to make this look a bit better?

(Related questions which I hope are outdated now: Gradient colour for lines, How to visualize measure values along linestrings in QGIS?)

  • If you choose a flat cap style instead of square (square is the default), the line segments won't overlap as much.
    – csk
    Commented Oct 7, 2019 at 21:21

1 Answer 1


Using Geometry Generator in style, you can change line feature to be rendered as polygon. For example added as small buffer, and later on style that buffer as polygon, so add gradient to it.


  • 5
    That appears to apply the gradient from the top of the screen to the bottom. If I understand the question correctly, the desired effect is for the line to transition from the first vertex to the last, regardless of the direction of the line. Commented Oct 8, 2019 at 21:52
  • 1
    Was any solution found for applying gradient to a line depending on the start and end vertexes? Commented Feb 3, 2022 at 20:06

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.