Scanning mechanisms that have application in confocal imaging use electromagnetic actuation to move elements in an optical system. An objective lens mounted to a flexure comprising a magnetic material is actuated in the axial direction by an electromagnet coil. An optical path may pass through the coil. Scanning in transverse directions may be provided using magnetically actuated flexible beams which move the tip of an optical fiber or other pinhole in one or more transverse directions. Actuators may be actuated using driving currents that include an AC component and a DC bias component. The scanning mechanisms may be miniaturized and may be constructed to provide real-time imaging.