Rather than two separate languages, Croatian and Serbian share a history, alphabet, vocabulary, and grammar.
Serbo-Croatian is what’s known as a pluricentric language, sporting no less than four mutually intelligible major dialects (Bosnian is also essentially the same language). As such, Serbian and Croatian both began life as a version of Old Church Slavonic and each was first written down in the 9th century. For most of their shared history the differences between these two languages were small – and they remain small today, in fact. A Serb and a Croat, meeting on a road somewhere, would have no difficulty at all in understanding each other, with only minor grammatical, pronunciation, and regional differences to deal with.
During the 20th century and communist rule, the official policy in Yugoslavia was that there was a single language for all ‘Yugoslavs’ (an artificial combination of Serbs, Croats, Bosnians, and other ethnic groups) which happened to have two major dialects. This was a sensible policy, but when the communist order collapsed and the area split into various independence movements and, eventually, civil war, there was a passion for distinct, independent aspects to each new country.
As a result, the different nations and groups began insisting that their language was a distinct language from that of their neighbours. Croats began referring to their language as Croatian and Serbs to theirs as Serbian, and despite being essentially the same language treated their language as distinct and unique.
Today, efforts are underway in both countries to ‘standardise’ their version of the language – which is to say to rigidly define the differences between them. This will eventually – it may take centuries – result in the languages evolving in different ways, and someday in the far future these may in fact evolve into separate languages.
That would be an unfortunate result, in my opinion, but at present there doesn’t seem to be much to be done about it. Once nationalist passion takes over, there is little that can argue against it, and because the languages are still essentially the same these policies have little immediate negative impact. But as a Word Nerd I must argue that it is always better to use language to bring people together than to drive them apart.