We report on the determination of astrometric, spin and orbital parameters for PSR J1518+0204C, a black widow binary millisecond pulsar in the globular cluster M5. The accurate position and orbital parameters obtained from radio timing allowed us to search for the optical companion. By using WFC3/HST images we identified a very faint variable star (m_F390W > 24.8, m_F606W > 24.3, m_F814W > 23.1) located at only 0.25 from the pulsars timing position. Due to its strong variability, this star is visible only in a sub-sample of images. However, the light curve obtained folding the available data with the orbital parameters of the pulsar shows a maximum at the pulsar inferior conjunction and a possible minimum at the pulsar superior conjunction. Furthermore, the shape of the optical modulation indicates a heating process possibly due to the pulsar wind. This is the first identification of an optical companion to a black widow pulsar in the dense stellar environment of a globular cluster.