It’s ‘cuckoo spit’. Beneath the foam you’ll find a little green sap sucking froghopper insect. I just brush them off with my fingers but a jet of water will work too.
It's very common on lavender too. It's harmless but if you don't like the look of it you can just hose it off. (It often returns though, but won't go on for long!)
They rarely eat enough of the leaves to be noticeable, and they're part of the great cycle of life, providing food for birds etc. I love to see it ... reminds me of my childhood when we'd keep an eye out for it and hope to hear the cuckoo calling ... that's how it got it's name ... because it appears when the cuckoos do.
Gardening in Central Norfolk on improved gritty moraine over chalk ... free-draining.
The nymphs can cause some leaf distortion if feeding on the tips but nothing serious. The RHS advises to leave them in the garden as they are part of its biodiversity: Cuckoo spit (spittlebugs) / RHS Gardening
Same here — I’ve not noticed any damage on my rosemary or lavender with them. I used to hose it off with water but seems they come back anyway, so I don’t bother anymore.
Rosemary beetles are another thing — I squish them on sight!
Posts
Gardening in Central Norfolk on improved gritty moraine over chalk ... free-draining.
Cuckoo spit (spittlebugs) / RHS Gardening