Short answer
Yes, you may greet them and speak to them, as the Prophet ﷺ greeted the people of the graves. Scholars differ on how much the dead hear, but the greeting is sunnah. What is forbidden is asking the dead to help you or fulfil your needs; ask Allah alone, and make dua for them.
Greeting the dead at the grave is sunnah. Whether the dead hear ordinary speech is a question on which Hanafi scholars differ, and no act of practice depends on it. Asking the dead to cure, provide or protect is not permitted.
The four schools agree on this.
Explanation
When you stand at the grave of someone you love, it is natural to speak to them. The sunnah gives words for this: As-salamu 'alaykum ahl al-diyar min al-mu'minin wal-muslimin. The Prophet ﷺ taught this greeting, which speaks to the dead directly.
Do the dead hear? The hadith says the dead person hears the footsteps of the people as they walk away after the burial. After Badr, the Prophet ﷺ spoke to the dead of Quraysh and said the living did not hear his words better than they did. The Quran also says that he cannot make those in the graves hear. Scholars, including within the Hanafi school, explain these texts in different ways: some say the dead hear in general, others that they hear only what Allah lets them hear, such as the greeting.
- Greeting them with salam is sunnah.
- Telling them you miss them and love them, then making dua for them, is fine.
- Reciting Quran and asking Allah to give them its reward is good; see reciting Quran for the dead.
- Asking the dead to cure you, give you children, solve your problems or protect you is not allowed. These are requests only Allah can answer.
- Prostrating to the grave, praying toward it or treating it as a place of worship is not allowed.
- Wailing, or words of complaint against Allah's decree, are not allowed.
Grief makes the heart reach out. Turn that love into dua, and trust that your dua reaches them. See visiting graves and, for the graves of the righteous, dua at the grave of a saint.
The evidence
Quran, Surah Faatir 35:22
وَمَا يَسْتَوِى ٱلْأَحْيَآءُ وَلَا ٱلْأَمْوَٰتُ ۚ إِنَّ ٱللَّهَ يُسْمِعُ مَن يَشَآءُ ۖ وَمَآ أَنتَ بِمُسْمِعٍۢ مَّن فِى ٱلْقُبُورِ ﴿٢٢﴾
And not equal are the living and the dead. Indeed, Allah causes to hear whom He wills, but you cannot make hear those in the graves.
This ayah is one of the texts scholars weigh on whether the dead hear.
Sahih Muslim 975
Sahih... السلام عليكم أهل الديار من المؤمنين والمسلمين ...
"Peace be upon you, people of these dwellings, from the believers and the Muslims."
The sunnah greeting speaks to the dead directly.
Sahih al-Bukhari 1338
Sahih... وتولى عنه أصحابه وإنه ليسمع قرع نعالهم ...
"When his companions turn away from him, he hears the sound of their sandals."
The dead person is aware of those at the grave after burial.
Sahih al-Bukhari 3976
Sahih... ما أنتم بأسمع لما أقول منهم ...
"You do not hear what I say better than they do."
The Prophet ﷺ spoke to the dead at Badr.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Salah, Bab Salat al-Janazah, on visiting graves. Greeting the dead and what is done at the grave.
- Fath al-Qadir, Kitab al-Ayman, the oath not to speak to someone. The discussion of whether the dead hear speech.
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.