A more detailed response is:
In Sunni Islam, mourning is often said to be for 3 days only, based on Sunni hadith (for instance, Sahih Bukhari).
In Shi'i Islam, it is not considered forbidden to mourn for more than 3 days, and people may vary in how much time they personally need to mourn. However, it is recommended to send food to the homes of the deceased for 3 days.
Mourning for 40 days is done in several religious traditions and probably has some general human significance, but is not required.