The electronic structures and optical properties of pure, N-doped and N-F codoped ZnO are investigated based on the density-functional theory. The calculations of the impurity formation energies and ionization energies for these systems indicate that incorporating the reactive donor F into N doped ZnO systems, not only enhances the N acceptor solubility, but also leads to a shallower N acceptor energy level in the band gap in p-type codoped ZnO. In addition, we analyze the imaginary part of the dielectric functions, and reflectivities for pure and N-F codoped ZnO. Compared with the pure ZnO, the remarkable feature in the dielectric function for N-F codoped ZnO is that there is a sharp peak in the low-energy region.