Short answer
In the Hanafi school the janazah is best prayed in an open space or a hall set apart for it, and praying it inside the main mosque without need is disliked. It can be prayed at home, in a funeral home, or in a clear area of the cemetery. The Shafi'i and Hanbali schools have no objection to praying it inside the mosque.
Praying the janazah inside a congregational mosque is makruh, and the stronger view in the school calls it makruh tahrimi, unless there is an excuse such as rain, cold or lack of space. Any clean place is valid, such as a courtyard, hall, home or a cleared area of the cemetery.
Other madhhabs
- Shafi'i
- Praying the janazah inside the mosque is allowed without dislike, and some call it better.
- Hanbali
- Allowed inside the mosque without dislike, as long as there is no fear of soiling it.
- Maliki
- Bringing the body into the mosque is disliked, close to the Hanafi view.
Explanation
In Madinah there was a place set aside beside the mosque for funeral prayers, and the janazah was usually prayed there. When Aisha asked for the body of Sa'd ibn Abi Waqqas to be brought into the mosque so she could pray over him, people objected that funerals were not taken into the mosque. She replied that the Prophet ﷺ had prayed over Suhayl ibn Bayda inside it. The schools weigh these reports differently.
The Hanafi view. Since the usual practice was the funeral place, Hanafi scholars dislike praying inside the main prayer hall without need. Many mosques in the UK, US and Canada have a separate janazah area, a courtyard or a car park space for this reason. With an excuse, such as heavy rain or snow, or no other space, it is fine inside.
- At home: valid if there is room for rows and the place is clean. This also lets the women of the family pray.
- At a funeral home or hall: valid.
- At the cemetery: valid in a clear area set apart from graves; many cemeteries have one. Do not pray with a grave directly in front of you.
- On a public road or someone's land: avoid praying on a road, or on private land without permission.
Wherever it is held, the body is placed in front of the imam, with men's rows behind him and women's rows behind the men. The prayer is the same in every place; see how to pray janazah. If your mosque only has the main hall, or follows another school, do not argue: the prayer is valid in every case. For a person buried without a janazah, see janazah in absentia.
The evidence
Sahih al-Bukhari 1329
Sahih... قريبا من موضع الجنائز عند المسجد ...
"The two were stoned near the place of funerals by the mosque."
There was a set place for funeral prayers beside the Prophet's ﷺ mosque.
Sahih Muslim 973
Sahih... ما صلى رسول الله صلى الله عليه وسلم على سهيل ابن بيضاء إلا في جوف المسجد ...
"The Messenger of Allah prayed over Suhayl ibn Bayda only inside the mosque."
Aisha's reply is the evidence of the schools that allow it in the mosque; the people's objection shows it was not the usual practice.
Sahih Muslim 972
Sahih... لا تجلسوا على القبور ولا تصلوا إليها ...
"Do not sit on graves and do not pray toward them."
In a cemetery, the prayer is held where no grave is in front.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Salah, Bab Salat al-Janazah. The dislike of the janazah inside the congregational mosque and the two views on its degree.
- al-Fatawa al-Hindiyya, Kitab al-Salah, chapter on the jana'iz. Praying the janazah on a road or on others' land.
- al-Majmu' (Nawawi), Kitab al-Jana'iz. The Shafi'i permission to pray it in the mosque.
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.