It is basically because of the phenomenon of scattering. Sunlight gets scattered by small air molecules during its passage through the atmosphere. Also note that all the 7 colors of sunlight does not scatters at the same rate. Scattering is inversely proportional to wavelength. That is, blue with the shortest wavelength will scatter more compared to the red with the highest wavelength. In short, as a result of this greater scattering of blue light by the air molecules in all directions make the atmosphere appear blue during cloudless daytime.