While some of the details about how the earth came to be remain a mystery, scientists have learned much from studying old rock materials and observing natural phenomena in space. The earth was formed about 4.6 billion years ago when bits of rocks and dust floating in space began to clump together due to their gravitational pull. At this time, many of the other planets in our solar system were beginning to form from the same cloud of gas and particulates. In fact, the sun was formed from the gases in this cloud.
As the bits of rock and dust began to clump together, they amassed into bigger forms like asteroids, repeatedly slammed into each other by gravity. These large rock masses drew even more particulate in-- think of how meteorites are drawn in by our planet's gravitational pull. The collisions caused extreme volcanism, so the surface of our planet was molten rock for a long time. Eventually, the planet began to cool and the crust was formed. With a cooled crust, hydrogen and oxygen in the atmosphere were able to form into liquid water, creating the oceans on our planet's surface.
The same geological and cosmological processes which formed our planet are still at work today, as meteorites continue to fall to the earth and volcanoes are constantly spilling out fresh lava. You could say our planet is still being made!