This paper investigated the treatment of textile wastewater polluted with aniline blue (AB) by electrocoagulation process using stainless steel mesh electrodes with a horizontal arrangement. The experimental design involved the application of the response surface methodology (RSM) to find the mathematical model, by adjusting the current density (4-20 mA/cm2), distance between electrodes (0.5-3 cm), salt concentration (50-600 mg/l), initial dye concentration (50-250 mg/l), pH value (2-12 ) and experimental time (5-20 min). The results showed that time is the most important parameter affecting the performance of the electrocoagulation system. Maximum removal efficiency (96 %) was obtained at a current density of 20 mA/cm2, distance between electrodes of 1.75 cm, salt concentration of 462.5 mg/l, dye concentration of 50 ppm, pH value of 7, and time duration of 15 min. On the other hand, the electrocoagulation efficiency was directly proportional to current density, salt concentration, and contact time, while it was inversely proportional to dye concentration. Isotherm experiments showed that the equilibrium data are best fitted to Freundlich isotherm and sips isotherm; whereas the kinetics results showed that the rate of adsorption followed the pseudo-second-order with an R2 value of 98 %.