At the time, the germ theory of disease had yet to be established. The prevailing thinking was the miasma theory of disease, which held that disease was caused by bad air and especially bad smells.
Plague doctor masks were sort of like primitive gas masks. The “beak” was filled with aromatics like herbs and dried flowers to stop the “miasma” from infiltrating. The distinctive costume also openly indicated their profession, which may have been required by law in some cities.
Latest Answers