The chemical structure determines the color of dyes. More specifically, it is the atomic groupings, or chromophores that are the determining factors. The more chromophores present, the deeper the color. The chromophores can be acidic or basic.
Generally speaking, stain is taken up by tissues due to dye-tissue or reagent-tissue affinities. Affinity is used to describe the attractive forces binding the dye to the tissue components. This is called a chemical bond which is formed through an electrostatic attraction between two oppositely charged ions.
An acidic dye is the salt of a color acid and has the affinity for basic tissue components such as the cytoplasm of all cells.
A basic dye is the salt of a color base and has the affinity for acidic tissue components such as the nucleic acids in the nucleus of all cells.