Valence electrons are the electrons in the outermost principal energy level (shell) of an atom or ion. Anions like Cl⁻ are formed by gaining electrons, which occupy the available spaces in the valence shell or the next available shell.