Hydrogen bonding arises when a chemical bond is polarised to one end of it has a slight positive charge and the other has a slight negative charge. In the case of o-nitrophenol it's mainly the OH bond that is polarised - the H atom has a slight positive charge and the O atom has a slight negative charge. The charge separation means the OH bond has an electric dipole.
Electric dipoles interact with each other, so the dipole on one o-nitrophenol molecule can attract the dipole on a neighbouring o-nitrophenol molecule. This creates the attractive force between the molecules known as a hydrogen bond. There is an extended description of this on this web site.
Just to complicate matters o-nitrophenol can also exhibit intra-molecular hydrogen bonding. This is because the OH and NO$_2$ groups are next door to each other, and the H on the OH group can interact with the O on the NO$_2$ group.
Response to comment:
Intramolecular hydrogen bonding will not cause molecules to repel each other, but it will reduce the attractive interactions between molecules. This is simply because in o-nitrophenol the OH group forms a hydrogen bond with the adjacent nitro group and that reduces its ability to form hydrogen bonds with other molecules. In p-nitrophenol the OH and nitro groups are on opposite sides of the molecule so there can't be any intramolecular hydrogen bonding and therefore the intermolecular hydrogen bonding is stronger. So o-nitrophenol has a melting point of 44ºC while p-nitro[henol has a melting point of 113ºC.
So intramolecular hydrogen bonding won't cause the molecules to separate, but it will make them bind together less strongly.