The main force responsible for tides is the gravitational pull of the Moon. The Moon's gravity exerts a greater force on the side of the Earth facing it, causing the water to bulge out in that direction. This creates a high tide on the side of the Earth facing the Moon.
The Sun also exerts a gravitational force on the Earth, but its effect on tides is less significant than that of the Moon. The Sun's gravity pulls on the entire Earth, causing a slight bulge on both sides of the planet. These bulges are not as pronounced as those caused by the Moon, so they produce a smaller tidal effect.
The rotation of the Earth also plays a role in the formation of tides. As the Earth rotates, the bulges of water created by the Moon's and Sun's gravity move around the planet, causing the rise and fall of the tides.
In addition to these main factors, the shape of the coastline, the depth of the water, and the local geography can all influence the exact timing and height of tides in a particular location.