How were stars like the sun formed?
The sun formed 5000 million years ago from a cloud of hydrogen, helium and dust, which contracted under its own gravity.
the sun and the rest of the solar system formed from a giant, rotating cloud of gas and dust known as the solar nebula. As the nebula collapsed because of its gravity, it spun faster and flattened into a disk. Most of the material was pulled toward the center to form the sun.