Deposition of MgHx (MgH2 + Mg) thin films is performed using RF reactive sputtering in argon-hydrogen plasma. Films are characterized using x-ray diffraction (XRD), scanning electron microscopy, optical and resistivity measurements. Formation of crystalline MgH2 is confirmed by XRD, but the formation of some metallic Mg in the films could not be avoided. Increased H/Mg ratio by deposition at high hydrogen flow or high total pressure gives films that oxidize within days or weeks. Deposition at elevated substrate temperature results in improved crystallinity and stability. Initial studies of MgHx for silicon surface passivation are presented.