Co–Sm and Co–Pr films were deposited by dc magnetron sputtering. Transmission electron microscopy and magnetic measurement were used to study the microstructure and magnetic property relationship. The nanostructure of the as-deposited Co 19 at. % Sm films consists of two phases: the amorphous phase and the crystallite phase. Upon annealing at 600 °C, the Co5Sm phase with the Cu5Ca structure, having grain size of about 20 nm, is obtained along with high coercivity (45 kOe). The as-deposited Co 22 at. % Sm films also have nanostructure similar to the Co 19 at. % films except the volume fraction of the crystallite is reduced. This is related to the concentration of Sm which promotes the formation of the amorphous phase. A new metastable phase Co3Sm is formed upon annealing of the Co 22 at. % Sm film at 500 °C. This phase has the DO19 structure in which the Sm atoms take ordered positions of a triangular pattern in the close-packed planes. A relatively high coercivity value of 29 kOe was obtained from this phase. The as-deposited Co–Pr films show mainly an amorphous phase. Upon annealing at 500 °C for 20 min, Co2Pr with the Mg2Cu-type structure was identified in the Co 35 at. % Pr film. Two phases were identified in the Co 16 at. % Pr films. Coercivities up to 3.1 kOe were achieved in these films.