A hydrogen bond occurs because a hydrogen atom with a polar covalent bond to oxygen, nitrogen or fluorine has a partial positive charge, and it is strongly attracted to the parts of similar molecules with a partial negative charge. The most common example is water, which contains hydrogen and oxygen.
The amount of hydrogen bonding that occurs in a substance depends on the electron structure of the partially negative parts of the molecules. When oxygen binds to hydrogen, for instance, the oxygen and hydrogen share two electrons, one from each atom. The oxygen in water is bound to two hydrogens. This gives the oxygen atom a total of eight electrons in its outermost orbit, four of which are not shared with any hydrogen atoms.
These electrons are paired, so the molecule has two groups of two electrons. Each pair of unshared electrons can form a hydrogen bond with a hydrogen atom covalently bound to another oxygen atom, so each water molecule can have a hydrogen bond with the hydrogen from two other water molecules. Each of its two hydrogen atoms can form a hydrogen bond with the oxygen of another water molecule, so each water molecule can form a total of four hydrogen bonds.
Hydrogen bonds are stronger than most polar forces, but are still much weaker than the covalent bonds within molecules.