Islam does encourage visiting the graves since it reminds people of the hereafter. When visiting the graves, a person is to make du`aa’ (supplication) for the dead and seek Allah’s forgiveness for them.
Sheikh Ahmad Kutty, a senior lecturer and Islamic scholar at the Islamic Institute of Toronto, Ontario, Canada, states: Visiting graves is a recommended sunnah of the Prophet (peace and blessings be upon him), who said, “In the past, I had forbidden you earlier from visiting graves, but now you can do so, for it helps to remind you of the hereafter.” In other words, in the early days of Islam, Muslims were told not to visit graves, because of the fear of shirk, as the Arabs had been closer to their pagan ways, for they had been in the habit of worshiping idols, statues, and graves, etc. But after Islamic creed of tawheed (the Oneness of Allah) had become rooted and people had imbibed the true lessons of Islam, there was no fear of Muslims reverting to the practice of worshiping graves; hence the above prohibition was lifted and the Muslims were allowed to visit graves.

The Prophet (peace and blessings be upon him), however, did not merely allow them to visit graves, but also went a step further to encourage them to do so because of the obvious benefits associated with it: First, it reminds them of their final resting place; second, it helps people remember their dead ones and offer prayers for them. Allah tells us in the Qur’an that the true believers are those who supplicate to Allah saying, [Our Lord, forgive us and our brothers who have preceded us in faith and do not allow for any rancour in our hearts towards the believers; our Lord you are Full of Pity, Merciful] (Al-Hashr 59:10).
The Prophet (peace and blessings be upon him) demonstrated the sunnah of visiting graves through his own practice. We are told that he used to visit the graves of his Companions who had passed away and prayed for them. Once when `A’ishah, the beloved wife of the Prophet (peace and blessings be upon him), saw him returning from the graveyard, she inquired, “If I were to visit the graves, what should I say?” Then he told her, “Pray: Greetings of peace to you, the faithful residing in these dwellings. Surely we will be joining you soon. May Allah forgive us and you and all the Muslims.”
A final point: While visiting graves there is nothing wrong in reading some Qur’an and saying prayers (du`aa’) for the dead; we are told that some of the members of As-Salaf As-Salih (the pious predecessors) used to read Al-Fatihah and parts of Surat Al-Baqarah while visiting the graves.
I pray to Allah to forgive us and all those brothers and sisters who have preceded us in faith; and may He remove rancour and malice against the faithful from our hearts. Ameen.