To provide a magnetic encoder in which the air gap between a magnetic scale part and a detecting element can be kept constant and which can obtain a stable output.
A magnetic scale part 11 which comprises a magnetic-pole pattern for position detection is provided. In addition, a holder 13 which holds a detecting element 12 used to detect the magnetic-pole pattern of the magnetic scale part 11, which comprises an insertion and passage hole 14 for the insertion and the passage of the magnetic scale part 11 and which can be slid with reference to the magnetic scale part 11 is provided. At this time, an urging body 15 by which the magnetic scale part 11 is always urged to the side of the detecting element 12 is installed at the holder 13. In addition, the detecting element 12 is held by the holder 13 so as to be faced nearly parallel to the magnetic scale part 11.
ONAKA KAZUHIRO