Two scan modes were developed for an Omicron atomic force microscope/scanning tunneling microscope (AFM/STM) operating in ultra-high vacuum (UHV). These modes allow scanning at a constant tip–sample distance in order to measure forces or force gradients. Samples and tip probes were prepared and used in the same UHV system. Co films were deposited on Si substrates by electron beam evaporation. The thickness of these films was 2–120 monolayers (ML). Si tips, coated with 20 ML Fe, were used as probes. The Co films showed a magnetic structure with in-plane magnetization. Cross-tie domain walls were also observed. Furthermore, the Co film was sensitive to forces exerted by the tip on the sample in contact AFM mode. Operating a magnetic force microscope (MFM) in ultra-high vacuum (UHV) has some fundamental advantages over using it in ambient conditions. The MFM tips are entirely prepared in UHV, and used in situ. Ultra-thin magnetic films are prepared without any protecting cap layer. Lack of tip protection reduces the effective tip–sample distance, which has an essential effect on the resolution and the sensitivity. Furthermore, any possible effect of the sample cap layer on domain structure is excluded. UHV–MFM therefore provides the best conditions for investigating the domain structures of as-prepared magnetic films. We adapted the software of a commercial Omicron UHV AFM/STM system (Omicron Vacuumphysik GmbH, D65232 Taunusstein) to enable MFM operation. This includes software-controlled determination of the sample slope to ensure measurement of force or force gradient at a welldefined height above the sample surface. The system was initially tested on Co/Pt multilayers, garnet films and barium ferrite [1]. We describe the application of UHV–MFM to magnetic domain and domain wall investigations of Co thin films prepared in situ. 1 Experimental 1.1 Experimental set-up The UHV system consists of two chambers, both at a base pressure below 109 Pa (10−10 torr). One chamber, equipped with an argon ion gun, was used entirely for tip and sample preparation. The tips were ion-sputtered before iron was evaporated on to them using an electron beam evaporation technique. Another evaporator was mounted to deposit ultrathin Co films on Si(100) substrates. The second chamber (the analysis chamber) was equipped with a LEED/AES unit and an Omicron AFM/STM mounted on a damping stage. Cantilevers and samples could be changed in situ. The samples were on a holder attached to a piezo element. The maximum range of scanning was 6 μm along the x and the y axes. The cantilevers were mounted on a piezo element which in turn could be excited at the cantilever resonance frequency. Owing to force gradients acting on the probe tip, the resonance frequency varied as ω =√k− (∂F/∂z)/meff. The shift of the frequency was measured by an FM detector. The frequency shift could be kept constant by a feedback loop to measure topography in noncontact mode. The height data obtained in this manner represent a surface of constant force gradient. Using a magnetic tip over a magnetic sample the force gradient at low frequency shifts (i.e. relatively far apart from the sample surface) is dominated by magnetic interaction. Thus information about the local domain structure is obtained. A different approach is applied to measure forces or force gradients at a constant tip to sample distance. Two scan modes were built into the system to realize this approach. The first mode works similarly to the “lift mode” of the Nanoscope (Digital Instruments GmbH, D-68199 Mannheim). The topography of the sample is measured along a single line. This can be done either in STM, AFM contact or AFM noncontact mode. Subsequently, the topographic information is used to scan the tip at a given height above the same scan