Nitrogen and oxygen co-doped hierarchical micro-mesoporous carbon foams has been synthesized by pyrolyzation treatment of a preliminary foam containing melamine and formaldehyde as nitrogen, carbon and oxygen precursors and Zn(NO3)2. 6H2O and pluronic F127 as micro-meso pores generators. Several characterizations including thermal gravimetric analysis (TGA), X-ray diffraction (XRD) and Raman spectroscopy, FTIR and X-ray photoelectron spectroscopy, N2 adsorption–desorption, field emission scanning electron microscopy (FE-SEM) and transmission electron microscopy (TEM) were performed on the prepared foams. X-ray diffraction patterns, Raman spectra and N2 adsorption–desorption results confirmed that ZnO has pronounced effect on the graphitization of the prepared carbon foam. From X-ray diffraction, thermal gravimetric and N2 adsorption–desorption analysis results it was confirmed that the carbothermal reaction and the elimination of ZnO and also the elimination of pluronic F127 are the main factors for the induction of porosities in the foam structure. The presence of Zn(NO3)2. 6H2O and pluronic F127 in the initial composition of the preliminary foam results in the specific surface area as high as 1176 m2.g−1 and pore volume of 0.68 cm3.g−1. X-ray photoelectron and FTIR spectroscopy analyses results approved the presence of nitrogen (about 1.9 at %) in the form of pyridinic, graphitic and nitrogen oxide and oxygen (about 7.5 at. %) functional groups on the surface of the synthesized carbon foam. Electrochemistry analysis results including cyclic voltammetry (CV) and galvanostatic charge–discharge (GCD) and also electrochemical impedance spectroscopy (EIS) analysis illustrated the formation of an electric double layer supercapacitor with the capacitance as high as 137 Fg−1.