The process of childbirth moved from homes to hospitals in the early 20th century. New standards and practices meant that nurses took care of babies while the mother rested for days. The babies became concentrated in nurseries to make things easier for the nurses, but family members still wanted to see the babies, which created a dilemma for hospital staff wanting to isolate the newborns from the horde of germs carried in by visitors.
The stated purpose for the viewing window was twofold: first, the window allows relatives to “see the infants,” and second, the window serves as a barrier to prevent contact between relatives and the newborns they have come to see. But while hospitals justified the construction of these windows as sanitary barriers between newborns and the general hospital community, it’s unlikely that infection prevention was a primary motivator. If windows served mainly as antibacterial barriers, the hospitals would have had no reason to install them in the first place; standard windowless walls surrounding nurseries would have been less trouble to build, and would have eliminated the potential for compromising the barrier between the nursery and the corridor via cracks between the window and the wall. Thus, the ubiquitous nursery window served a primarily social function.
Hospital viewing windows became a popular spot for not just relatives, but anyone who wanted to take a look. Today, the pendulum has moved the other way. Babies are normally kept in the mother's room, where family visits take place, and they are sent home the next day (or even the same day). But the public still wants to see new babies through a window. Read about the rise and fall of the nursery viewing window at Smithsonian.