The present invention provides a gas generator and comprises an electrolytic cell and a water-blocking device. The electrolytic cell is used for electrolyzing electrolyzed water to generate a gas with hydrogen. The electrolytic cell has an outlet for outputting the gas with hydrogen. The water-blocking device is set on the outlet for preventing the electrolyzed water from flowing out when the electrolytic cell is tilted by a tilt angle. The gas pathway of the invention will be closed by the water-blocking device when the gas generator is toppled, thereby preventing the electrolyte-rich electrolyzed water from flowing out.