Allaah, the Exalted, says: “Tell the believing men to lower their gaze (from looking at forbidden things), and to protect their private parts (from illegal sexual acts, etc.). That is purer for them. Verily, Allaah is All-Aware of what they do.” [al-Noor 24:30]
The Prophet (صلى الله عليه وسلم) said: "The adultery of the eyes is by looking" (i.e. by looking at what Allaah has forbidden). (Reported by al-Bukhaari, see Fath al-Baari, 11/26).
Looking for a legitimate purpose is exempted from this rule, such as looking at a woman for marriage purposes, or a doctor examining a patient for medical reasons, etc. Women are equally forbidden to look at non-mahram men, as Allaah, the Most Hight, says: “And tell the believing women to lower their gaze (from looking at forbidden things) and to protect their private parts (from illegal sexual acts, etc.) . . .” [an-Noor 24:31]
Men are also forbidden to look with desire at a man with a hairless or beautiful face. Men are forbidden to look at the ‘awrah of other men, and women are forbidden to look at the ‘awrah of other women. A man may look at his mahram female relatives' face, head, chest, shins and arms, but according to the Hanafis he may not look at their back or belly. A man may look at all of the body of another man except for that which is between his navel and his knees. A Muslim woman may look at all of the body of another Muslim woman, except for the area between the navel and the knees. "A man shall not look at the nakedness of [another] man, nor shall a woman look at the nakedness of [another] woman." [Muslim]
Jabir Ibn `Abdullah (رضي الله عنه) said: I asked the Messenger of Allah (صلى الله عليه وسلم) about (the Islamic ruling on) accidental glance (i.e., at a woman one is not Islamically allowed to look at) and he ordered me to turn my eyes away. [Muslim]
The Prophet (صلى الله عليه وسلم) told another Companion, not to follow the first (unintentional) look with a second (deliberate) look, for the first one is excused, but the second is not. If one's eyes unintentionally fall on a member of the opposite sex, one should stop looking as soon as one realizes it, and should neither continue looking nor look again deliberately, for the gaze is one of the poisoned arrows of Shaytaan. "The furtive glance is one of the poisoned arrows of Shaytan, on him be God's curse. Whoever forsakes it for the fear of Allah, will receive from Him (Great and Gracious is He) a faith, the sweetness of which he will find within his heart." (al-Haakim.)