Narrated `Abdullah
Allah's Messenger (ﷺ), the truthful and truly-inspired, said, "Each one of you collected in the womb of his mother for forty days, and then turns into a clot for an equal period (of forty days) and turns into a piece of flesh for a similar period (of forty days) and then Allah sends an angel and orders him to write four things, i.e., his provision, his age, and whether he will be of the wretched or the blessed (in the Hereafter). Then the soul is breathed into him. And by Allah, a person among you (or a man) may do deeds of the people of the Fire till there is only a cubit or an arm-breadth distance between him and the Fire, but then that writing (which Allah has ordered the angel to write) precedes, and he does the deeds of the people of Paradise and enters it; and a man may do the deeds of the people of Paradise till there is only a cubit or two between him and Paradise, and then that writing precedes and he does the deeds of the people of the Fire and enters it."
Narrated Anas bin Malik
The Prophet (ﷺ) said, "Allah puts an angel in charge of the uterus and the angel says, 'O Lord, (it is) semen! O Lord, (it is now ) a clot! O Lord, (it is now) a piece of flesh.' And then, if Allah wishes to complete its creation, the angel asks, 'O Lord, (will it be) a male or a female? A wretched (an evil doer) or a blessed (doer of good)? How much will his provisions be? What will his age be?' So all that is written while the creature is still in the mother's womb."