A handheld electronic device having an antibacterial mechanism is provided. The handheld electronic device includes a main body, a display panel and a processing module. The display panel is disposed at a first surface of the main body and includes a plurality of display light sources and at least one antibacterial light source. The display light sources generate a display light. The antibacterial light source generates an antibacterial light. The processing module is coupled to the display light sources and the antibacterial light source. The processing module is operated to activate the display light sources to generate the display light during a display period and to activate the antibacterial light source to generate the antibacterial light during an antibacterial period.