The primary cause of endocarditis is usually a bacterial infection, though it can also be caused by fungi or other microorganisms. Common bacteria that cause endocarditis in children include Staphylococcus aureus and Streptococcus viridans. These bacteria can enter the bloodstream through various means, such as dental procedures, surgical interventions, or even everyday activities in children with predisposing conditions.