Surface tension is caused by the attraction between the liquid’s molecules by various intermolecular forces. In the bulk of the liquid, each molecule is pulled equally in every direction by neighbouring liquid molecules, resulting in a net force of zero. At the surface of the liquid, the molecules are pulled inwards by other molecules deeper inside the liquid and are not attracted as intensely by the molecules in the neighbouring medium (be it vacuum, air or another liquid). Therefore, all of the molecules at the surface are subject to an inward force of molecular attraction which is balanced only by the liquid’s resistance to compression, meaning there is no net inward force. However, there is a driving force to diminish the surface area. Therefore, the surface area of the liquid shrinks until it has the lowest surface area possible.
Surface tension ends up forming spheres, as opposed to other shapes, due to spheres having the smallest possible surface area to volume ratio.