It does not always match. DFT using GGA-PBE underestimates band-gap in many cases. But, hybrid functionals like HSE06 provides much more accurate result.
Another thing to remember is, for many materials, optical band-gap does not match with the electronic band-gap for multifaceted reasons. So, detailed understanding of the particular material is necessary before dropping a conclusion.