Ophthalmic erythromycin is used to treat bacterial infections of the eye. This medication is also used to prevent bacterial infections of the eye in newborn babies. Erythromycin is in a class of medications called macrolide antibiotics. It works by killing bacteria that cause infections.