Imagine spacetime as a flexible fabric. When a massive object like a planet is placed on the fabric, it creates a dip or curvature in the fabric. This curvature causes nearby objects to move in certain ways, such as orbiting around the planet.
In a similar manner, photons also follow this curved spacetime. As they travel through a gravitational field, they follow the curvature created by massive objects. This results in the bending and deflection of light, a phenomenon known as gravitational lensing.
So, while photons have no mass, they are still affected by gravity because they interact with spacetime itself, which can be curved due to the presence of massive objects.