No one knows what causes gravity, but it is described as a force that attracts two objects to each other. All objects gravitationally pull other objects.
For example, the earth gravitationally pulls on you, while you pull on the earth. This pull can also be seen when inanimate objects are gravitationally pulled towards earth and when planets orbit the sun.
Gravity is affected both by the mass of the two objects being pulled towards each other and the distance between the two objects.
Gravity exemplifies the inverse square law, meaning that when the two objects are a distance x away from each other and you move the objects to a distance of 2x, the force of gravity at 2x will be one fourth of that it was when it was at x. This means that if you go far away from earth that the effects of gravity will be so weak that you won’t feel anything.
Gravity allows the sun to keep the planets in orbit because even though the distance between the sun and the planets is great, the sun and planets have great masses, meaning that they still have strong gravitational attractions. This is the same reason why moons orbit planets.