Short answer
Talking for a real need, such as work, study, buying and selling, or a serious marriage enquiry with family involved, is allowed if it stays decent and to the point. Casual chatting, flirting, private DMs, late-night calls and voice notes with a non-mahram are not allowed. The rule is the same online and offline, and the four schools agree.
Speaking with a non-mahram is permitted when there is a need and the conversation is decent. Talk that is soft, flirtatious, private for its own sake or driven by attraction is haram, as it leads to zina of the eyes, tongue and heart.
The four schools agree on this.
Explanation
Women spoke with the Prophet ﷺ and the Companions about their questions, their trade and their rights, so speaking to the opposite sex is not haram in itself. The Quran sets the manner: do not be soft in speech so that someone with a disease in his heart is tempted, and speak in a proper way. He also said that the eyes commit zina by looking and the tongue by speaking, and the heart wishes and desires.
Online chat makes this harder, because it feels private, it never ends, and no one else is in the room. That is why scholars treat one-to-one private messaging between a young man and woman like a form of khalwah.
- Allowed: work emails and team chats, class group discussions, customer service, asking a question of a teacher, a marriage enquiry through or with family.
- Not allowed: chatting for fun, compliments, sharing photos of yourself, "good morning" messages, video calls with no need, and talking late at night.
- Gaming and social media: the same rules apply in comments, DMs and voice chat.
- Is it haram to talk to a girl? A man asking a female classmate about an assignment is fine. Messaging her every day because he likes her is the start of what Islam forbids.
A simple test: would you be comfortable if your parents or your spouse read the conversation? If not, stop. See having a girlfriend or boyfriend, talking to your fiancé and is a woman's voice awrah.
The evidence
Quran, Surah Al-Ahzaab 33:32
يَٰنِسَآءَ ٱلنَّبِىِّ لَسْتُنَّ كَأَحَدٍۢ مِّنَ ٱلنِّسَآءِ ۚ إِنِ ٱتَّقَيْتُنَّ فَلَا تَخْضَعْنَ بِٱلْقَوْلِ فَيَطْمَعَ ٱلَّذِى فِى قَلْبِهِۦ مَرَضٌۭ وَقُلْنَ قَوْلًۭا مَّعْرُوفًۭا ﴿٣٢﴾
O wives of the Prophet, you are not like anyone among women. If you fear Allah, then do not be soft in speech [to men], lest he in whose heart is disease should covet, but speak with appropriate speech.
Speech with non-mahrams should be proper and not soft or inviting.
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.
Guarding the gaze applies to photos and video too.
Sahih al-Bukhari 6243
Sahih... فزنا العين النظر وزنا اللسان المنطق ...
"The zina of the eye is looking, and the zina of the tongue is speech."
Flirtatious talk is a step towards zina.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Hazr wa al-Ibaha, chapter on looking and touching. Speaking with a non-mahram woman is allowed for need and without fear of fitnah.
- al-Fatawa al-Hindiyya, Kitab al-Karahiyya. Greeting and conversing with a young non-mahram woman is avoided where there is fear of temptation.
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.