We derive the Mg/H ratio in the Orion nebula and in 30 Doradus. We also derive the O/H and the Fe/O ratios in the extremely metal-poor galaxy SBS 0335-052 E. We estimate the dust depletions of Mg, Si, and Fe in Galactic and extragalactic H II regions. From these depletions we estimate the fraction of O atoms embedded in dust as a function of the O/H ratio. We find an increasing depletion of O with increasing O/H. The O depletion increases from about 0.08 dex, for the metal poorest H II regions known, to about 0.12 dex, for metal-rich H II regions. This depletion has to be considered to compare nebular with stellar abundances.