How is the flame test used to identify cations?

Some elements emit a color in the visible spectrum and we can use that color to identify the element. For example, Na is bright yellow, Li is crimson, Ba is a green color, Cu is a blue green, etc.