Just curious. It sorta seems like magic. But I have no idea what it is, and why it exists.
Basically is due the motion of the electric charges in the material. Moving electric fields induce a magnetic field. In a magnet this magnetic field is created due the net of electron spins. When the electron spins are aligned they create the magnetic poles that interact. All materials are somehow magnetic, magnets are ferromagnetic (have an intrinsic magnetic field). Materials that have no magnetic field but are attracted to them are paramagnetic, materials that have also no magnetic field but are repelled to them are diamagnetic.
It's a miracle eh. Listen to: Insane Clown Posse - Miracles But seriously now, I just took physics 30 and we talked about this but I don't remember. :P It has something to do with the electrical field and the particle moving through it.
Materials consist of electrons orbiting nuclei. The electrons carry charge, and it is the movement of charges that cause magnetic fields to appear. In most materials these fields point in all sorts of directions and don't build up to anything. In magnets some of these line up and generate an overall magnetic field. So your next question might be why do moving charges create magnetic fields? A magnetic field is a 'space' component to the general electromagnetic field (the electric field is the time component) and Einstein's special theory of relativity demands that moving electric fields will have a magnetic component. Ok, so your next question might be why do charges generate electric fields. Hey that's a good one - when you find out let me know.