In this work, two indazole derivatives, namely 5-aminoindazole (AIA) and 5-nitroindazole (NIA), were investigated as corrosion inhibitors for carbon steel in 1 M HCl solution by experimental and density functional theory (DFT) methods. The electrochemical results indicate that the inhibition ability follows the order of AIA > NIA, which is due to the stronger electron-donating effect of –NH2 of the AIA group than the –NO2 group of NIA. Besides, the frontier orbital theory shows that the AIA exhibits higher reaction activity than NIA, and a more negative adsorption energy for AIA was also obtained, which is consistent with the analysis of the electrochemical measurements. We draw the conclusion that the electron-donating effect makes it easier for AIA to donate electrons to iron atoms to form a stronger protective layer than NIA.