By late in the last century, people had began looking closely at the spectra of stars. It was realized that the spectra of stars (in particular, their patterns of absorption lines) had systematic features!!
At first, they identified a number of stars which showed a very STRONG pattern
of lines, called the Balmer Lines. (due to Hydrogen). They were called 'A' Stars.
It was realized by Annie J. Cannon, an assistant at the Harvard Observatory
beginning in 1896, that there were really only about 7 unique kinds of stars, and
all other LETTERS were dropped.
Ms. Cannon classified more than a quarter million stars
which were published as The Draper Catalogue in nine volumes, from 1918 to 1924.
Those stars with slightly weaker Balmer lines of Hydrogen, were called 'B' Stars and so on. At one point, the letters labeling all these different looking stellar
spectra went all the way to 'S'.