Short answer
Yes, with care. The Prophet ﷺ let children into his mosque and shortened his prayer when he heard a baby cry. In the Hanafi school bringing children who understand and behave is good, but bringing very young children who are likely to soil the mosque is forbidden, and disturbing worshippers is disliked.
Bringing children of understanding (about seven and above) to learn prayer is encouraged. Bringing infants or very young children is haram where it is likely they will make the mosque impure, and makruh otherwise, because of disturbance. Parents must supervise them.
The four schools agree on this.
Explanation
The Prophet ﷺ led prayer carrying his granddaughter Umamah, let his grandson ride on his back in sujud rather than hurry him, came down from the minbar to pick up al-Hasan and al-Husayn, and said he would shorten his prayer when he heard a baby cry, knowing the mother's distress. So children were present in his mosque. A well-known report telling people to keep children away from mosques is weak, though Hanafi scholars apply its meaning to very young or unsupervised children.
The Hanafi balance:
- Children of about seven and up: bring them, teach them, and let them pray with you. This is how they come to love the mosque.
- Toddlers and babies: the main concern is impurity and disturbance. With nappies, close supervision and a quiet area, many scholars today allow it, especially for mothers at the women's section or for short visits.
- Not allowed: leaving children to run, shout or play games during prayer, or bringing a child who will likely soil the carpets.
For the community: be patient with children and their parents. Shouting at a child in the mosque can push a family away for years. Mosques do well to offer a family room or a crèche. On where children stand, see children in the prayer rows. For women attending, see women in the mosque, and teach the dua for entering the mosque.
The evidence
Quran, Surah At-Taghaabun 64:15
إِنَّمَآ أَمْوَٰلُكُمْ وَأَوْلَٰدُكُمْ فِتْنَةٌۭ ۚ وَٱللَّهُ عِندَهُۥٓ أَجْرٌ عَظِيمٌۭ ﴿١٥﴾
Your wealth and your children are but a trial, and Allah has with Him a great reward.
The ayah the Prophet recited when he came down from the minbar to pick up his grandsons.
Sahih al-Bukhari 709
Sahih... إني لأدخل في الصلاة وأنا أريد إطالتها فأسمع بكاء الصبي ...
"I begin the prayer intending to make it long, then I hear a child crying, so I shorten my prayer."
Babies were present in the Prophet's mosque.
Sahih al-Bukhari 516
Sahih... وهو حامل أمامة بنت زينب ...
"He prayed while carrying Umamah, the daughter of Zaynab."
The Prophet carried a small child in prayer.
Sunan an-Nasa'i 1141
Grading to be checked... إن ابني ارتحلني فكرهت أن أعجله ...
"My son was riding on my back, and I did not want to hurry him."
Gentleness with children during prayer.
Sunan Abi Dawud 1109
Grading to be checked... صدق الله إنما أموالكم وأولادكم فتنة ...
"Allah spoke the truth: your wealth and your children are a trial."
He interrupted his sermon to pick up his grandsons.
Where the ruling is recorded
- al-Durr al-Mukhtar, Kitab al-Salah, chapter on what invalidates the prayer and what is disliked in it, section on the mosque. Bringing children into the mosque is haram where impurity is likely, and makruh otherwise.
- Radd al-Muhtar (Ibn Abidin), Kitab al-Salah, same chapter. Explains the ruling and the weak hadith behind it.
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.