Scientists think Earth was formed at roughly the same time as the sun and other planets some 4.6 billion years ago, when the solar system coalesced 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.
Other particles within the disk collided and stuck together to form ever-larger bodies, including Earth. The solar wind from the sun was so powerful that it swept away most of the lighter elements, such as hydrogen and helium, from the innermost worlds, rendering Earth and its siblings into small, rocky planets.