Water and oil are made up of entirely different elements and have distinct physical and chemical characteristics. The water molecule is composed of two Hydrogen atoms and an Oxygen atom. But the atoms are not arranged in a straight line. The two hydrogen atoms are aligned to one side of the oxygen atom which occupies a sharp end, forming the shape of English letter V. The molecule has a small positive charge at the end of Hydrogen atoms and the end of Oxygen atom has a slightly negative charge, due to the difference in electronegativity of the two atoms. This makes water a polar molecule. As you know, opposite charges attract each other. Hence, the negative poles on each water molecule are attracted to the positive poles on other water molecules. This constitutes a tight bonding between molecules, called hydrogen bonds.
As for oil, it is a non-polar chemical. Oils are made of fatty acids. The electron sharing is more even in non-polar molecules and they have no charge. Hence, they are not attracted to other polar molecules like water. They attract molecules of their own kind and cluster together. Polar molecules dissolve only in polar solvents and non-polar molecules dissolve only in non-polar solvents. This nature essentially separates water and oil into two separate layers. The oil floats on top of the water simply because it is less dense than water.
However, with the advancement of science, it is possible to mix the two substances now. It is done using a mediating agent, called emulsifier. Most of them create bonds to both oil and water. The end product is an emulsion in which one substance is spread through the other. The detergents and soaps we use in daily lives are examples of emulsifiers.
You might also like: