Whether a bond is nonpolar or polar covalent is determined by a property of the bonding atoms called electronegativity.
Electronegativity values of the elements were proposed by one of the most famous chemists of the twentieth century: Linus Pauling. Pauling investigated the energies required to break bonds in heteronuclear molecules such as hydrogen and fluoride. Based on the values, he proposed that the energy required to break a bond will be the average of bond energies of H2 (436 kJ/mol) and F2 (155 kJ/mol), i.e., 296 kJ/mol. However, the experimentally obtained bond energy of HF is 565 kJ/mol, which is much higher than the predicted value. To account for this difference, Pauling suggested that the bond must have an ionic character, which is determined by the concept of electronegativity.
Electronegativity is a measure of the tendency of an atom to attract electrons (or electron density) towards itself.
Electronegativity determines how the shared electrons are distributed between the two atoms in a bond. The more strongly an atom attracts the electrons in its bonds, the larger its electronegativity. Electrons in a polar covalent bond are shifted toward the more electronegative atom; thus, the more electronegative atom is the one with the partial negative charge. The greater the difference in electronegativity, the more polarized the electron distribution and the larger the partial charges of the atoms.
Be careful not to confuse electronegativity and electron affinity. The electron affinity of an element is a measurable physical quantity, namely, the energy released or absorbed when an isolated gas-phase atom acquires an electron, measured in kJ/mol. Electronegativity, on the other hand, describes how tightly an atom attracts electrons in a bond. It is a dimensionless quantity that is calculated, not measured. Pauling derived the first electronegativity values by comparing the amounts of energy required to break different types of bonds. He chose an arbitrary relative scale ranging from 0 to 4.
This text is adapted from Openstax, Chemistry 2e, Section: 7.2 Covalent Bonding.