What is the relationship between something magnetic and unpaired electrons? I don't get how some elements are magnetic. Can someone please explain the relationship between something magnetic and unpaired electrons?

Why is cobalt magnetic?
There are five forms of magnetic behavior. Ferromagnetism is when a material is attracted to a magnetic field and can spontaneously hold a magnetic field alone (the typical form of magnetism).  Paramagnetism is when a material is attracted to a magnetic field but cannot spontaneously hold a magnetic field alone (the attraction may be too weak to observe practically).  Diamagnetism is a material that expels magnetic fields (essentially non-magnetic). there is also ferrimagnetic and anti-ferromagnetic but though these are interesting they not incredibly relevant to the answer.

Electrons form the magnetic fields of materials.  If a metal's atom have unpaired electrons the metal can attract a magnetic field.  If all of the electrons are paired in opposite spin orbitals then the spins cancel each other out and no response to a magnetic field is observed. 

Cobalt has unpaired electrons making it at minimum demonstrate paramagnetic behavior. It is however able to hold a magnetic field making it ferromagnetic.  Most metals have unpaired electron and are paramagnetic (for example: aluminum, zirconium, titanium, magnesium and potassium)  Ferromagnetic metals become paramagnetic at elevated temperatures and inversely many paramagnetic metals become ferromagnetic at low temperatures.