Cavalry became obsolete with the widespread adoption of cartridge rifles.
Horses remained valuable for transport through WWI, and were used extensively through WWII by Germany and others.
But as a fighting force, cartridge rifles made horse cavalry obsolete, as the cavalry charge became a suicide mission.