Question: Is it permissible to be in an elevator with a non-mahram alone? It happens often but the time is very little and it usually safe. So should I continue using the elevator or do I have to take the stairs? Would I be sinful? I live on the 11th floor so it would be a hardship.
Answer: Assalamu alaykum,
Thank you for your question.
I have copied and pasted below the answer to your question from this link:
Elevators and Impermissible Seclusion (khalwa)
The Default Ruling
The definition of impermissible seclusion (khalwa) is: for an unrelated man and woman to gather in a place where it is normally possible for them to engage in indecency, even if this indecency is of a lower degree than actual intercourse, such as kissing, looking at what is unlawful to look at, or touching.
Based on this definition, it appears to this needy soul that for a man and a woman to be alone in a modern elevator does constitute impermissible seclusion, even if the seclusion only lasts a short time. This is because during the short time it takes to travel between floors, it is not possible to open the door [h: and the two are hence guaranteed this duration of seclusion], and it is possible for them to engage in an act of indecency that is of a lower degree than actual intercourse [h: such as kissing or touching].
If, however, the elevator is made of glass and is in a public area through which many people pass (as is often the case), then for a man and a woman to be alone in it is not impermissible.
The Exceptional Circumstance
As for the hardship that the questioner has mentioned, what I say about it–seeking the help of my Lord that He guide me to what is correct–is that the default ruling is what has been mentioned above. Allah Most High has, however, said, “He has not placed any hardship for you in your religion” (22:78). Based on this [h: and also based on a number of related issues mentioned by our scholars in classical manuals of Islamic Law], getting in an elevator with an unrelated member of the opposite sex will be permissible if the following conditions are met:
(1) The need that needs to be fulfilled by getting on the elevator must be a significant need. 
(2) There must be no other way to fulfill the need other than getting on an elevator with an unrelated member of the opposite sex to reach the place that one needs to get to. 
(3) Not getting on the elevator must result in either (a) losing the opportunity to fulfill the need, or (b) climbing many flights of stairs, such that this would be commonly acknowledged as posing a hardship. 
(4) One must have confidence in one’s own ability to restrain one’s gaze and to avoid falling into temptation.
And Allah Most High knows best, and to Him is the final return.
Shaykh Amjad Rasheed (Translated by Shaykh Hamza Karamali)
 Getting on an elevator to reach a coffee shop where one plans to relax, for example, would not constitute a “significant need,” but getting on the elevator to meet an important work-related appointment would.
 If there is an alternative permissible route whose traversal does not pose great hardship, then it would be obligatory to take that route.
 If one only has to climb a single flight of stairs, and one is not handicapped in any way, then it would be obligatory to take the stairs instead of the elevator.
[Ustadha] Shazia Ahmad
Checked and Approved by Shaykh Faraz Rabbani
Ustadha Shazia Ahmad lived in Damascus, Syria for two years where she studied aqidah, fiqh, tajweed, tafseer, and Arabic. She then attended the University of Texas at Austin, where she completed her Masters in Arabic. Afterward, she moved to Amman, Jordan where she studied fiqh, Arabic, and other sciences. She recently moved back to Mississauga, Canada, where she lives with her family.