# How does the litmus pH indicator work?

I'm wondering about how does the litmus solution work as a pH indicator.

And another question:

When you put drops of litmus solution into an colorless acid (e.g. $\ce{HCl}$), it turns red. But then if you add colorless base (e.g. $\ce{NaOH}$) to the mixture, it turns blue. How come?

I thought that the litmus solution doesn't change color after it's changed color once already after a chemical change with an acid or a base. In this case, I thought that the mixture wouldn't turn blue after adding the $\ce{NaOH}$ into the mixture. But it seems that it still works well after used once.

How come?

See that $\ce{OH}$ group at the lower left? That's where the so-called "acidic proton" is. This molecule is actually a weak acid, meaning that in the presence of a strong base, the $\ce{OH}$ group can lose a proton, which reacts with an hydroxide ion ($\ce{OH^{-}}$) to form a water. The 7-hydroxyphenoxazone is now a negatively charged ion: it looks the same except it is missing the $\ce{H}$ on the $\ce{OH}$ group, and it leaves behind an electron.
To think about the equation that describes what's going on, pretend that the entire 7-hydroxyphenoxazone molecule is represented by the formula $HLit$, where $\ce{H}$ is the hydrogen on the $\ce{OH}$ group and $Lit$ is everything else (this is common procedure: only the hydrogen matters in the acid-base equation). Then the acid-base equation is:
$$\ce{OH^{-} + HLit <=>H2O + Lit^{-}}$$
As more strong base is added, more hydroxide ion is present, driving the equilibrium to the right and producing more $Lit^-$ ion. And now, the color change: $HLit$ is red, but $Lit^-$ is bue. So the more acidic your solution, the more the equilibrium is to the left and thus there is more $HLit$ than $Lit^-$.