Abstract This work successfully developed a new green and low-cost preparation method of zeolitic imidazolate framework-8 (ZIF-8) by adding sodium hydroxide as a proton removing agent and surfactant to reduce the amount of 2-methylimidazole and the size of ZIF-8. Using surfactants cetyltrimethylammonium bromide (CTAB) and sodium dodecyl sulfate (SDS) to modify ZIF-8. The modified ZIF-8 showed selective adsorption behaviors for Rhodamine B (Rh B), methylene blue (MB), methyl orange (MO), and acid yellow 36 (AC36). ZIF-8 modified by SDS was more likely to adsorb MB and Rh B cationic dyes than ZIF-8 modified by CTAB, with removal rates of 85.3 and 90.1%, respectively. The removal rates of anionic MO and AC36 by CTAB-modified ZIF-8 were 98.7 and 80.4%, respectively. Because of the selectivity of modified ZIF-8, it can separate specific dyes from mixed dyes. Fourier transform infrared spectrometry and zeta potential analysis showed that the adsorption of dyes by modified ZIF-8 was carried out by electrostatic interaction, π–π stacking and hydrogen bonding.