The first martial art to introduce the colored belt ranking system was Judo. Gichin Funakoshi, who borrowed the judo gi for Karate, also adapted the colored belt system for karate.
As students pass through the ranks they will be awarded a different belt color. The colors will differ from style to style and sometimes from dojo to dojo. However, the Kyu (numbered rank) will always start at 10 and ends at 1. Once obtaining a black belt the ranks start over progressing from 1 to 10.
In "the old days" the white belt was simply dyed to a new color. This repeated dying process dictates the type of belt color and the order of the colors!.
Due to the dying process, it is practical to increasingly use darker colors. This began shortly after World War II when Japan was a very poor Nation and dying belts darker was a more economical way to maintain the rank system.
Another explanation for the colored belts, more of a Karate myth than reality, is the notion that the belts simply went from white to black because the original Karate founders never washed their belts. They started off with white belts and after years of training ended up with black belts. However, dirtiest belt will never go black, and although the color change from white to yellow to brown can easily be imagined, other colors like green would be harder to achieve, unless the belt is host to a culture of particularly nasty and colorful bacteria.