Molecules are made up of atoms linked together by sharing electrons. The electrons in atoms and molecules can jump up energy levels if exactly the right amount of energy is supplied. This amount of energy can be provided by electromagnetic radiation.
Visible light is one form of electromagnetic radiation.
Small molecules, with little spreading out of electrons, have large energy steps and so require electromagnetic radiation of higher energy than visible light. Consequently visible light passes through such molecules and they appear transparent. For larger molecules, if the electrons are spread out enough in the molecule, the energy levels for the electrons are close enough together that visible light has enough energy to make the electrons jump up a level. When this happens, the particular energy of light, which corresponds to a particular wavelength or colour, is absorbed and disappears. The remaining light, lacking this colour, shows the remaining mixture of colours as non-white light.