DUA WHEN VISITING GRAVES
السَّلاَمُ عَلَيْكُمْ أَهْلَ الدِّيَارِ مِنَ الْمُؤْمِنِينَ وَالْمُسْلِمِينَ وَإِنَّا إِنْ شَاءَ اللَّهُ لَلَاحِقُونَ أَسْأَلُ اللَّهَ لَنَا وَلَكُمْ الْعَافِيَةَ
Transliteration: Assalaamu 'alaykum 'ahlad-diyaari, minal-mu'mineena walmuslimeena, wa 'innaa 'in shaa' Allaahu bikum laahiqoona [wa yarhamullaahul-mustaqdimeena minnaa walmusta'khireena] 'as'alullaaha lanaa wa lakumul- 'aafiyata
Translation: Peace be upon you, the inhabitants of the city, among the believers, and Muslims, and God willing we shall join you. I beg of Allah peace for us and for you.
REFERENCE HADITH
Sulaiman b. Buraida narrated on the authority of his father that the Messenger of Allah (ﷺ) used to teach them when they went out to the graveyard. One of the narrators used to say this in the narration transmitted on the authority of Abu Bakr:
" Peace be upon the inhabitants of the city (i. e. graveyard)." In the hadith transmitted by Zuhair (the words are):" Peace be upon you, the inhabitants of the city, among the believers, and Muslims, and God willing we shall join you. I beg of Allah peace for us and for you."
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، وَزُهَيْرُ بْنُ حَرْبٍ، قَالاَ حَدَّثَنَا مُحَمَّدُ بْنُ عَبْدِ اللَّهِ، الأَسَدِيُّ عَنْ سُفْيَانَ، عَنْ عَلْقَمَةَ بْنِ مَرْثَدٍ، عَنْ سُلَيْمَانَ بْنِ بُرَيْدَةَ، عَنْ أَبِيهِ، قَالَ كَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم يُعَلِّمُهُمْ إِذَا خَرَجُوا إِلَى الْمَقَابِرِ فَكَانَ قَائِلُهُمْ يَقُولُ - فِي رِوَايَةِ أَبِي بَكْرٍ - السَّلاَمُ عَلَى أَهْلِ الدِّيَارِ - وَفِي رِوَايَةِ زُهَيْرٍ - السَّلاَمُ عَلَيْكُمْ أَهْلَ الدِّيَارِ مِنَ الْمُؤْمِنِينَ وَالْمُسْلِمِينَ وَإِنَّا إِنْ شَاءَ اللَّهُ لَلَاحِقُونَ أَسْأَلُ اللَّهَ لَنَا وَلَكُمْ الْعَافِيَةَ.
Reference: Sahih Muslim 975
In-book reference: Book 11, Hadith 133
USC-MSA web (English) reference: Book 4, Hadith 2128
https://sunnah.com/muslim/11/133