Find their comfortable distance
Start far enough away that your dog can notice the other dog with a loose body and turn away with you. If they stare hard, stiffen or bark, turn back or cross the road safely. A parked car can block the view. Shorten the outing if your dog stays tense.
Teach them what to do instead
Each time your dog notices another dog at that comfortable distance, give a treat, whatever your dog does. Stop the treats when the other dog is gone. Over time they learn that other dogs predict good things and often start looking back at you. If your dog barks or will not eat, you are too close, so add more space. A happy U-turn cue helps you leave quickly when needed.
Pick quieter times and places
While you are working on it, walk at quieter times, use a well-fitted harness and give lots of sniffing. Fewer stressful moments means faster progress.
Avoid punishment and get support
Yanking the lead or telling them off can make them more worried about other dogs. If your dog is getting worse, or you are worried about safety, a qualified reward-based behaviour professional can help. A vet check is worth it too, as pain can make dogs more reactive.