A search for the exclusive decays of the Higgs and Z bosons to a ϕ or ρ meson and a photon is performed with a pp collision data sample corresponding to an integrated luminosity of up to 35.6 fb−1 collected at s=13 TeV with the ATLAS detector at the CERN Large Hadron Collider. These decays have been suggested as a probe of the Higgs boson couplings to light quarks. No significant excess of events is observed above the background, as expected from the Standard Model. Upper limits at 95% confidence level were obtained on the branching fractions of the Higgs boson decays to ϕγ and ργ of 4.8 × 10−4 and 8.8 × 10−4, respectively. The corresponding 95% confidence level upper limits for the Z boson decays are 0.9 × 10−6 and 25 × 10−6 for ϕγ and ργ, respectively.[Figure not available: see fulltext.].