Why are HgO and CdS compounds colourful? We know that the electron configuration in $3d$ orbitals of $\ce{Zn^2+}$, in $4d$ orbitals of $\ce{Cd^2+}$ and in $5d$ orbitals of $\ce{Hg^2+}$ ions are completely same.

Then why the compounds of $\ce{Hg(II)}$ and $\ce{Cd}$, such as $\ce{HgO}$, $\ce{CdS}$ radiate versatile colour where $\ce{ZnO}$, $\ce{ZnS}$ are white?
The band gap decreases as either electronegativity of the anion decreases (electronegativity of anion in CdS &lt; CdTe , ZnS &lt; ZnSe) or the overlap decreases (overlap in ZnS > CdS).

Also, note that colored compounds only result when 1.8 &lt; Band gap &lt; 3.0. Larger gaps give white/transparent &amp; smaller gaps give a black colour to compounds.
(The band gap in ZnS is 3.54, the band gap in CdS is 2.45.)