Hydrogen bonding occurs when an electronegative atom (such as oxygen, nitrogen, fluorine) attracts a nearby hydrogen atom more strongly than it does other atoms around it.
The partial negative charge on the electronegative atom is attracted to the positive end of another polar molecule or ion with a lone pair of electrons that can form a hydrogen bond.