Short answer
Only for a real need. In the Hanafi school, a man in itikaf may leave the masjid to use the toilet, make wudu or an obligatory ghusl, fetch food if no one can bring it, and attend Jumuah if it is not held there. Leaving for anything else, even briefly, ends the sunnah itikaf of the last ten days, which is then made up for one day.
During the sunnah itikaf of the last ten days of Ramadan (sunnah mu'akkadah kifayah), leaving the masjid is allowed only for natural needs, such as the toilet, wudu, obligatory ghusl and bringing food when no one else can, and religious needs such as Jumuah. Leaving without such a need, even for a moment, ends the sunnah itikaf; what remains counts as voluntary itikaf, and one day of itikaf with fasting is made up later.
Other madhhabs
- Shafi'i
- If you set a condition when starting itikaf, such as visiting the sick or attending a funeral, you may go out for it.
- Hanbali
- A condition made at the start, for example to visit the sick or attend a janazah, permits going out for it.
Explanation
The Prophet ﷺ observed itikaf (spiritual retreat in the masjid) in the last ten days of Ramadan every year until he passed away. Aisha said that during itikaf he would not enter the house except for a human need. The point of itikaf is to stay in the masjid, so leaving it is limited to what cannot be avoided.
Allowed:
- Going to the toilet, and making wudu if there is no place inside the masjid.
- Ghusl after a wet dream.
- Fetching food or drink if no one can bring it to you.
- Going to Jumuah if the masjid does not hold it, leaving in good time.
Not allowed: visiting the sick, attending a janazah, going to work, shopping, a shower just to cool down, or standing outside to chat. If you pass a sick person on the way to the toilet, you may greet them and ask after them without stopping. Phone calls, reading and quiet conversation inside the masjid are fine, though itikaf is best spent in prayer, Quran and dhikr.
Women in the Hanafi school observe itikaf in the place set aside for prayer in their home. For how to begin, the times and what to bring, see itikaf in Ramadan, and for the nights themselves, see Laylatul Qadr.
The evidence
Quran, Surah Al-Baqara 2:187
أُحِلَّ لَكُمْ لَيْلَةَ ٱلصِّيَامِ ٱلرَّفَثُ إِلَىٰ نِسَآئِكُمْ ۚ هُنَّ لِبَاسٌۭ لَّكُمْ وَأَنتُمْ لِبَاسٌۭ لَّهُنَّ ۗ عَلِمَ ٱللَّهُ أَنَّكُمْ كُنتُمْ تَخْتَانُونَ أَنفُسَكُمْ فَتَابَ عَلَيْكُمْ وَعَفَا عَنكُمْ ۖ فَٱلْـَٰٔنَ بَٰشِرُوهُنَّ وَٱبْتَغُوا۟ مَا كَتَبَ ٱللَّهُ لَكُمْ ۚ وَكُلُوا۟ وَٱشْرَبُوا۟ حَتَّىٰ يَتَبَيَّنَ لَكُمُ ٱلْخَيْطُ ٱلْأَبْيَضُ مِنَ ٱلْخَيْطِ ٱلْأَسْوَدِ مِنَ ٱلْفَجْرِ ۖ ثُمَّ أَتِمُّوا۟ ٱلصِّيَامَ إِلَى ٱلَّيْلِ ۚ وَلَا تُبَٰشِرُوهُنَّ وَأَنتُمْ عَٰكِفُونَ فِى ٱلْمَسَٰجِدِ ۗ تِلْكَ حُدُودُ ٱللَّهِ فَلَا تَقْرَبُوهَا ۗ كَذَٰلِكَ يُبَيِّنُ ٱللَّهُ ءَايَٰتِهِۦ لِلنَّاسِ لَعَلَّهُمْ يَتَّقُونَ ﴿١٨٧﴾
It has been made permissible for you the night preceding fasting to go to your wives [for sexual relations]. They are clothing for you and you are clothing for them. Allah knows that you used to deceive yourselves, so He accepted your repentance and forgave you. So now, have relations with them and seek that which Allah has decreed for you. And eat and drink until the white thread of dawn becomes distinct to you from the black thread [of night]. Then complete the fast until the sunset. And do not have relations with them as long as you are staying for worship in the mosques. These are the limits [set by] Allah, so do not approach them. Thus does Allah make clear His ordinances to the people that they may become righteous.
Itikaf is staying in the masjid for worship, with its own limits.
Sahih al-Bukhari 2029
Sahih... وكان لا يدخل البيت إلا لحاجة إذا كان معتكفا ...
"When he was in itikaf, he would not enter the house except for a need."
Leaving the masjid during itikaf is limited to real needs.
Sahih al-Bukhari 2026
Sahih... يعتكف العشر الأواخر من رمضان حتى توفاه الله ...
"He would observe itikaf in the last ten days of Ramadan until Allah took him."
Itikaf in the last ten days is an established sunnah.
Where the ruling is recorded
- al-Hidaya, Kitab al-Sawm, chapter on itikaf. The person in itikaf does not leave the masjid except for a human need or Jumuah.
- Radd al-Muhtar (Ibn Abidin), Kitab al-Sawm, chapter on itikaf. Leaving without need breaks the sunnah itikaf, and the day is made up.
- al-Majmu' (Nawawi), Kitab al-I'tikaf. The Shafi'i rule that a condition made at the start permits specified outings.
This answer is pending review by the scholars on our team. 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.