Tides in the oceans are primarily caused by the gravitational forces exerted by the Moon and the Sun on Earth. The gravitational pull of the Moon causes the water on the side of Earth facing the Moon to bulge out, creating a high tide. At the same time, there is another high tide on the opposite side of Earth, due to the centrifugal force caused by the Earth and the water being pulled away from each other.
As Earth rotates, locations on its surface move through these high tide bulges, causing the water level to rise and fall in a repeating pattern, resulting in two high tides and two low tides each day. The gravitational force of the Sun also affects the tides, although to a lesser extent than the Moon. This combined effect of the gravitational forces of the Moon and the Sun leads to the formation of tides in the oceans.