The molecules of a liquid attract each other due to gravitation. If any molecule inside a liquid is considered, it is obvious that it is attracted uniformly in all directions by its surrounding molecules. So, the resultant attractive force is zero, and the molecule remains stationary.
On the other hand, for any molecule on the liquid surface, the downward attraction isn’t balanced by any equivalent upward force. Therefore, each surface molecule experiences a resultant force acting downwards. As a result, the surface molecules tend to dip inside the liquid and the area of this free surface tends to contract. This property of a liquid is referred to as surface tension.
However, the contraction of the free surface of a liquid doesn’t continue indefinitely. When any two liquid molecules come within an overlapping distance, elastic stress is developed and they effectively repel each other in order to retain the molecular shapes. This actually is the origin of the property of incompressibility of a liquid. The opposing effects of this repulsion and the gravitational attraction among the molecules bring the liquid surface to an eventual equilibrium state. When the net potential energy of the surface molecules reaches a minimum value.