Mandarin and Cantonese are both Chinese dialects. What this means is that they are both essentially variations of the same language. For the purpose of most written work in Mainland China and South-East Asia, they are both identical in that they utilise Simplified Chinese. In Hong Kong (Cantonese), Macau (Cantonese) & Taiwan (Mandarin) people use Traditional Chinese.
Simplified Chinese grew out of a desire to both modernise the Chinese language and to improve literacy levels. Traditional Chinese characters were extremely complex and often simplified in an understandable way through cursive writing. In the mid 20th century, Simplified Chinese made use of this to strip out unnecessary character strokes and incorporate some of the cursive shorthand simplifications of the time. The Communist Party saw an opportunity to also remove grammatical differences and adopted Mandarin’s grammatical structure as the basis for Simplified Chinese’s written form. This created a unified written system that anyone in China could learn to communicate with anyone else regardless of which Chinese dialects they spoke.
Traditional Chinese is a bit more complicated. In Traditional Chinese, characters retain their older form which includes a lot more strokes than Simplified Chinese. There are also additional Traditional Chinese characters where two or more traditional variants have been simplified into a single Simplified Chinese character. While there are some minor differences in grammatical structure between the two character sets, most Simplified Chinese readers have no problem understanding Traditional Chinese and visa-versa if they have some familiarity with the process of simplification.