The greenhouse effect is “the trapping of the sun's warmth in a planet's lower atmosphere due to the greater transparency of the atmosphere to visible radiation (light) from the sun than to infrared radiation (heat) emitted from the planet's surface.”
Visible light and infrared light are both forms of electromagnetic radiation. Visible light is of a higher radiation frequency that penetrates the atmosphere and its gases with ease. It strikes the surface of the planet and there’s a step down in the energy level to the infrared radiation level which we feel as heat. This heat radiates back out towards space. However, certain gases such as CO2 absorb and re-emit the infrared energy, thus creating a blanket effect much like greenhouse glass does. Or, shall we say, the thicker the CO2, the warmer the atmospheric blanket becomes.
Diagram of visible light warming Earth and infrared light radiating away from Earth’s surface:
IR infrared radiation: