The detection of p-nitrophenol (PNP) is of great significance for assessment of environment pollution and potential health risks. In this study, based on inverse opal polymeric photonic crystals (IOPPCs), a selective and visual sensor for high-performance PNP detection is developed. Due to their unique optical properties, IOPPCs report events by change of color, which can easily be observed by the naked eye. Hydroxyethyl methacrylate (HEMA) was selected as the functional monomer with which to fabricate the IOPPCs. By precisely adjusting the molar ratio between the functional monomer and the crosslinker, the sensors were only able to be sensitive to a specific solution, thus realizing the visual, selective, and semi-quantitative detection of PNP. When the sensors were immersed in different concentrations of PNP solution, their Bragg diffraction wavelengths showed different redshifts. The color of the IOPPCs changed from green to red as the peak shift of Bragg diffraction occurred. In addition, the IOPPCs displayed good interference immunity and reusability.