In vivo B(0) inhomogeneity in the rat brain at 11.7 Tesla was measured and decomposed up to the fourth-order spherical harmonic terms using an automatic slice shimming routine derived from the FLATNESS method. In vivo shimming of horizontal slices showed that significant improvement in the T(2)*-weighted echo-planar imaging was achieved after correction of all first-, second- and third-order in-slice shims. For localized proton spectroscopy, reproducible, high quality data were obtained after correcting all first- and second-order shims. The measured high-order in vivo B(0) inhomogeneity in terms of spherical harmonic terms should provide a useful guide for designing shims to meet in vivo requirements.