The Sun started out as a large collapsing cloud of gas in an ancient interstellar cloud that was "polluted" by a supernova (an explosion of a star) a couple million years before the collapse phase ended. When the cloud stopped collapsing, it formed a rotating disk with a large central bulge which formed the Sun.🌞
Most scientists think Earth started out as a cloud of cold dust particles swirling through space. They were disturbed by the explosion of a nearby star and started to collapse. As everything was pulled together by gravity, it formed a solar nebula. That spun and the disk accreted to the Sun and the outer rings turned into large burning balls of gas and liquid that eventually cooled into a solid, earth. 🌎
One theory of how the Moon was formed is that the Moon was once part of earth and somehow separated. Another theory is that it was formed somewhere else in the solar system and later the gravitational field of earth captured it and pulled it in.🌕