Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
$\begingroup$Something worth noting: science never describes the true reason why something happens. It concentrates on predicting the effects of what happens. When one asks science "why," we answer by showing a deeper and more powerful model (such as Newtons' law of universal gravitation or Einstein's relativity). If you want the "real" reason for gravity, turn to philosophy or religion. They'll dare to try to answer such ontological questions.$\endgroup$
$\begingroup$@KeithThompson Just taking a stab at this, but maybe rotational energy? The rotational energy would be a cause of frame dragging which helps to distort the space-time around the mass and as GR tells us, space-time distortion is gravity.$\endgroup$
$\begingroup$The total mass-energy of the Earth is it's rest mass $\times c^2$ plus a negative term due to its potential energy plus a positive term due to the kinetic energy of its constituents. The latter two terms are tiny in comparison to the first. @KeithThompson$\endgroup$
Any massive body (i.e., a body having mass) like the stars, planets, moons, and any atom in the universe have, what is called, a gravitational potential which results in its gravity. This is described by Newton's Law of Gravity. Why masses cause gravity, we do not know.
So, in short, the earth's mass causes it to have gravity.
Anything that has mass will have gravity ( Exhibit a phenomemon called gravitation) not just black holes.
One way of understanding gravity was put forth by Newton as his law of gravitation. As @christo said, there is no clear knowledge of why it has gravity.
A more generic way to put it would be to say, anything that has mass curves the space around it. The force or gravity you would feel can be considered as the way you are being forced to follow the curved lines instead of your intended path. This is how Einstein's general theory of relativity explains gravitation.
In quantum mechanics, It is speculated that gravity is caused by exchanging particles called gravitons, think of it like the way you would play catch with your friends. Multiple objects having some mass throwing small balls called gravitons at each other. There is no evidence for the existence of gravitons yet, but it explains a lot of things in the quantum realm.
The earth is made from MANY particles, these particles get something called mass, from a thing called the higgs feild, this mass is how much gravity something has, the earth has its mass, and mass warps space time, like when you push your finger on your bed, it creates a curve that goes down, it happens for space, and things get attracted to earth.
The exciting thing is that everything has mass! Even us, but our mass, like some tens of KGs, are too small to create a gravitational pull, to pull other things, even just a centimeter away.