In this study, the imidazolium π–π stacking of two water miscible imidazolium ionic liquids (ILs) in the TiO 2 matrix formed during the sol–gel polymerization was studied by FT-IR, XRD, TEM and BET measurements. It was found that the mesoporous morphology, including surface area, average pore size and wormhole-like structure, and thermal stability of the as-prepared TiO 2 particle were varied with the imidazolium chain length and content of the IL used due to different extent of imidazolium π–π stacking. Besides, the wormhole-like mesoporous anatase TiO 2 particles with high surface area exhibited higher photodegradation efficiencies of methylene blue (MB) under 1h UV irradiation, while those with large pore size used for the electrode materials showed higher efficiency in dye-sensitized solar cells.