Born in Toledo, Kingdom of Castile, Alfonso was the eldest son of Ferdinand III and Elizabeth (Beatrice) of Swabia. His mother was the paternal cousin of Holy Roman Emperor Frederick II, to whom Alfonso is often compared. His maternal grandparents were Philip of Swabia and Irene Angelina. Little is known about his upbringing, but he was most likely raised in Toledo. For the first nine years of his life Alfonso was only heir to Castile until his paternal grandfather king Alfonso IX of León died and his father united the kingdoms of Castile and León. He began his career as a soldier, under the command of his father, when he was only sixteen years old.