To check the impact of the multiple population scenario for globular clusters on their horizontal branch (HB), we present an analysis of the composition of 110 red HB (RHB) stars in 47Tucanae and of 61 blue HB (BHB) and 30 RHB stars in M5. In 47Tuc we found tight relations between the colours of the stars and their abundances of p-capture elements. This strongly supports the idea that the He content - which is expected to be closely correlated with the abundances of p-capture elements - is the third parameter (after overall metallicity and age) that determines the colour of HB stars. However, the range in He abundance must be small (ΔY<0.03) in47Tuc to reproduce our observations; this agrees with previous analyses. There is possibly a correlation between the abundances of p- and n-capture elements in47Tuc. If confirmed, this might suggest that asymptotic giant branch stars of moderate mass contributed to the gas from which second-generation stars formed. Considering the selection effects in our sample (which does not include stars warmer than 11 000K and RR Lyrae variables, which were excluded because we could not obtain accurate abundances with the adopted observing procedure) is important to understand our results for M5. In this case, we find that, as expected, RHB stars are Na-poor and O-rich, and likely belong to the primordial population. There is a clear correlation of the [Na/O] ratio and N abundance with colour along the BHB. A derivation of the He abundance for these stars yields a low value of Y=0.22±0.03. This is expected because HBstars of a putative He-rich population in this cluster should be warmer than 11 000K, and would accordingly not have been sampled by our analysis. However, we need some additional source of scatter in the total mass loss of stars climbing up the red giant branch to reproduce our results for M5. Finally, we found a C-star on the HB of 47Tuc and a Ba-rich, fast-rotating, likely binary star on the HB of M5. These stars are among the brightest and coolest HB stars.