Margaret was the daughter of the English prince Edward the Exile, and granddaughter of Edmund Ironside, King of England. After the Danish conquest of England in 1016, King Canute the Great had the infant Edward exiled to the continent. He was taken first to the court of the Swedish king, Olof Skötkonung, and then to Kiev. As an adult, he travelled to Hungary, where in 1046 he supported the successful bid of King Andrew I for the Hungarian crown. King Andrew I was then also known as "Andrew the Catholic" for his extreme aversion to pagans and great loyalty to the Roman Catholic Church. The provenance of Margaret's mother, Agatha, is disputed, but Margaret was born in Hungary c. 1045. Her brother Edgar the Ætheling and sister Cristina were also born in Hungary around this time. Margaret grew up in a very religious environment in the Hungarian court.