The Hadith of intention is usually the first in most books of Hadith. Ibn Daqiq Al-Id expounds on it in his explanation of Imam Nawawi’s 40 Hadith.
Umar Bin Al-Khattab (may Allah be pleased with him) said: I heard the Messenger of Allah (peace be upon him) say: “Actions are but by intention and every man shall have but that which he intended.
Thus he whose migration was for Allah and His messenger, his migration was for Allah and His messenger, and he whose migration was to achieve some worldly benefit or to take some woman in marriage, his migration was for that for which he migrated.” (Al-Bukhari and Muslim)
This Hadith is great in its benefit and importance. It has been said that Islam revolves around it. Some scholars said it is one-third of knowledge because actions involve the heart, tongue, and limbs. So the intention of the heart is one-third of that.
Other scholars said Islam is encompassed in three Ahadith: This one, the Hadith “The Halaal is clear, the Haraam is clear and between them are doubtful matters…,” and the Hadith “Whoever innovates in this religion that which is not from it will have his actions rejected (by Allah).”
The word “by” (in the sentence “actions are but by intention”) means that the acceptance and correctness of any action depend upon the intention behind it.
An action which is apparently good, such as giving money to charity, will be rejected if the intention behind it is wrong. Giving charity to show off is one such example. The Prophet (peace be upon him) narrated from Allah that if a person performs an act for Allah’s sake and also for the sake of someone else, then Allah will reject the deed entirely and leave the whole of that deed for the partner the person made (with Allah). This shows us how grave the sin of Shirk is – it is the only sin that Allah will never forgive.
In the Hadith, the words “shall have” means that the person will be rewarded only for what he intended. If a person did the Hijrah with a wrong intention, then he would not be rewarded with Hijrah (for Allah’s sake).
The word “actions” refers to those actions which are part of the Shariah of Islam.
Thus, any action of the Shariah – such as Wudhu, Ghusl, Tayammum, Salah, Zakat, Fasting, Haj, I’tikaf, or any other act of worship – will not be accepted and rewarded unless it is performed with the correct intention.