Shaykh Dr. Yasir Qadhi lays out what the Sharia says about humour and joking.
Numerous Hadith are cited that support the humorous stance of the Prophet ﷺ:
The Prophet ﷺ used to joke with the small child of one of the Sahabah called Abu Umayr, who had a small bird he used to play with. One day he saw the child looking sad, so he said, "Why do I see Abu Umayr looking sad?" The Sahabah told him, "The nughar which he used to play with has died, O Messenger of Allah." The Prophet ﷺ began to gently joke with the child, saying, "O Abu Umayr, what happened to the nughair?"
A man came to the Prophet ﷺ asking him to give him something to ride. The Prophet ﷺ jokingly said, "I will give you the offspring of a she-camel to ride." He said, "O Messenger of Allah , what will I do with the offspring of a she-camel?" The Prophet said: "Are riding-camels born except from she-camels?"
Zahir was one of the Sahaba for whom the Prophet ﷺ had a deep fondness. One day the Prophet ﷺ came to him while he was selling some goods. He embraced him from behind. Zahir, unable to see who he was, said, "Let me go! Who is this?" Then he turned around and recognized the Prophet SAW and then he tried to move closer to him once he knew who it was. The Prophet ﷺ said, "Who will buy this slave?" Zahir said,"O Messenger of Allah, you will find me unsellable." The Prophet ﷺ said, "But in the sight of Allah SWT you are valuable."
Conditions and etiquette for cracking jokes:
There cannot be anything intrinsically Haram in it.
One cannot terrify the other believer with his jokes.
We should not laugh excessively as it deadens the heart.
It is Haram if we joke against Allah and His Messenger ﷺ.
There cannot be blatant lying in the jokes we make.