Short answer
Your prayer is valid, but going to the masjid with a strong smell of raw garlic, onion, cigarettes or a vape on your breath or clothes is makruh tahrimi in the Hanafi school, because it bothers the worshippers and the angels. Brush your teeth, rinse your mouth and freshen up first; if the smell stays, pray at home that time.
Entering the masjid with an offensive smell, from food, tobacco or anything else, is makruh tahrimi, and the smell should be removed first. The smell does not break wudu or affect the validity of the prayer. Cooked onion or garlic that leaves no smell is no problem.
The four schools agree on this.
Explanation
The Prophet ﷺ told anyone who had eaten garlic or onion to keep away from the masjid, explaining that the angels are bothered by what bothers people. Scholars apply the same rule to anything with a strong unpleasant smell, including cigarettes, shisha and vapes. The four schools agree.
The rule is about the masjid and the people in it, not the prayer itself. Smoking or eating garlic does not break wudu, and a prayer at home after it is valid. The aim is that you clean up and then come, not that you use the smell as an excuse to skip the congregation or Jumuah.
- Freshen up: brush your teeth, use the miswak or mouthwash, and change a jacket that smells of smoke.
- Timing: avoid raw garlic and onion, and smoking, shortly before going to the masjid, especially on Friday.
- Work smells: if your job leaves a strong smell, wash and change before you go.
- Medical bad breath: if you cannot help it, do what you reasonably can; that is not blameworthy.
Whether smoking itself is allowed is a separate question about food and health. For the masjid congregation, see is praying in congregation obligatory.
The evidence
Sahih al-Bukhari 855
Sahih... من أكل ثوما أو بصلا فليعتزلنا ...
"Whoever has eaten garlic or onion, let him keep away from us."
A strong smell keeps a person from the masjid until it is gone.
Sahih Muslim 564
Sahih... فلا يقربن مسجدنا فإن الملائكة تأذى مما يتأذى منه الإنس ...
"Let him not come near our masjid, for the angels are harmed by what harms people."
The reason: smells bother worshippers and angels.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Salah, chapter on what is disliked in prayer, rulings of the masjid. Entering the masjid with a bad smell, from raw garlic, onion and the like, is disliked.
- al-Fatawa al-Hindiyya, Kitab al-Karahiyya, chapter on the masjid. The masjid is kept clear of offensive smells.
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.