Lung maturity and surfactant
Lung development is usually adequate by the 7th month to support life outside the uterus. One of the critical factors in this process of maturation is the production of a substance within the lung called surfactant. This detergent-like substance reduces the surface tension of the fluid lining the alveoli, and allows them to stay open - without surfactant, the surface tension is high enough to cause collapse of the alveoli. This happens in very premature babies, greatly reducing the surface area available for gas exchange, and in the resulting struggle to breathe damage is done to the pulmonary epithelium. The accumulation of debris within the airways produces the condition known as hyaline membrane disease.
Removal of fluid
Before birth, the lungs are full of fluid. Most of this fluid is produced by the lungs themselves, but some consists of amniotic fluid drawn into the airways when the fetus practices breathing movements before birth. During birth, much of the fluid in the respiratory tree is expelled as the chest squeezes through the narrow birth canal. The remaining fluid is removed by the baby's pulmonary circulation and lymphatic system after birth.
Formation of respiratory system -
L = lung, H = heart,
ST = septum transversum,
M = mesonephros