We formulate a theory of thermal expansion based on the self-consistent phonon (SCP) theory, which nonperturbatively considers the anharmonic effect. We show that the Grüneisen formula holds within the SCP theory by replacing the phonon frequency by the SCP frequency. By comparing it with the quasiharmonic approximation (QHA), we derive explicit formulas of the correction to the QHA result. We show that the phonon anharmonicity gives a small correction of O(〈Û4〉/〈Û2〉) to the thermal expansion coefficient $α$, where Û2 and Û4 are the harmonic and the quartic terms of the potential energy surface. On the other hand, we show that the phonon anharmonicity gives two correction terms to the temperature (T)-dependent phonon frequency shift which are comparable to the original QHA term. In strongly anharmonic materials such as NaCl and MgO, these two correction terms tend to cancel out each other, which explains why QHA sometimes gives reasonable values for the T-dependent phonon frequency shift while it fails for thermal expansion.