The imaginary part of the dielectric function of wurtzite AlN and GaN has been calculated in the long wavelength limit, using two different first-principle electronic structure methods. The first method is a full-potential linearized augmented plane wave method and the second is a full-potential linear muffin-tin orbital method. From the Kramers–Kronig dispersion relations the real part of the dielectric function has been obtained, taking into account a quasi-particle band-gap correction according to Bechstedt and Del Sole. Absorption due to optical phonons is treated as a delta function in the imaginary part of the dielectric function. Both the longitudinal as well as the transverse components of the dielectric function are presented, showing that the anisotropy is small in these materials. Although we use different correlation potentials in the two methods, the results are similar. We compare our calculated dielectric functions with spectroscopic ellipsometry and reflectance spectra measurements.