This is a wonderful question … in the first instance, it’s answered by Einstein’s theory of general relativity. (Spoiler alert, light travels along geodesics, which are approximately straight lines in most circumstances that humans encounter in everyday life, but are curved by gravity). It’s also interesting because there is some sense in which light does have “mass” and therefore should be influenced by gravity.
https://www.forbes.com/sites/quora/2017/11/22/why-is-light-affected-by-gravity/#a1ff88511ceb
In recent years, several papers on the mass and charge of photons have been publishedPhoton has the upper limit of mass (a nonzero photon mass), [1] and the minimum of electric charge which challenges the old approach to the photon. [2]
1 - https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.111.021801
2- https://www.sciencedirect.com/science/article/pii/037026938890723X