In the flame test compounds of some metals, in the presence of conc. HCl, form different colored flames. In the flame test, electrons in both the metal atoms and the chlorine atoms are agitated to higher energy levels. In this test, the compounds become volatile and then vapors form different colored flame’s. For most metals, the emitted light is in the visible region. The purpose of using conc. HCl is to convert the compounds into their metallic chlorides. Because the metallic chlorides are very much volatile. Thus, the flame color is caused by the metal alone.
When heated in the flame the elements of the metals of the compounds become excited and go to higher energy levels. Later when they come back to the ground state, they emit extra energy as visible light. As a result flames of different colors are formed for different metals. Hydrochloric acid has a fewer probability of attacking the salt, even when concentrated. Also, it does not give color to the flame, while it does burn away much contaminating substance, particularly organic matter. Such as for Na golden yellow, for K lilac violet, for Ca brick red flames are found. dil HCl cannot be used for the reason that all salts will not form chlorides that simply with dil acid. You need a better concentration of H+ and Cl- ions. Chlorine atoms do not produce energy in the observable area. These electrons emit energy of feature wavelengths when they come back to the ground state.