We study the thermal structure and evolution of magnetars as cooling neutron stars with a phenomenological heat source in an internal layer. We focus on the effect of magnetized (B > 10^{14} G) non-accreted and accreted outermost envelopes composed of different elements, from iron to hydrogen or helium. We discuss a combined effect of thermal conduction and neutrino emission in the outer neutron star crust and calculate the cooling of magnetars with a dipole magnetic field for various locations of the heat layer, heat rates and magnetic field strengths. Combined effects of strong magnetic fields and light-element composition simplify the interpretation of magnetars in our model: these effects allow one to interpret observations assuming less extreme (therefore, more realistic) heating. Massive magnetars, with fast neutrino cooling in their cores, can have higher thermal surface luminosity.