He was born in Vienna, the eldest son of Emperor Ferdinand III and his first wife, Infanta Maria Anna of Spain (daughter of King Philip III of Spain). He was made King of Bohemia in 1646, King of Hungary in 1647, and was elected King of the Romans (future ruler of the Holy Roman Empire) on May 31, 1653, and crowned at Ratisbon (Regensburg) on June 18 of the same year. He died in Vienna, predeceasing his father, leaving his younger brother, the future Leopold I, Holy Roman Emperor, as heir.