Assalamualaikum ustaz. I have a question. Is it permissible to offer salam to a person of the opposite gender, for instance, a salam from a student to a teacher or for one’s colleagues? Thank you.
Waalaikumussalam wrt. wbt.,
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions, and all those who follow his footsteps until the Final day.
We begin with the statement of Allah SWT:
فَإِذَا دَخَلْتُم بُيُوتًا فَسَلِّمُوا عَلَىٰ أَنفُسِكُمْ تَحِيَّةً مِّنْ عِندِ اللَّـهِ مُبَارَكَةً طَيِّبَةً
“But when you enter houses, give greetings of peace upon each other – a greeting from Allah, blessed and good.” 
The above verse means that when enters a house, whether the house has its occupants or not, then some of you should give salam to the others with the phrase (السلام عليكم ورحمة الله وبركاته) or (السلام علينا وعلى عباد الله الصالحين) if there is no one – in the house. The salam speech is sanctioned by Allah SWT and it is a blessed speech, which cultivates love and affection. Especially preferred by those who hear it. 
Ibn Juzai al-Kalbi in his commentary is of the opinion that salam isn’t limited to houses (homes) but also mosques and we are commanded to give salam to whoever is in them. If there is no one in it, then give salam to the Prophet PBUH, then angels and pious slaves of Allah SWT. 
The ruling of giving and answering salam
The original ruling of giving salam is sunnah muakkad (greatly encouraged). Whereas the ruling of answering salam is obligatory. This is stated by Imam al-Nawawi and the ruling of giving salam is sunnah muakkad and answering it is fardhu ain or obligatory according to the ijma’. If a person gives salam to another person, then the second person is obligated to answer it and it is a fardhu ain. While if the salam is given to a group of people, then answering it is fardhu kifayah. If a person from the group answers it, then the obligation on the group is fulfilled. If all of them answered it, then all of them are considered to have fulfilled a fardhu, whether they answer it at the same time or otherwise. If none of them answers it, then they are all sinful. 
Giving and answering salam to the opposite gender
Furthermore, al-Nawawi also stated that the ruling of giving and answering salam between women is the same as between men. Then, scholars of madhhab al-Syafi’i said that if a man gives salam to a woman – if they have a mahram, marriage or slavery relationship – then it is sunnah and answering it is obligatory. However, if they don’t share any of these relationships, then it isn’t obligatory to be answered, except if he is very old and it doesn’t lead to fitnah.
Then, al-Nawawi cited from al-Mutawalli who said that if a man gives salam to another young woman who is a stranger, then it is impermissible for the woman to answer it. However, if the woman is the one who gives the salam to the man, then it is makruh for the man to answer it. Likewise, if a group of women gives salam to a man or a group of men give salam to a woman, then it is sunnah if there is no concern on any parties – whether it is the lone man or lone woman or a group of women – for fitnah. 
This is based on a hadith from Asma’ binti Yazid R.Anha, she said:
مَرَّ عَلَيْنَا النَّبِيُّ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ فِي نِسْوَةٍ فَسَلَّمَ عَلَيْنَا
“The Prophet (ﷺ), passed us by when we were with some women and gave us a salutation.” 
‘Abd al-Muhsin al-‘Abbad when commenting on this hadith stated that salam to a woman if she is a mahram or family member, then it is clear there is no issue in it. However, if the woman is a stranger – which means not a mahram nor a family member – then it is impermissible to give salam to her except if it is safe from fitnah.
In other words, if the act of giving the salam then it wouldn’t lead to fitnah, or the woman is with her family and the salam is given to all, or she is elderly that it will not lead to fitnah and it is on the condition that it must be safe from fitnah and there is nothing that is prohibited, then as long as it is safe from fitnah, it is permissible to give salam. He also stated that if there is a possibility of fitnah or harm, then it is impermissible for the man to give salam to the woman and vice versa even if they pass by on the road. 
There is another hadith which shows that the companions give salam to an elderly woman as narrated by Sahl bin Sa’d, he said:
كَانَتْ فِينَا امْرَأَةٌ تَجْعَلُ عَلَى أَرْبِعَاءَ فِي مَزْرَعَةٍ لَهَا سِلْقًا، فَكَانَتْ إِذَا كَانَ يَوْمُ جُمُعَةٍ تَنْزِعُ أُصُولَ السِّلْقِ، فَتَجْعَلُهُ فِي قِدْرٍ، ثُمَّ تَجْعَلُ عَلَيْهِ قَبْضَةً مِنْ شَعِيرٍ تَطْحَنُهَا، فَتَكُونُ أُصُولُ السِّلْقِ عَرْقَهُ، وَكُنَّا نَنْصَرِفُ مِنْ صَلاَةِ الجُمُعَةِ، فَنُسَلِّمُ عَلَيْهَا، فَتُقَرِّبُ ذَلِكَ الطَّعَامَ إِلَيْنَا، فَنَلْعَقُهُ وَكُنَّا نَتَمَنَّى يَوْمَ الجُمُعَةِ لِطَعَامِهَا ذَلِكَ.
“There was a woman amongst us who had a farm and she used to sow Silq (a kind of vegetable) on the edges of streams in her farm. On Fridays she used to pull out the Silq from its roots and put the roots in a utensil. Then she would put a handful of powdered barley over it and cook it. The roots of the Silq were a substitute for meat. After finishing the Jumua prayer we used to greet her and she would give us that food which we would eat with our hands, and because of that meal, we used to look forward to Friday.”
Thus, we know that the limitation in giving salam between a man and a woman who don’t have any relations with each other is as long as it doesn’t lead to fitnah and harm.
According to the above discussion, in our opinion, giving salam between a man and a woman who don’t share any relations is permissible on the condition that it is safe from fitnah just as the salam speech of a man and mahram woman or family members. In this issue, there is an Islamic legal maxim that states:
“Every matter is based on the intention.”
This means any speech and actions of a person depends on the intention.  Thus, the same goes for the acknowledgement of salam from a student to his teacher or a teacher to his student of the opposite gender is permissible on the condition that it is safe from fitnah and doesn’t lead to desires or other harms. If it leads to fitnah or other harms such as disturbance from the individual, then giving salam is impermissible and should be avoided.
May Allah SWT grant us all a clear understanding in religion. Amin.
 Narrated by Abu Daud (5204); Ibn Majah (3701) and Syu‘aib al-Arna’ut stated this hadith is hasan. The sanad of this hadith is dhaif because there is a weak narrator, Syahr bin Husyab, however, there is mutaba‘ah. While the rest of the narrators are thiqah.