In short atoms and molecules are repelled by magnets (diamagnetic) if they have no unpaired electrons (only electrons with 2 different spins in orbitals) but are somewhat attracted to magnets (paramagnetic) when they have at least 1 unpaired (electron with 1 spin in orbital) electron in their outermost electron layer. Diamagnetism is weakest form of magnetism and due to this weakness it shows up usually when material has no unpaired electron. Also core electrons deeper in atom contribute to diamagnetism due to aligning with outside magnetism and causing internal magnetic field that pushes away from outside magnetic field. Diamagnetic response is believed to have similar mechanism to larger scale magnetic responses as outside magnetic field that can move electrons in material cause magnetic field in that material (superconductor, ring of wire, benzene ring or just atom) that tries to repel outside magnetic field.
Some of the more stronger room temperature diamagnets are purely carbon compounds like graphene, pyrolytic carbon and diamonds. Carbon has connection to 4 other atoms and in these materials all 4 are paired making all carbon atom electrons diamagnetic.
Water is weakly diamagnetic (superconductor are about 100 000 times more diamagnetic than water) and its stream can be pushed few millimeters away from strong magnet (clip). Another more sensitive way to test it is to put water container on floating vessel and slowly push it by holding magnet near water (clip). As animals are mostly water they can be floated above strong enough magnets. Frogs may float at around 10 tesla (clip). Humans have been tested in at least 7 tesla MRIs and while they didn't float they had some additional side effects like flashes after changing direction of magnetic field. These flashes were suspected to be caused by diamagnetic responses in parts of retinal rod cells that realign themselves and by pressing against each other they may activate each others. Rhodopsin is the light sensitive protein in rod cells and at least these proteins are also diamagnetic.
Copper is one of the few diamagnetic metals (clip) and copper pipes can slow down strong magnets falling through them.
Main difference between ferromagnets
and paramagnets is that ferromagnets don't need outside magnetic field
to become and stay magnetic. Both of these arise from unpaired electron
but crystal structure of ferromagnets keeps them from losing magnetism
due to heat movements that remove magnetism from paramagnetic materials with random movements. Permanent magnets use crystal structure that are magnetic in certain directions while resisting alignments in other directions. In production of permanent magnets all these crystals get aligned in one direction so entire material would spontaneously magnetize in same direction with enough stability to stay that way below curie temperatures.
Table showing unpaired electrons for single ions. Single hydrogen atom is purely paramagnetic and attracted to magnets but it becomes diamagnetic after becoming hydrogen molecule with all electrons paired. Transition metals have unfilled d orbitals that make them paramagnetic or ferromagnetic. Electron are in increasingly more diamagnetic configurations in lower rows of transition metals and most famous strong magnets use elements from 1st row of transition metals.
Electron pairing is usually shown with single or 2 opposite oriented arrows. Transition metals usually have electron orbitals with same energies (degenerate orbitals) and electrons can move freely as gas in transition metals between orbitals. Magnetism can arise in combination with other element. According to crystal field theory electrons stop having equal energy if other element has electrostatic effect on metal atom by pulling or pushing electrons to 1 side of atom.
2 rows show orbitals on side of metal closer to and further from other element that had electrostatic effect. Electrons closer to neighboring atom gets some extra energy from electrostatic interaction and if energy difference between orbitals is small then electrons can occupy them singly with high spin electrons (arrow up).
If resulting interaction between atoms makes some orbitals harder to access so it would take less energy to combine with other electron on same orbital then electrons tend to pair up (low-spin) and not go on new orbital unless all single electrons are paired.