The opening stanza of the late British author and poet Rudyard Kipling's The White Man's Burden can perhaps be useful in illuminating the role played by racism in imperialism:
Take up the White Man's burden--
Send forth the best ye breed--
Go bind your sons to exile To serve your captives' need;
To wait in heavy harness,
On fluttered folk and wild--
Your new-caught, sullen peoples,
Half-devil and half-child.
While Kipling's poem about the burden imposed upon the white races of having to occupy, enlighten and exploit those less fortunate than himself can be interpreted as a cynical indictment of that racism, the fact is that Kipling was indeed imbued with a sense of European racial supremacy. Colonialism is not necessarily inherently racist. On the contrary, if foreign lands had only natural resources and no people on them, the Spanish, English, French, Portuguese and others would have colonized these lands anyway. The people, while providing cheap labor, just so happened to be there, so were subjected to the brutalities and indignities of foreign occupation. And, colonization, the result of imperialism, was driven by the desire to capture resources more than it was a desire to enslave other peoples. That said, the two go together. There was among the European imperialists, and among many Americans with respect to the Western Hemisphere, an innate racism lying behind the drive to expand. No greater proof of the influence of racial theories on foreign policy can be found than in the words of a giant of the history of American juris prudence, Chief Justice of the Supreme Court John Marshall. In his opinion in the case of Johnson and Graham lessee v. William M'Intosh (1823), Chief Justice Marshall famously wrote:
"But the tribes of Indians inhabiting this country were fierce savages, whose occupation was war, and whose subsistence was drawn chiefly from the forest. To leave them in possession of their country, was to leave the country a wilderness; to govern them as a distinct people, was impossible, because they were as brave and as high spirited as they were fierce, and were ready to repel by arms every attempt on their independence."
Marshall's perspective was hardly unique; in fact, it was widely accepted among many, but far from all Americans that they were possessed of a divine right to expand from coast to coast (i.e., Manifest Destiny), and that the indigenous tribes that stood in their way represented inferior species of humans. In short, then, while imperialism was not driven by theories of racial superiority, such theories certainly existed among many Europeans and, later, Americans.
Racism relates to imperialism because racism was one of the things that allowed imperial powers to justify going out and conquering other people. When a country (particularly a democratic one like the United States) goes out conquering, it needs to be able to justify doing so. It has to give some reason why it is acceptable for it to conquer and rule others.
For imperial powers in the late 1800s, racism was one justification for imperialism. Imperial powers argued that they were racially superior to those that they conquered. For example, Americans argued that the Filipinos were racially inferior and therefore not really capable of governing themselves. For this reason, it was acceptable to conquer them and to rule them as an imperial power.
Racism, then, was a good way to justify imperialism. Supposed racial superiority provided a way to argue that it was right to take an empire.