The Prophet ﷺ said, "Allah has appointed an angel over the womb. The angel says, 'My Lord, a drop of fluid. My Lord, a clinging clot. My Lord, a lump of flesh.' Then, when Allah wills to complete its creation, the angel asks, 'Male or female? Wretched or blessed? What provision? What term of life?' All of this is then written while the child is still in its mother's womb."
عن النبي ﷺ قال: إن الله عز وجل وكل بالرحم ملكا يقول: يا رب نطفة، يا رب علقة، يا رب مضغة. فإذا أراد أن يقضى خلقه قال: أذكر أم أنثى؟ شقي أم سعيد؟ فما الرزق والأجل؟ فيكتب في بطن أمه.