Emperor Xiaozhuang of Northern Wei (Chinese: (北)魏孝莊帝, 507–531), personal name Yuan Ziyou (Chinese: 元子攸), was an emperor of China of the Northern Wei, a Xianbei dynasty. He was placed on the throne by General Erzhu Rong, who refused to recognize the young emperor, Yuan Zhao, who Empress Dowager Hu had placed on the throne after she poisoned her son Emperor Xiaoming.
During his reign, General Erzhu largely controlled the military and acted in a violent manner, leading Emperor Xiaozhuang to believe that he would usurp the throne. In 530, Emperor Xiaozhuang ambushed General Erzhu and killed him in the palace, but his cousin Erzhu Shilong and nephew Erzhu Zhao subsequently captured and killed Xiaozhuang.
Yuan Ziyou was born in 507, during the reign of his cousin Emperor Xuanwu, as the third son of the highly regarded imperial prince, Emperor Xuanwu's uncle Yuan Xie the Prince of Pengcheng. His mother was Yuan Xie's wife Princess Li Yuanhua, the daughter of the honored official Li Chong (李沖). Of his two older brothers, the oldest, Yuan Zizhi (元子直), was not Princess Li's son, and the other, born of Princess Li, was Yuan Shao (元劭).
In 508, Princess Li was again pregnant and due to give birth, when Emperor Xuanwu, believing in false accusations of his maternal uncle Gao Zhao that Yuan Xie was plotting rebellion, forced Yuan Xie to commit suicide. Princess Li soon gave birth to Yuan Ziyou's younger brother, Yuan Zizheng (元子正). It appeared that Yuan Ziyou was close to his brothers. Yuan Shao, as the oldest son of Yuan Xie's wife, inherited Yuan Xie's title of Prince of Pengcheng. Yuan Ziyou and his brothers Yuan Zizhi and Yuan Zizheng were created dukes—in Yuan Ziyou's case, the Duke of Wucheng. Yuan Ziyou, in his youth, served as an attendant to Emperor Xuanwu, and was praised for his intelligence and handsome looks. He held increasingly higher offices during the reigns of Emperor Xuanwu and his son and successor Emperor Xiaoming.