Short answer
Hoping for a son, or for a daughter, is not a sin, and prophets asked Allah for children. What the Quran condemns is grieving at the birth of a girl, treating daughters as less, or blaming the mother. Allah gives daughters to whom He wills and sons to whom He wills, and raising daughters well is a path to Paradise.
Wishing or making dua for a child of a particular sex is permissible. Disliking a daughter's birth, preferring sons over daughters in treatment or gifts, or blaming the wife for the child's sex is sinful.
The four schools agree on this.
Explanation
Zakariyya prayed for a good child and an heir, and Ibrahim asked for a righteous child. So hoping for a son is human and allowed. But the Quran describes the people of ignorance: when told a girl was born, a man's face darkened, he hid from people and wondered whether to keep her in shame or bury her. Allah says: evil is what they decide.
Allah decides, not the mother. Allah says He gives daughters to whom He wills and sons to whom He wills, or both, and makes some childless. Blaming a wife for having girls is unjust in faith, and also wrong in fact, since it is the father's contribution that decides the baby's sex.
The reward of daughters: the Prophet ﷺ said that whoever raises two girls until they come of age will be with him on the Day of Judgement like two joined fingers. He loved his daughter Fatimah openly and stood to greet her. See the reward for raising daughters.
In practice:
- Make dua for righteous children, and accept what comes with gratitude.
- Celebrate a girl's birth exactly as you would a boy's: the same joy, the same newborn sunnahs.
- Treat sons and daughters equally in gifts and love; see favourite children.
- For choosing a baby's sex by medical means, see IVF gender selection.
The evidence
Quran, Surah An-Nahl 16:58-59
وَإِذَا بُشِّرَ أَحَدُهُم بِٱلْأُنثَىٰ ظَلَّ وَجْهُهُۥ مُسْوَدًّۭا وَهُوَ كَظِيمٌۭ ﴿٥٨﴾ يَتَوَٰرَىٰ مِنَ ٱلْقَوْمِ مِن سُوٓءِ مَا بُشِّرَ بِهِۦٓ ۚ أَيُمْسِكُهُۥ عَلَىٰ هُونٍ أَمْ يَدُسُّهُۥ فِى ٱلتُّرَابِ ۗ أَلَا سَآءَ مَا يَحْكُمُونَ ﴿٥٩﴾
And when one of them is informed of [the birth of] a female, his face becomes dark, and he suppresses grief. He hides himself from the people because of the ill of which he has been informed. Should he keep it in humiliation or bury it in the ground? Unquestionably, evil is what they decide.
Grieving at a daughter's birth is condemned.
Quran, Surah Ash-Shura 42:49-50
لِّلَّهِ مُلْكُ ٱلسَّمَٰوَٰتِ وَٱلْأَرْضِ ۚ يَخْلُقُ مَا يَشَآءُ ۚ يَهَبُ لِمَن يَشَآءُ إِنَٰثًۭا وَيَهَبُ لِمَن يَشَآءُ ٱلذُّكُورَ ﴿٤٩﴾ أَوْ يُزَوِّجُهُمْ ذُكْرَانًۭا وَإِنَٰثًۭا ۖ وَيَجْعَلُ مَن يَشَآءُ عَقِيمًا ۚ إِنَّهُۥ عَلِيمٌۭ قَدِيرٌۭ ﴿٥٠﴾
To Allah belongs the dominion of the heavens and the earth; He creates what he wills. He gives to whom He wills female [children], and He gives to whom He wills males. Or He makes them [both] males and females, and He renders whom He wills barren. Indeed, He is Knowing and Competent.
The child's sex is Allah's decision.
Quran, Surah Aal-i-Imraan 3:38
هُنَالِكَ دَعَا زَكَرِيَّا رَبَّهُۥ ۖ قَالَ رَبِّ هَبْ لِى مِن لَّدُنكَ ذُرِّيَّةًۭ طَيِّبَةً ۖ إِنَّكَ سَمِيعُ ٱلدُّعَآءِ ﴿٣٨﴾
At that, Zechariah called upon his Lord, saying, "My Lord, grant me from Yourself a good offspring. Indeed, You are the Hearer of supplication."
Asking Allah for children is the way of the prophets.
Sahih Muslim 2631
Sahih... من عال جاريتين حتى تبلغا ...
"Whoever raises two girls until they reach adulthood..."
The great reward for raising daughters.
Where the ruling is recorded
- al-Fatawa al-Hindiyya, Kitab al-Hiba, chapter on gifts to children. Sons and daughters are given equally in lifetime gifts.
- Ahkam al-Quran (al-Jassas), Commentary on Surat al-Nahl, ayahs 58 and 59. A Hanafi explanation of the condemnation of disliking daughters.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.