Please enable JavaScript to use CodeHS

ANSI Colors

Understanding ANSI colors in the terminal

By Andy Bayer

Software Developer at CodeHS

Every ANSI sequence is going to begin with the escape code, a sequence indicating to the terminal that the next characters it receives are going to be an ANSI code.

In the tutorial for clearing the console with ANSI sequences, we saw the escape code is \x1b, \033, or \u001b, depending on if you’re using hexadecimal, octal, or unicode. For simplicity, let’s use \x1bc, the hexadecimal respresentation. And to make it even easier, let’s put that value in a variable named ESC: