Prune rosemary and other shrubby herbs like thyme and lavender after flowering to prevent them getting leggy and keep them neat.
Rosemary is a real asset in the garden, making a handsome and spicily fragrant evergreen shrub with pretty lavender-blue flowers in early summer. In common with other Mediterranean herbs like lavender, though, it's prone to getting leggy without regular pruning, making long straggly stems with sparse, patchy foliage that's no good for picking. Eventually they flop, revealing an unsightly bare middle, by which time there's nothing you can do but dig the whole thing out and start again.
All this can be avoided, though, with a neat haircut in late spring. Wait till the flowers have finished so that you (and the bees) don't miss its spectacular display, then go over the whole thing with a pair of shears, cutting back new growth hard.
Stick to last year's paler, softer growth and don't cut into old, dark brown wood (unless you want to remove entire branches), as rosemary only regenerates from young, flexible stems. You'll find the plant quickly bounces back with plenty of dense, productive growth. Picking only encourages more young shoots packed to bursting with essential oils to fill your cooking with flavour all year round.