It is true that photons, which are particles of light, are considered massless according to our current understanding of physics. However, even though photons have no rest mass, they are still affected by gravity. This can be explained by the theory of general relativity, proposed by Albert Einstein.
In general relativity, gravity is not considered as a force acting on particles but as the curvature of spacetime caused by mass and energy. Massive objects, such as stars or planets, curve the surrounding spacetime, and the path of light passing through this curved spacetime is affected. Photons traveling near a massive object, like a star or a black hole, follow a curved trajectory due to the curvature of spacetime caused by the object's mass.
The effect of gravity on light can be observed through phenomena such as gravitational lensing, where light from a distant source is bent by the gravitational field of a massive object, creating distortions or multiple images. This effect has been confirmed through observations and experiments, providing evidence for the interaction between mass and light, even though photons themselves have no mass.
So, while photons themselves do not possess mass, they still experience the effects of gravity because they travel through curved spacetime created by massive objects according to the predictions of general relativity.