This magnetic sensor is provided with: a substrate; a magnetoresistive element group including first and second magnetoresistive elements disposed on the substrate; and a magnet group including first and second magnets corresponding to the first and second magnetoresistive elements, respectively. This magnetic sensor can be made more compact and more precise.