The more massive a planet or star is, the stronger the gravitational force it exerts. It is this force that allows a planet or star to hold other objects in their orbit. This is summed up in Isaac Newton's Universal Law of Gravitation, which is an equation for calculating the force of gravity.
Universal Law of Gravitation
Newton's Universal Law of Gravitation is a formula for understanding the relationship of gravity between two objects. The equation is "F = G(M1)(M2)/R," where "F" is the force of gravity, "G" is the gravitational constant, the "M"s are the masses of the objects being considered, and "R" is the radius of the distance between the two objects. Thus, the more massive either object is, and the closer they are together, the stronger the force of gravity.
Solar Systems and Moons
Gravity is what keeps planets in orbit around the sun. The sun is extremely massive, thus it holds very distant objects, like the outer planets and comets, in its orbit. This can also be seen on a smaller scale, with planets keeping satellites in their orbits; the more massive a planet is, the more distant its satellites. For example, Saturn, one of the gas giants, has the most known moons. Stars themselves orbit around the center of the galaxy.
Newton's three laws of motion are also applicable for understanding the effects of gravity on the cosmic law, particularly the first and third law. The first law states that an object at rest or in motion will remain in that state until something acts on it; this explains why planets and moons stay in their orbits. The third law is that for every action, there is an opposite and equal reaction. While this is negligible when considering something like a planet affecting a star, this explains tides on Earth, which are caused by the moon's gravity.
Newton understood how gravity worked, but not why. It wasn't until Albert Einstein's General Theory of Relativity, published in 1915, that a theory was postulated to explain the cause of gravity. Einstein showed that gravity was not a quality inherent to objects, but instead it was caused by curves in the space-time dimensions, which is what all objects rest on. Thus, even light and other massless phenomena are affected by gravity.