Recent studies have demonstrated that large secondary motions are excited by surface roughness with dominant spanwise length scales of the order of the flow's outer length scale. Inspired by this, we explore the effect of spanwise heterogeneous surface temperature in weakly to strongly stratified closed channel flow (at
$Ri_\tau =120$
, 960;
$Re_\tau = 180$
, 550) with direct numerical simulations. The configuration consists of equally sized strips of high and low temperature at the lower and upper boundaries, while an overall stable stratification is induced by imposing an average temperature difference between the top and bottom. We consider the influence of the width of the strips (
${\rm \pi} /8 \leq \lambda /h \leq 4{\rm \pi} $
), Reynolds number, stability and upper boundary condition on the mean flow structure, skin friction and heat transfer. Results indicate that secondary flows are excited, with alternating high- and low-momentum pathways and vortices, similar to the patterns induced by spanwise heterogeneous surface roughness. We find that the impact of the surface heterogeneity on the outer layer depends strongly on the spanwise heterogeneity length scale of the surface temperature. Comparison to stable channel flow with uniform temperature reveals that the heterogeneous surface temperature increases the global friction coefficient and reduces the global Nusselt number in most cases. However, for the high-Reynolds cases with
$\lambda /h \geq {\rm \pi} /2$
, we find a reduction of the friction coefficient. At stronger stability, the vertical extent of the vortices is reduced and the impact of the heterogeneous temperature on momentum and heat transfer is smaller.