Short answer
Free mixing, meaning men and women socialising without the limits of hijab, lowered gaze and real need, is not allowed. Being in the same place for a need, such as work, study, shopping or the mosque, is allowed when those limits are kept and no man and woman are alone together. The four schools agree in principle.
Khalwah, a non-mahram man and woman alone where no one else can enter, is haram. Mixing that involves uncovered awrah, flirting, touching or casual socialising is haram. Sharing a space for a genuine need, with proper dress and decent conduct, is permitted, though separation is better wherever it is possible.
The four schools agree on this.
Explanation
Two separate things are often confused. Khalwah is a man and a non-mahram woman being alone together in a closed room, a car or a house; the Prophet ﷺ forbade it outright. Ikhtilat (mixing) is men and women being in the same space with others around. Mixing is judged by its purpose and its conduct.
In the time of the Prophet ﷺ women came to the mosque, the market and the battlefield, yet with clear limits. Women prayed in rows behind the men and left first. They asked him for a separate day for their lessons because the men crowded them out. He told women to keep to the sides of the road rather than walk in the middle among men. The Quran told the Companions to speak to his wives from behind a screen, because that is purer for both hearts.
How this applies today:
- Work and university: allowed with hijab, lowered gaze and professional conduct. Avoid one-to-one closed meetings and social outings with colleagues of the other sex.
- Family gatherings: cousins and in-laws such as a husband's brother are not mahram. Mixed sitting and joking with them falls under the same limits.
- Weddings and parties: separate seating is the Islamic norm, and mixed dancing is not allowed.
- Group chats and online: the same rules apply. See talking to a non-mahram online.
The aim is not to keep women out of public life but to protect hearts and marriages. For who is and is not a mahram, see who is a mahram, and for working women see can women work.
The evidence
Quran, Surah An-Noor 24:30
قُل لِّلْمُؤْمِنِينَ يَغُضُّوا۟ مِنْ أَبْصَٰرِهِمْ وَيَحْفَظُوا۟ فُرُوجَهُمْ ۚ ذَٰلِكَ أَزْكَىٰ لَهُمْ ۗ إِنَّ ٱللَّهَ خَبِيرٌۢ بِمَا يَصْنَعُونَ ﴿٣٠﴾
Tell the believing men to reduce [some] of their vision and guard their private parts. That is purer for them. Indeed, Allah is Acquainted with what they do.
Lowering the gaze is the first limit when men and women share a space.
Quran, Surah Al-Ahzaab 33:53
يَٰٓأَيُّهَا ٱلَّذِينَ ءَامَنُوا۟ لَا تَدْخُلُوا۟ بُيُوتَ ٱلنَّبِىِّ إِلَّآ أَن يُؤْذَنَ لَكُمْ إِلَىٰ طَعَامٍ غَيْرَ نَٰظِرِينَ إِنَىٰهُ وَلَٰكِنْ إِذَا دُعِيتُمْ فَٱدْخُلُوا۟ فَإِذَا طَعِمْتُمْ فَٱنتَشِرُوا۟ وَلَا مُسْتَـْٔنِسِينَ لِحَدِيثٍ ۚ إِنَّ ذَٰلِكُمْ كَانَ يُؤْذِى ٱلنَّبِىَّ فَيَسْتَحْىِۦ مِنكُمْ ۖ وَٱللَّهُ لَا يَسْتَحْىِۦ مِنَ ٱلْحَقِّ ۚ وَإِذَا سَأَلْتُمُوهُنَّ مَتَٰعًۭا فَسْـَٔلُوهُنَّ مِن وَرَآءِ حِجَابٍۢ ۚ ذَٰلِكُمْ أَطْهَرُ لِقُلُوبِكُمْ وَقُلُوبِهِنَّ ۚ وَمَا كَانَ لَكُمْ أَن تُؤْذُوا۟ رَسُولَ ٱللَّهِ وَلَآ أَن تَنكِحُوٓا۟ أَزْوَٰجَهُۥ مِنۢ بَعْدِهِۦٓ أَبَدًا ۚ إِنَّ ذَٰلِكُمْ كَانَ عِندَ ٱللَّهِ عَظِيمًا ﴿٥٣﴾
O you who have believed, do not enter the houses of the Prophet except when you are permitted for a meal, without awaiting its readiness. But when you are invited, then enter; and when you have eaten, disperse without seeking to remain for conversation. Indeed, that [behavior] was troubling the Prophet, and he is shy of [dismissing] you. But Allah is not shy of the truth. And when you ask [his wives] for something, ask them from behind a partition. That is purer for your hearts and their hearts. And it is not [conceivable or lawful] for you to harm the Messenger of Allah or to marry his wives after him, ever. Indeed, that would be in the sight of Allah an enormity.
A barrier between men and women is purer for the hearts of both.
Sahih al-Bukhari 5233
Sahih... لا يخلون رجل بامرأة إلا مع ذي محرم ...
"No man may be alone with a woman unless a mahram of hers is present."
Forbids khalwah with a non-mahram.
Sunan Abi Dawud 5272
Grading to be checked... استأخرن فإنه ليس لكن أن تحققن الطريق ...
"Keep back, for you should not walk in the middle of the road; keep to its sides."
Shows the Prophet ﷺ separating men and women even in public streets.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Hazr wa al-Ibaha, chapter on looking and touching. Khalwah with a non-mahram woman is haram.
- al-Fatawa al-Hindiyya, Kitab al-Karahiyya, chapter on looking and touching. The limits of looking at and dealing with non-mahram women.
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.