To form a nebula, gravity plays a crucial role by pulling together gas and dust in space. Nebulae often form when regions of space become dense enough due to gravitational attraction. This increased density can arise from various sources, such as the remnants of a supernova explosion, stellar winds from nearby stars, or interactions between different clouds of gas and dust.
While you mentioned "causing an explosion," it’s important to clarify that explosions (like those from supernovae) can indeed disperse material and create new regions of gas and dust, but the actual formation of a nebula is primarily due to gravity pulling matter together. Over time, this accumulation can lead to the formation of new stars within the nebula as the gravitational forces continue to cause clumping, leading to increasing density and temperature until nuclear fusion occurs.
In summary, gravity is the dominant force in the formation of nebulae, while explosions can contribute to the creation of regions with sufficient material to potentially form new nebulae.