The diffuse extragalactic background light (EBL) is formed by ultraviolet (UV), optical, and infrared (IR) photons mainly produced by star formation processes over the history of the Universe, and contains essential information about galaxy evolution and cosmology. In this talk, we present a new determination of the evolving EBL spectral energy distribution using a novel approach purely based on galaxy data aiming to reduce current uncertainties on the higher redshifts and IR intensities. Our calculations use multiwavelength observations from the UV to the far-IR of a sample of approximately 150,000 galaxies detected up to z~6 in the five fields of the Cosmic Assembly Near-Infrared Deep Extragalactic Legacy Survey (CANDELS) from the Hubble Space Telescope. This is one of the most comprehensive and deepest multi-wavelength galaxy datasets ever obtained. These unprecedented resources allow us to derive the overall EBL evolution up to z~6 and its uncertainties. Our results agree with cosmic observables estimated from galaxy surveys and gamma-ray attenuation such as monochromatic luminosity densities, including those in the far-IR, and star formation rate densities, also at the highest redshifts. We will also discuss the gamma-ray optical depths that are derived from our EBL approximation and how we can measure the expansion of the Universe using very high energy observations of blazars with Fermi-LAT and imaging atmospheric Cherenkov telescopes.