The opal photonic crystals made of polystyrene microspheres with 155, 230, 270 or 410 nm in diameter were used to enhance upconversion (UC) emission of YF3:Yb3+, Er3+ nanoparticles, respectively. The red or green UC emission of YF3:Yb3+, Er3+ nanoparticles can be selectively enhanced when the red or green UC emission wavelength overlapped with the photonic bandgaps of opals, which is attributed to Bragg reflection of photonic bandgap. In addition, when the 980 nm excitation light wavelength was in the region of the photonic bandgap, red and green UC emissions of YF3:Yb3+, Er3+ nanoparticles were enhanced due to the enhancement of excitation field.