Short answer
Visit or contact the family within three days, say Inna lillahi wa inna ilayhi raji'un, remind them of Allah's mercy, and make dua for the dead. The Prophet ﷺ said: to Allah belongs what He took and what He gave, and everything has a set term with Him. Bringing food to the family is sunnah.
Ta'ziyah (offering condolence) is mustahabb, best within three days of the death; repeating it after three days is makruh except for someone who was away. The family may sit at home to receive visitors for up to three days. Neighbours and relatives preparing food for the family is mustahabb.
The four schools agree on this.
Explanation
Ta'ziyah means comforting the bereaved and helping them to be patient. You do not need a long speech. A few sincere words, a hand on the shoulder from the same gender, and practical help mean a great deal.
What to say:
- Inna lillahi wa inna ilayhi raji'un: "We belong to Allah and to Him we return."
- Inna lillahi ma akhadha wa lahu ma a'ta, wa kullu shay'in 'indahu bi-ajalin musamma: "To Allah belongs what He took and what He gave, and everything has a set term with Him." The Prophet ﷺ sent these words to his grieving daughter.
- A'zamallahu ajrakum: "May Allah make your reward great."
- "May Allah forgive them and give you patience."
More phrases are in what to say when someone dies.
What helps:
- Bringing cooked food, so the family does not have to cook or host.
- Helping with arrangements, children, school runs or calls.
- Keeping the visit short and calm, unless they want you to stay.
- Sharing good memories of the person.
What to avoid: "they would still be alive if...", comparing losses, long questions about the cause of death, and expecting the family to serve you food. Repeating formal condolence after three days is disliked, but checking on the family later, and visiting someone who was away, is good.
Condoling a non-Muslim is also allowed, with kind words such as "May God give you patience" and an offer of help; see attending a non-Muslim funeral.
The evidence
Quran, Surah Al-Baqara 2:155-156
وَلَنَبْلُوَنَّكُم بِشَىْءٍۢ مِّنَ ٱلْخَوْفِ وَٱلْجُوعِ وَنَقْصٍۢ مِّنَ ٱلْأَمْوَٰلِ وَٱلْأَنفُسِ وَٱلثَّمَرَٰتِ ۗ وَبَشِّرِ ٱلصَّٰبِرِينَ ﴿١٥٥﴾ ٱلَّذِينَ إِذَآ أَصَٰبَتْهُم مُّصِيبَةٌۭ قَالُوٓا۟ إِنَّا لِلَّهِ وَإِنَّآ إِلَيْهِ رَٰجِعُونَ ﴿١٥٦﴾
And We will surely test you with something of fear and hunger and a loss of wealth and lives and fruits, but give good tidings to the patient, Who, when disaster strikes them, say, "Indeed we belong to Allah, and indeed to Him we will return."
Condolence reminds the family of these words and the promise of reward.
Sahih al-Bukhari 1284
Sahih... إن لله ما أخذ وله ما أعطى وكل عنده بأجل مسمى ...
"To Allah belongs what He took and what He gave, and everything with Him has a set term."
These are the Prophet's ﷺ words of condolence.
Sunan Abi Dawud 3132
Graded hasan... اصنعوا لآل جعفر طعاما فإنه قد أتاهم أمر شغلهم ...
"Make food for the family of Ja'far, for what has come to them keeps them busy."
Bringing food to the bereaved is sunnah.
Sahih Muslim 918
Sahih... إنا لله وإنا إليه راجعون اللهم أجرني في مصيبتي وأخلف لي خيرا منها ...
"We belong to Allah and to Him we return. O Allah, reward me in my loss and give me something better in its place."
A dua to teach the grieving.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Salah, Bab Salat al-Janazah. Condolence for three days, sitting to receive it, and its wording.
- al-Fatawa al-Hindiyya, Kitab al-Salah, chapter on jana'iz. The dislike of repeating condolence after three days.
This answer is pending review by the scholars on our team. 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.