A new concept for anion detection in a handy, rapid, and sensitive way is described based on the combination of the unique properties of both ILs and photonic crystals. By simple counteranion exchanging of the pendant IL units, the 3D highly ordered IL porous structure can directly sense different anions and easily convert the anion detection events into readable optical signals with color changes.